Shubham PaulSamhita Ganguly
Published © GPL3+

Calculation of Right Ascension and Declination

The real-time position of any celestial body can be calculated using some parameters called Orbital Elements.

Full instructions provided14,135
Calculation of Right Ascension and Declination

Things used in this project

Software apps and online services

Code::Blocks

Story

Read more

Code

Code snippet #1

Plain text
JD = 2450680.5
Equinox and mean ecliptic of J2000.0

       Earth          Mars

i     0.0       1.8496   
o     0.0       49.668
p     103.147   336.322
a     1.0000    1.523762
n     0.985611  0.523998
e     0.016679  0.093346
L     324.5489  82.9625

The values for the other planets can be found in
the C program below.

Code snippet #2

Plain text
Elements

i - inclination
o - longitude of ascending node at date of elements 
p - longitude of perihelion at date of elements 
a - mean distance (au)
n - daily motion 
e - eccentricity of orbit
l - mean longitude at date of elements

Calculated quantities

M - mean anomaly (degrees)
V - True anomaly (degrees)
r - radius vector (au) referred to current coordinate origin
X - recangular coordinate (au)
Y - recangular coordinate (au)
Z - recangular coordinate (au)
alpha - right ascension (hours or decimal degrees according to
context)
delta - declination (decimal degrees)

Code snippet #4

Plain text
        Days to beginning of month

        Month   Normal year    Leap year
        Jan         0             0
        Feb        31            31
        Mar        59            60
        Apr        90            91
        May       120           121
        Jun       151           152
        Jul       181           182
        Aug       212           213
        Sep       243           244
        Oct       273           274
        Nov       304           305
        Dec       334           335

        Days since J2000 to beginning of each year

                  Days
        1999     -366.5
        2000       -1.5
        2001      364.5
        2002      729.5
        2003     1094.5
        2004     1459.5
        2005     1825.5
Similarly,
        2013     4747.5
        2016     5842.5

Code snippet #9

Plain text
        M = n * d + L - p 

        n is daily motion
        d is the number of days since the date of the elements
        L is the mean longitude
        p is the longitude of perihelion 

        M should be in range 0 to 360 degrees, add or subtract
          multiples of 360 to bring M into this range.

Code snippet #10

Plain text
        n = 0.523998
        d = 928
        L = 82.9625
        p = 336.322

        M = 0.523998 * 928 + 82.9625 - 336.322
          = 232.910644

Code snippet #11

Plain text
v = M + 180/pi * [ (2 * e - e^3/4) * sin(M) + 5/4 * e^2 * sin(2*M)
                             + 13/12 * e^3 * sin(3*M)........ n terms ]

         v is true anomaly
         M is mean anomaly
         e is eccentricity
         pi is 3.14159...

         e^3 means the third power of e. Note how the third
         power is involved the first term as well as the last.


A more expanded series can give a better result so this is what i have used 
in my code :


 v = m + (2 * e - 0.25 *pow(e,3) + 5/96 * pow(e,5)) * sin(m) +
 (1.25 * pow(e,2) - 11/24 * pow(e,4)) * sin(2*m) + 
(13/12 * pow(e,3) - 43/64 * pow(e,5)) * sin(3*m) + 
103/96 * pow(e,4) * sin(4*m) + 1097/960 * pow(e,5) * sin(5*m);

Code snippet #12

Plain text
    M = 232.910644 degrees or 4.065057601 radians
    e = 0.093346
Therefore,
    v = 224.9688989 degrees  or 3.926448  radians

Note: In my code I have done all the calculations in  Radians

Code snippet #13

Plain text
      r = a * (1 - e^2) / [1 + e * cos(v)]
  
          a is the semi-major axis
          e is the eccentricity
          v is the true anomaly

          the radius vector r will be in the same units as a
          a.u. in this case.

Code snippet #14

Plain text
a = 1.523762
e = 0.093346
v =224.9688989

r = 1.523762 * (1 - 0.093346^2) / [ 1 + 0.093346 * cos (224.9688989) ]
  = 1.617293 a.u

Code snippet #15

Plain text
 
    X = r * [cos(o) * cos(v + p - o) - sin(o) * sin(v + p - o) *
    cos(i)]
    Y = r * [sin(o) * cos(v + p - o) + cos(o) * sin(v + p - o) *
    cos(i)]
    Z = r * [sin(v + p - o) * sin(i)]

    r is radius vector
    v is true anomaly
    o is longitude of ascending node
    p is longitude of perihelion
    i is inclination of plane of orbit

    the quantity v + p - o is the angle of the planet measured
    in the plane of the orbit from the ascending node

Code snippet #16

Plain text
    r = 1.617293
    v = 224.9688989
    o = 49.668
    p = 336.322
    i = 1.8496
    v + p - o = 511.6228989 - 360 = 151.6228989
 
    and I get the following rectangular coordinates;

    X  = -1.506606
    Y  = -0.587503
    Z  =  0.024809

    SQRT(X^2 + Y^2 + Z^2) should be same as r

Code snippet #17

Plain text
   Xe = r * cos(v + p)
   Ye = r * sin(v + p)
   Ze = 0

   r is radius vector of Earth
   v is true anomaly for Earth
   p is longitude of perihelion for Earth

Code snippet #21

Plain text
    Xq = X'
    Yq = Y' * cos(ec) - Z' * sin(ec)
    Zq = Y' * sin(ec) + Z' * cos(ec)

    Xq are the equatorial coordinates
    X' are the geocentric ecliptic coordinates      
    ec is the obliquity of the ecliptic 

Code snippet #23

Plain text
    alpha = arctan(Yq/Xq)
     
    If Xq is negative then add 180 degrees to alpha  
    If Xq is positive and Yq is negative then add 360 degrees to
    alpha

    alpha is usually expressed in hours, so divide by 15

    delta = arctan( Zq / SQRT(Xq^2 + Yq^2)) 

    distance = SQRT( Xq^2 + Yq^2 + Zq^2)          

Code snippet #24

Plain text
  (right ascension) alpha = 15.440000 hrs
          
  (declination)  delta = -18.250000 degs
         
   distance = 1.077971278 a.u.      

Alitude-Azimuth Calculator

It is a cpp code that calculates Ra and Declination of all the nine planets with proper data and time as an input and with the Location input it give azimuth and altitude.

Credits

Shubham Paul

Shubham Paul

5 projects • 15 followers
Electronics Engineer | Embedded & Networking Hobbyist | Astrophysics Enthusiast | Otaku
Samhita Ganguly

Samhita Ganguly

5 projects • 13 followers

Comments