Vector and Matrix Operations
SOFA.a2af — Method
a2af(ndp::Integer, angle::Real)Decompose radians into degrees, arcminutes, arcseconds, and fraction.
Input
ndp– number of useful digitsangle– angle in radians
Output
dms– angle in sign, degrees, minutes, seconds, and fraction
Examples
julia> a2af(4, 2.345)
(sign = '+', degree = 134, minute = 21, second = 30, fraction = 9706)Note
The argument ndp is interpreted as follows:
ndp resolution : ...0000 00 00 -7 1000 00 00 -6 100 00 00 -5 10 00 00 -4 1 00 00 -3 0 10 00 -2 0 01 00 -1 0 00 10 0 0 00 01 1 0 00 00.1 2 0 00 00.01 3 0 00 00.001 : 0 00 00.000...
The largest positive useful value for ndp is determined by the size of angle, the format of Float64 on the target platform, and the risk of overflowing dms[3]. On a typical platform, for angle up to 2pi, the available floating-point precision might correspond to ndp=12. However, the practical limit is typically ndp=9, set by the capacity of a 32-bit int, or ndp=4 if int is only 16 bits.
The absolute value of angle may exceed 2pi. In cases where it does not, it is up to the caller to test for and handle the case where angle is very nearly 2pi and rounds up to 360 degrees, by testing for dms[0]=360 and setting dms[0-3] to zero.
SOFA.a2tf — Method
a2tf(ndp::Integer, angle::Real)Decompose radians into hours, minutes, seconds, and fraction.
Input
ndp– number of useful digitsangle– angle in radians
Output
hms– angle in sign, hour, minutes, seconds, and fraction
Note
The argument ndp is interpreted as follows:
ndp resolution : ...0000 00 00 -7 1000 00 00 -6 100 00 00 -5 10 00 00 -4 1 00 00 -3 0 10 00 -2 0 01 00 -1 0 00 10 0 0 00 01 1 0 00 00.1 2 0 00 00.01 3 0 00 00.001 : 0 00 00.000...
The largest positive useful value for ndp is determined by the size of angle, the format of Float64 on the target platform, and the risk of overflowing hms[3]. On a typical platform, for angle up to 2pi, the available floating-point precision might correspond to ndp=12. However, the practical limit is typically ndp=9, set by the capacity of a 32-bit int, or ndp=4 if int is only 16 bits.
The absolute value of angle may exceed 2pi. In cases where it does not, it is up to the caller to test for and handle the case where angle is very nearly 2pi and rounds up to 24 hours, by testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
SOFA.af2a — Method
af2a(sign::Char, degree::Integer, minute::Integer, second::Real)Convert degrees, arcminutes, arcseconds to radians.
Input
sign– sign of arcdegree– degrees of arcminute– minutes of arcsecond– seconds of arc
Output
angle– angle in radians
Examples
julia> af2a('-', 45, 13, 27.2)
-0.7893115794313645Note
- Unlike the SOFA C function, which computes a result even when the range checks fail (flagging a warning status), this function throws an AssertionError if any argument is out of range.
SOFA.c2s — Method
c2s(pos::AbstractVector{<:Real})P-vector to spherical coordinates.
Input
p– p-vector
Output
θ– longitude angle (radians)ϕ– latitude angle (radians)
Examples
julia> c2s([100.0, -50.0, 25.0])
(θ = -0.4636476090008061, ϕ = 0.21998797739545944)Note
The vector p can have any magnitude; only its direction is used.
If p is null, zero θ and ϕ are returned.
At either pole, zero θ is returned.
SOFA.d2tf — Method
d2tf(ndp::Integer, day::Real)Decompose days to sign, hours, minutes, seconds, fraction.
Input
ndp– number of useful digitsday– interval in days
Output
hms– hms in sign, hours, minutes, seconds, and fraction
Note
The argument ndp is interpreted as follows:
ndp resolution : ...0000 00 00 -7 1000 00 00 -6 100 00 00 -5 10 00 00 -4 1 00 00 -3 0 10 00 -2 0 01 00 -1 0 00 10 0 0 00 01 1 0 00 00.1 2 0 00 00.01 3 0 00 00.001 : 0 00 00.000...
The largest positive useful value for ndp is determined by the size of days, the format of Float64 on the target platform, and the risk of overflowing hms[3]. On a typical platform, for days up to 1.0, the available floating-point precision might correspond to ndp=12. However, the practical limit is typically ndp=9, set by the capacity of a 32-bit int, or ndp=4 if int is only 16 bits.
The absolute value of days may exceed 1.0. In cases where it does not, it is up to the caller to test for and handle the case where days is very nearly 1.0 and rounds up to 24 hours, by testing for ihmsf[0]=24 and setting ihmsf[0-3] to zero.
SOFA.pap — Method
pap(a::AbstractVector{<:Real}, b::AbstractVector{<:Real})Position-angle from two p-vectors.
Input
a– direction of reference pointb– direction of point whose PA is required
Output
θ– position angle of b with respect to a (radians)
Note
The result is the position angle, in radians, of direction b with respect to direction a. It is in the range -pi to +pi. The sense is such that if b is a small distance "north" of a the position angle is approximately zero, and if b is a small distance "east" of a the position angle is approximately +pi/2.
The vectors a and b need not be of unit length.
Zero is returned if the two directions are the same or if either vector is null.
If vector a is at a pole, the result is ill-defined.
SOFA.pas — Method
pas(λa::Real, ϕa::Real, λb::Real, ϕb::Real)Position-angle from spherical coordinates.
Input
λa– longitude of point A (e.g. RA) in radiansϕa– latitude of point A (e.g. Dec) in radiansλb– longitude of point Bϕb– latitude of point B
Output
θ– position angle of B with respect to A
Note
The result is the bearing (position angle), in radians, of point B with respect to point A. It is in the range -pi to +pi. The sense is such that if B is a small distance "east" of point A, the bearing is approximately +pi/2.
Zero is returned if the two points are coincident.
SOFA.pv2s — Method
pv2s(pv::AbstractVector{<:AbstractVector{<:Real}})Convert position/velocity from Cartesian to spherical coordinates.
Input
posvel– position-velocity-vector
Output
θ– longitude angle (radians)ϕ– latitude angle (radians)r– radial distancedθ– rate of change of θdϕ– rate of change of ϕdr– rate of change of r
Note
If the position part of pv is null, theta, ϕ, td and pd are indeterminate. This is handled by extrapolating the position through unit time by using the velocity part of pv. This moves the origin without changing the direction of the velocity component. If the position and velocity components of pv are both null, zeroes are returned for all six results.
If the position is a pole, theta, td and pd are indeterminate. In such cases zeroes are returned for all three.
SOFA.pvdpv — Method
pvdpv(a::AbstractVector{<:AbstractVector{<:Real}}, b::AbstractVector{<:AbstractVector{<:Real}})Inner (=scalar=dot) product of two pv-vectors.
Input
a– first pv-vectorb– second pv-vector
Output
adb– a . b (see note)
Note
- If the position and velocity components of the two pv-vectors are ( ap, av ) and ( bp, bv ), the result, a . b, is the pair of numbers ( ap . bp , ap . bv + av . bp ). The two numbers are the dot-product of the two p-vectors and its derivative.
SOFA.pvmpv — Method
pvmpv(a::AbstractVector{<:AbstractVector{<:Real}}, b::AbstractVector{<:AbstractVector{<:Real}})Subtract one pv-vector from another.
Input
a– first pv-vectorb– second pv-vector
Output
amb– a - b
SOFA.pvppv — Method
pvppv(a::AbstractVector{<:AbstractVector{<:Real}}, b::AbstractVector{<:AbstractVector{<:Real}})Add one pv-vector to another.
Input
a– first pv-vectorb– second pv-vector
Output
apb– a + b
SOFA.pvu — Method
pvu(dt::Real, pv::AbstractVector{<:AbstractVector{<:Real}})Update a pv-vector.
Input
dt– time intervalpv– pv-vector
Output
upv– p updated, v unchanged
Note
"Update" means "refer the position component of the vector to a new date dt time units from the existing date".
The time units of dt must match those of the velocity.
SOFA.pvup — Method
pvup(dt::Real, pv::AbstractVector{<:AbstractVector{<:Real}})Update a pv-vector, discarding the velocity component.
Input
dt– time intervalpv– pv-vector
Output
p– p-vector
Note
"Update" means "refer the position component of the vector to a new date dt time units from the existing date".
The time units of dt must match those of the velocity.
SOFA.pvxpv — Method
pvxpv(a::AbstractVector{<:AbstractVector{<:Real}}, b::AbstractVector{<:AbstractVector{<:Real}})Outer (=vector=cross) product of two pv-vectors.
Input
a– first pv-vectorb– second pv-vector
Output
axb– a x b
Note
- If the position and velocity components of the two pv-vectors are ( ap, av ) and ( bp, bv ), the result, a x b, is the pair of vectors ( ap x bp, ap x bv + av x bp ). The two vectors are the cross-product of the two p-vectors and its derivative.
SOFA.rm2v — Method
rm2v(r::AbstractMatrix{<:Real})Express an r-matrix as an r-vector.
Input
r– rotation matrix
Output
w– rotation vector (Note 1)
Note
A rotation matrix describes a rotation through some angle about some arbitrary axis called the Euler axis. The "rotation vector" returned by this function has the same direction as the Euler axis, and its magnitude is the angle in radians. (The magnitude and direction can be separated by means of the function pn.)
If r is null, so is the result. If r is not a rotation matrix the result is undefined; r must be proper (i.e. have a positive determinant) and real orthogonal (inverse = transpose).
The reference frame rotates clockwise as seen looking along the rotation vector from the origin.
SOFA.rv2m — Method
rv2m(w::AbstractVector{<:Real})Form the r-matrix corresponding to a given r-vector.
Input
w– rotation vector (Note 1)
Output
r– rotation matrix
Note
A rotation matrix describes a rotation through some angle about some arbitrary axis called the Euler axis. The "rotation vector" supplied to this function has the same direction as the Euler axis, and its magnitude is the angle in radians.
If w is null, the identity matrix is returned.
The reference frame rotates clockwise as seen looking along the rotation vector from the origin.
SOFA.rx — Method
rx(ϕ::Real, r::AbstractMatrix{<:Real})Rotate an r-matrix about the x-axis.
Input
ϕ– angle (radians)r– r-matrix
Output
r– r-matrix, rotated
Note
Calling this function with positive ϕ incorporates in the supplied r-matrix r an additional rotation, about the x-axis, anticlockwise as seen looking towards the origin from positive x.
The additional rotation can be represented by this matrix:
( 1 0 0 ) ( ) ( 0 + cos(ϕ) + sin(ϕ) ) ( ) ( 0 - sin(ϕ) + cos(ϕ) )
SOFA.rxpv — Method
rxpv(r::AbstractMatrix{<:Real}, pv::AbstractVector{<:AbstractVector{<:Real}})Multiply a pv-vector by an r-matrix.
Input
r– r-matrixpv– pv-vector
Output
rpv– r * pv
Note
The algorithm is for the simple case where the r-matrix r is not a function of time. The case where r is a function of time leads to an additional velocity component equal to the product of the derivative of r and the position vector.
It is permissible for pv and rpv to be the same array.
SOFA.ry — Method
ry(θ::Real, r::AbstractMatrix{<:Real})Rotate an r-matrix about the y-axis.
Input
θ– angle (radians)r– r-matrix
Output
r– r-matrix, rotated
Note
Calling this function with positive theta incorporates in the supplied r-matrix r an additional rotation, about the y-axis, anticlockwise as seen looking towards the origin from positive y.
The additional rotation can be represented by this matrix:
( + cos(θ) 0 - sin(θ) ) ( ) ( 0 1 0 ) ( ) ( + sin(θ) 0 + cos(θ) )
SOFA.rz — Method
rz(ψ::Real, r::AbstractMatrix{<:Real})Rotate an r-matrix about the z-axis.
Input
ψ– angle (radians)r– r-matrix
Output
r– r-matrix, rotated
Note
Calling this function with positive ψ incorporates in the supplied r-matrix r an additional rotation, about the z-axis, anticlockwise as seen looking towards the origin from positive z.
The additional rotation can be represented by this matrix:
( + cos(ψ) + sin(ψ) 0 ) ( ) ( - sin(ψ) + cos(ψ) 0 ) ( ) ( 0 0 1 )
SOFA.s2c — Method
s2c(θ::Real, ϕ::Real)Convert spherical coordinates to Cartesian.
Input
θ– longitude angle (radians)ϕ– latitude angle (radians)
Output
c– direction cosines
Examples
julia> s2c(3.0123, -0.999)
3-element StaticArraysCore.MVector{3, Float64} with indices SOneTo(3):
-0.5366267667260525
0.06977111097651444
-0.8409302618566215SOFA.s2pv — Method
s2pv(θ::Real, ϕ::Real, r::Real, dθ::Real, dϕ::Real,
dr::Real)Convert position/velocity from spherical to Cartesian coordinates.
Input
θ– longitude angle (radians)ϕ– latitude angle (radians)r– radial distancedθ– rate of change of θdϕ– rate of change of ϕdr– rate of change of r
Output
pv– pv-vector
SOFA.s2xpv — Method
s2xpv(s1::Real, s2::Real, pv::AbstractVector{<:AbstractVector{<:Real}})Multiply a pv-vector by two scalars.
Input
s1– scalar to multiply position component bys2– scalar to multiply velocity component bypv– pv-vector
Output
spv– pv-vector: p scaled by s1, v scaled by s2
SOFA.sepp — Method
sepp(a::AbstractVector{<:Real}, b::AbstractVector{<:Real})Angular separation between two p-vectors.
Input
a– first p-vector (not necessarily unit length)b– second p-vector (not necessarily unit length)
Output
θ– angular separation (radians, always positive)
Note
If either vector is null, a zero result is returned.
The angular separation is most simply formulated in terms of scalar product. However, this gives poor accuracy for angles near zero and pi. The present algorithm uses both cross product and dot product, to deliver full accuracy whatever the size of the angle.
SOFA.seps — Method
seps(λa::Real, ϕa::Real, λb::Real, ϕb::Real)Angular separation between two sets of spherical coordinates.
Input
λa– first longitude (radians)ϕa– first latitude (radians)λb– second longitude (radians)ϕb– second latitude (radians)
Output
θ– angular separation (radians)
Examples
julia> seps(1.0, 0.1, 0.2, -3.0)
2.346722016996999SOFA.tf2a — Method
tf2a(sign::Char, hour::Integer, minute::Integer, second::Real)Convert hours, minutes, seconds to radians.
Input
sign– sign: '-' = negative, otherwise positivehour– hoursminute– minutessecond– seconds
Output
angle– angle in radians
Note
- Unlike the SOFA C function, which computes a result even when the range checks fail (flagging a warning status), this function throws an AssertionError if any argument is out of range.
SOFA.tf2d — Method
tf2d(sign::Char, hour::Integer, minute::Integer, second::Real)Convert hours, minutes, seconds to days.
Input
sign– sign: '-' = negative, otherwise positivehour– hoursminute– minutessecond– seconds
Output
day– interval in days
Note
- Unlike the SOFA C function, which computes a result even when the range checks fail (flagging a warning status), this function throws an AssertionError if any argument is out of range.
SOFA.tr — Method
tr(r::AbstractMatrix{<:Real})Transpose an r-matrix.
Input
r– r-matrix
Output
rt– transpose
Note
It is permissible for r and rt to be the same array.
The name
trfollows the SOFA C library (iauTr) but collides withLinearAlgebra.tr(the matrix trace). When bothSOFAandLinearAlgebraare loaded, an unqualifiedtris ambiguous and must be written asSOFA.trorLinearAlgebra.tr.
SOFA.trxpv — Method
trxpv(r::AbstractMatrix{<:Real}, pv::AbstractVector{<:AbstractVector{<:Real}})Multiply a pv-vector by the transpose of an r-matrix.
Input
r– r-matrixpv– pv-vector
Output
trpv– r^T * pv
Note
The algorithm is for the simple case where the r-matrix r is not a function of time. The case where r is a function of time leads to an additional velocity component equal to the product of the derivative of the transpose of r and the position vector.
It is permissible for pv and rpv to be the same array.