Next: , Previous: , Up: Directory Index   [Contents][Index]


2.13 geometry

Function File: rotMatrix = rotationMatrix ( angle, rotAxis )

computes the rotation matrix for an *active* rotation by angle around the axis rotAxis (3d vector)

Examples

rotMatrix = rotationMatrix(1.357, [0.9, 8.7, 6.5]);
sert(ismatrix(rotMatrix))
sert(rotMatrix' * rotMatrix, eye(3), 1e-3)
Function File: vn = skyAngles2Vector ( [ longitude, latitude ] )

Convert a sky-position given in terms of longitude and latitude’ angles into a unit vector vn = [nx, ny, nz] in the same reference frame (ie either in equatorial or ecliptic system).

inputs {longitude, latitude} are allowed to be vectors, ie the input LongLat must be of size N x 2. returns unit-vector vn = [ nx, ny, nz ] of column-vectors nx,ny,nz

Examples

Ntrials = 1000;
LongLatIn = [ octforge_unifrnd(0, 2*pi, Ntrials, 1 ), octforge_unifrnd(-pi/2, pi/2, Ntrials, 1) ];
vn = skyAngles2Vector ( LongLatIn );
LongLatOut = skyVector2Angles ( vn );
maxerr = max ( abs ( LongLatIn(:) - LongLatOut(:) ) );
assert ( maxerr < 1e-6 );
Function File: skyEqu = skyEcliptic2Equatorial ( skyEcl )

Convert a sky-position given in terms of ’longitude’ and ’latitude’ angles into a unit vector vn = [nx, ny, nz] in the same reference frame (ie either in equatorial or ecliptic system).

convert input sky-position in ecliptic reference frame into equatorial frame

Input 3-vectors are interpreted as sky-vectors vn = [nx, ny, nz] (un-normalized), while 2-vectors are interpreted as sky angles [longitude, latitude], and the output uses the same format as the input (ie vector –> vector, angles–>angles). Multiple values can be input as column-vectors, ie Nx3 for vectors vn, Nx2 for angles

Note

simple wrapper for skyRotateFrame()

Examples

Ntrials = 10;
LongLatEclIn = [ octforge_unifrnd(0, 2*pi, Ntrials, 1 ), octforge_unifrnd(-pi/2, pi/2, Ntrials, 1 ) ];
vnEclIn = octforge_unifrnd(-1, 1, Ntrials, 3 );
LongLatEqu1 = skyEcliptic2Equatorial ( LongLatEclIn );
vnEqu1 = skyEcliptic2Equatorial ( vnEclIn );
LongLatEclOut = skyEquatorial2Ecliptic ( LongLatEqu1 );
vnEclOut      = skyEquatorial2Ecliptic ( vnEqu1 );
err1 = max ( abs ( LongLatEclIn - LongLatEclOut )(:) );
err2 = max ( abs ( vnEclIn - vnEclOut )(:) );
assert ( (err1 < 1e-6) && (err2 < 1e-6 ) );
Function File: skyEcl = skyEquatorial2Ecliptic ( skyEq )

Convert a sky-position given in terms of ’longitude’ and ’latitude’ angles into a unit vector vn = [nx, ny, nz] in the same reference frame (ie either in equatorial or ecliptic system).

convert input sky-position in equatorial reference frame into ecliptic frame

Input 3-vectors are interpreted as sky-vectors vn = [nx, ny, nz] (un-normalized), while 2-vectors are interpreted as sky angles [longitude, latitude], and the output uses the same format as the input (ie vector –> vector, angles–>angles). Multiple values can be input as column-vectors, ie Nx3 for vectors vn, Nx2 for angles

Note

simple wrapper for skyRotateFrame()

Examples

LongLatEqu = [ 1.5, -0.5; 2.6, 0.7 ];
LongLatEclCheck = [ 1.469781, -0.907669; 2.385547, 0.449178 ];       ## converted using frostydrew.org/utilities.dc/convert/tool-eq_coordinates/
LongLatEcl = skyEquatorial2Ecliptic ( LongLatEqu );
err = max ( abs ( LongLatEcl - LongLatEclCheck )(:) );
assert ( err < 1e-5 );
Function File: skyOut = skyRotateFrame ( skyIn, angle, axis )

Convert a sky-position given in terms of ’longitude’ and ’latitude’ angles into a unit vector vn = [nx, ny, nz] in the same reference frame (ie either in equatorial or ecliptic system).

convert input sky-position by rotating the reference by angle around 3-vector axis

Input 3-vectors are interpreted as sky-vectors vn = [nx, ny, nz] (un-normalized), while 2-vectors are interpreted as sky angles [longitude, latitude], and the output uses the same format as the input (ie vector –> vector, angles–>angles). Multiple values can be input as column-vectors, ie Nx3 for vectors vn, Nx2 for angles

Examples

assert(skyRotateFrame([0.1, 2.3, 4.5], 1.234, [9.8, 7.6, 5.4]), [3.0863, -1.0902, 3.8518], 1e-3)
Function File: LongLat = skyVector2Angles ( vSky )

Convert a sky-position given in terms of a 3-vector into ’longitude’ and ’latitude’ angles in the same reference frame (ie either in equatorial or ecliptic system).

input vSky must be a N x 3 vector (N>=1), returns matrix of the form [ longitude, latitude ] with column-vectors longitude in [0, 2pi] and latitude in [-pi, pi]

Note

the input vector doesn’t need to be normalized

Examples

Ntrials = 1000;
vnIn = randPointInNSphere ( 3, ones ( 1, Ntrials ) )';
LongLat = skyVector2Angles ( vnIn );
vnOut = skyAngles2Vector ( LongLat );
maxerr = max ( abs ( vnIn(:) - vnOut(:) ) );
assert ( maxerr < 1e-6 );
Function File: [ ua, ub ] = TwoLineIntersection ( p1a, p2a, p1b, p2b )

Returns the intersection of two lines defined by the locus of points pa = p1a + ua*(p2a - p1a) and pb = p1b + ub*(p2b - p1b) i.e. the values of ua and ub such that pa == pb.

Examples

[ua,ub] = TwoLineIntersection([-1;-1], [3;3], [-1;1], [1;-1]);
assert(ua, 0.25, 1e-3);
assert(ub, 0.5, 1e-3);

Next: , Previous: , Up: Directory Index   [Contents][Index]