idlastro / Astronomical Utilities: POSANG

[Source code]

NAME
POSANG
PURPOSE
Computes rigorous position angle of source 2 relative to source 1
EXPLANATION
Computes the rigorous position angle of source 2 (with given RA, Dec) 
using source 1 (with given RA, Dec) as the center.
CALLING SEQUENCE
POSANG, U, RA1, DC1, RA2, DC2, ANGLE
INPUTS
U    -- Describes units of inputs and output:
        0:  everything radians
        1:  RAx in decimal hours, DCx in decimal
                degrees, ANGLE in degrees
RA1  -- Right ascension of point 1
DC1  -- Declination of point 1
RA2  -- Right ascension of point 2
DC2  -- Declination of point 2
UTS:
ANGLE-- Angle of the great circle containing [ra2, dc2] from
        the meridian containing [ra1, dc1], in the sense north
        through east rotating about [ra1, dc1].  See U above 
        for units.
EDURE:
The "four-parts formula" from spherical trig (p. 12 of Smart's
Spherical Astronomy or p. 12 of Green' Spherical Astronomy).
PLE:
For the star 56 Per, the Hipparcos catalog gives a position of 
RA = 66.15593384, Dec = 33.94988843 for component A, and 
RA = 66.15646079, Dec =  33.96100069 for component B.   What is the
position angle of B relative to A?
IDL> RA1 = 66.15593384/15.d   & DC1 = 33.95988843
IDL> RA2 = 66.15646079/15.d   & DC2 = 33.96100069
IDL> posang,1,ra1,dc1,ra2,dc2, ang
     will give the answer of ang = 21.4 degrees
S:
(1) If RA1,DC1 are scalars, and RA2,DC2 are vectors, then ANGLE is a
vector giving the position angle between each element of RA2,DC2 and 
RA1,DC1.   Similarly, if RA1,DC1 are vectors, and RA2, DC2 are scalars,
then DIS is a vector giving the position angle of each element of RA1, 
DC1 and RA2, DC2.    If both RA1,DC1 and RA2,DC2 are vectors then ANGLE 
is a vector giving the position angle between each element of RA1,DC1 
and the corresponding element of RA2,DC2.    If then vectors are not the
same length, then excess elements of the longer one will be ignored.
(2) Note that POSANG is not commutative -- the position angle between
 A and B is theta, then the position angle between B and A is 180+theta 
EDURE CALLS:
 ISARRAY()
ORY:
Modified from GCIRC, R. S. Hill, RSTX, 1 Apr. 1998
Use V6.0 notation W.L. Mar 2011