<p>If I understand your question correctly than your problem is that the primary direction of <code>vCR[3]</code> is the intersection between the prime meridian and the Earth's equator, instead of the vernal equinox. The geographical latitude is the same as the declination, but to get the right ascension you will need to rotate your coordinates around the z-axis by an amount that is equal to the sidereal time at Greenwich ($\theta_G$). This is done, simply by replacing the the longitude (lon) with the sidereal time at your location $\theta = \theta_G-lon$.</p>

<pre><code>x =  R* cos(lat) * cos(theta);
y=   R* cos(lat) * sin(theta);
z =  R* sin(lat);

vCR[3]={x,y,z};
</code></pre>

<p>where <code>theta</code> is the sidereal time $\theta$. </p>

<p>The sidereal time is not a time but actually an angle that gives the right ascension of objects that are at that moment crossing the local meridian (i.e. the line between South and the Celestial north pole, for observers on the northern hemisphere). It is in a sense the longitude of your position on Earth if the geographical coordinate system were to rotate along with the celestial sphere.</p>

<p>EDIT: To calculate the Sidereal time, you can use the method explained in <a href="http://www.willbell.com/math/mc1.htm" rel="nofollow noreferrer">Astronomical Algorithms by Jean Meeus</a>:</p>

<p>$$T = \frac{JD-2451545.0}{3625}$$
$$\theta_0 = 100.46061837 + 36000.770053608 T + 0.000387933 T^2 - \frac{T^3}{38710000}$$</p>

<p>The sidereal time is expressed in degrees.</p>

<p>Then express the UTC time as an angle: </p>

<p>$$t = 15h+0.25m+\frac{0.25}{60}s$$</p>

<p>where $h$ is the number of hours, $m$, the number of minutes, and $s$ the number of seconds.</p>

<p>The sidereal time at Greenwich at the specified time is then:</p>

<p>$$\theta_G = \theta + 1.00273790935*t $$</p>

<p>and the local sidereal time is:</p>

<p>$$\theta = \theta_G - L$$</p>

<p>Where $L$ is the geographical longitude (positive west from Greenwich).</p>

CC BY-SA 3.0
2016-11-29T13:23:48.387Z
Yes this time you understand my problem quite well and the only difference is in longitude and Right ascension (R.A). 

According to my knowledge, sidereal time is the time taken by earth to spin with respect to the STARS not Sun. Further,  

Hour Angle = Sidereal time -  R.A

and if I am not wrong then here you mention theta is basically Hour angle which is actually an angle. If this is the situation so I need to calculate first sidereal time w.r.t Greenwich. i.e. GST. So may you further guide me to how to calculate this? What I already have is modified Julian date (mjd) only.
Saeed_2204
CC BY-SA 3.0
2016-11-29T17:10:28.563Z
No, the hour angle is the angle between the meridian (the line from south through zenith to the celestial north pole) and the longitudinal component of the position of the object. If RA = sidereal time then the hour angle is 0, i.e. the object is on the meridian. The sidereal time is, therefore, the RA of the objects that at that moment pass through the meridian. The sidereal time is NOT a time (which would also imply a date), it is an angle.
Dieudonné
CC BY-SA 3.0
2016-12-04T06:14:30.627Z
I am working on it and i hope it will work ..... thanks for all this
Saeed_2204
CC BY-SA 3.0
2016-12-04T06:58:34.507Z
One more relevant question: If we want to convert geocentric (alt,lat,lon) into geocentric cartesian coordinates (x,y,z), we simply need to use spherical to cartesian transformation formulas i.e.
x= R+h*sin(lat)*cos(lon), y= R+h*sin(lat)*cos(lon), z=R+h*cos(lat)  Or Same formulas with these modifications  lat= lat-90, lon = lon+180.
Saeed_2204
CC BY-SA 3.0
2016-12-05T08:29:55.657Z
I'm not sure I understand your question correctly. If you have geocentric coordinates you have longitude and latitude **and distance** ($d$), I'm not sure what you mean by alt. To get the cartesian coordinates: $x=d\cos(lon)\cos(lat)$, $y=d\sin(lon)\cos(lat)$ and $z=d\sin(lat)$.
Dieudonné
CC BY-SA 3.0
2016-12-05T13:56:47.680Z
Exactly, I was just expressing *d* as **alt** here and these are the right relations, I just want to re-confirm. Thanks.
Saeed_2204
CC BY-SA 3.0
2016-12-05T15:01:52.817Z
I got some results for local sidereal time by following formulation mentioned above but I have doubt either they are correct or not. Can you suggest me a way to re-check my results for further use.
Saeed_2204
CC BY-SA 3.0
2016-12-07T08:06:11.080Z
You can use an online calculator such as [Skywatch](http://www.wwu.edu/skywise/skymobile/skywatch.html) from Western Washington University Planetarium
Dieudonné
CC BY-SA 3.0
2016-11-29T09:28:16.707Z
2016-11-29T18:45:48.040Z
2016-11-29T18:45:48.040Z
Dieudonné
<p>I think, you are mixing two different concepts. Equatorial coordinates are coordinates in the equatorial coordinate system (as opposed to the ecliptical, galactic, super galactic, or horizontal coordinate systems). The coordinates also refer to a specific origin. This origin might be heliocentric (centre of the Sun), baryocentric (centre of mass of the Solar System), geocentric (centre of the Earth), or topocentric (a specific location on the Earth's ellipsoid).</p>

<p>So you may have heliocentric equatorial coordinates, geocentric equatorial coordinates, or topocentric equatorial coordinates. </p>

<p>From your question I infer that you have <em>geocentric</em> coordinates of the Moon and you want to convert them to <em>topocentric</em> (not geocentric!) coordinates for an observer at a specific location (latitude and longitude) on the Earth.</p>

<p>The best way to go about this would be to:</p>

<ul>
<li><p>First, convert you geocentric equatorial coordinates to its rectangular equivalent (i.e. find the $X_M$, $Y_M$, and $Z_M$ equatorial coordinates).</p></li>
<li><p>Second calculate the $X_o$, $Y_o$, and $Z_o$ coordinates of the observer on Earth in the equatorial system.</p></li>
<li><p>Third, subtract the $X_o$, $Y_o$, and $Z_o$ coordinates of the observer from the $X_M$, $Y_M$, and $Z_M$ coordinates of the Moon.</p></li>
<li><p>Finally, convert the coordinates back to spherical coordinates, i.e. the $X$, $Y$, and $Z$ coordinates back to right ascension, declination, and distance.</p></li>
</ul>

<p>If you have the geocentric right ascension $\alpha_M$, declination $\delta_M$, and distance $d_M$, then you can get the rectangular coordinates from:</p>

<p>$$ X_M = d_M \cos(\alpha_M) \cos(\delta_M) $$
$$ Y_M = d_M \sin(\alpha_M) \cos(\delta_M) $$
$$ Z_M = d_M \sin(\delta_M)  $$</p>

<p>The $X$-axis is pointed towards the vernal equinox, and the $Z$-axis is pointed towards the celestial north pole (i.e. parallel with the Earth's rotation axis).</p>

<p>For the rectangular equatorial coordinates of the observer, you need the geographical latitude ($\phi$) and longitude ($L$), the elevation ($H$) and the sidereal time ($\theta$). </p>

<p>To calculate the rectangular coordinates of the observer is a bit more difficult as the Earth's surface is (approximately) an ellipsoid. The following is taken from <a href="http://www.willbell.com/math/mc1.htm" rel="nofollow noreferrer">Jean Meeus book, Astronomical Algorithms</a>:</p>

<p>$$b' = 0.99664719$$</p>

<p>which is a measure of the ellipsoid.</p>

<p>$$ u = \arctan(b' \tan(\phi)) $$
$$ \rho\sin(\phi) = R_E b' \sin(u) + H \sin(\phi)) $$
$$ \rho\cos(\phi) = R_E \cos(u) + H \cos(\phi) $$</p>

<p>where $R_E = 6378140.0 \textrm{m}$ is the Earth's radius.
We can then calculate the rectangular geocentric equatorial coordinates of the observer:</p>

<p>$$ X_o =  \rho \cos(\phi) \cos(\theta)$$
$$ Y_o =  \rho \cos(\phi) \sin(\theta)$$
$$ Z_o =  \rho \sin(\phi) $$</p>

<p>The topocentric rectangular equatorial coordinates of the Moon are then:</p>

<p>$$ X = X_M - X_o $$ 
$$ Y = Y_M - Y_o $$ 
$$ Z = Z_M - Z_o $$ </p>

<p>Then convert back to spherical coordinates:</p>

<p>$$ d' = \sqrt{X^2 + Y^2 + Z^2} $$
$$ \alpha' = \arctan \left(\frac{Y}{X} \right) $$
$$ \delta' = \arcsin \left(\frac{Z}{d'} \right) $$</p>

<p>You then have the topocentric equatorial coordinates of the Moon: right ascension $\alpha'$, declination $\delta'$ and the distance $d'$.</p>

<p>You will have to make sure that $\alpha'$ is in the correct quadrant. Programmatically this can be easily achieved with the <code>atan2</code> function, i.e. <code>alpha = atan2(y,x)</code>.</p>

<p>I haven't tested these formulae so I hope that they are correct.</p>

CC BY-SA 3.0
2016-11-27T00:28:49.530Z
First of all, thanks for your kind reply. Now directly come to my point. Actually, I am dealing with two things simultaneously. More precisely, I have moon’s position (yes) in equatorial geocentric coordinates with following details:
 Origin: Center of Earth
 Lat      : Declination With fundamental Plane: Celestial Equator
 Lon     : R.A.  With Primary direction: Vernal Equinox
And I am able to obtain the moon’s position corresponding to a specific Modified Julian Date (MJD) by recalling a subroutine like 
 moon_pos(mjd, &ra_moon, &dec_moon);
Saeed_2204
CC BY-SA 3.0
2016-11-27T21:47:37.743Z
Then `ra_moon` will contain the right ascension of the moon ($\alpha_M$) and `dec_moon` will contain the declination of the moon ($\delta_M$), which you can use in the formulae above. You will, however, also need the distance to the moon, otherwise you will never be able to determine topocentric coordinates. You can only find the parallax if you know the distance.
Dieudonné
CC BY-SA 3.0
2016-11-29T01:35:45.107Z
the previous comment was not complete because of limitation of words here so i wrote it down again so sorry for this inconvenience.
Saeed_2204
CC BY-SA 3.0
2016-11-25T12:58:05.397Z
2016-11-25T13:41:17.640Z
2016-11-25T13:41:17.640Z
Dieudonné
<p>I have the moon's position in equatorial coordinates (RA and Dec) and now I want to calculate same moon's position in terms of earth centered coordinates i.e. Geocentric (latitude &amp; longitude). My main goal is to establish a c++-code that gives me this transformation from RA,Dec to Lat,Lon and vice versa. </p>

<p><em>EDIT</em>: More precisely, I have moon’s position in equatorial geocentric coordinates with following details:</p>

<p><em>Origin: Center of Earth</em><br>
<em>Lat   : Declination With fundamental Plane: Celestial Equator</em><br>
<em>Lon   : R.A.        With Primary direction: Vernal Equinox</em></p>

<p>And I am able to obtain the moon’s position corresponding to a specific Modified Julian Date (MJD). I am also able to calculate moon’s position in xyz-coordinates by following calculations</p>

<p>$X= EarthMoon*sin(PI/2.-dec_moon*deg2rad)*cos(ra_moon*deg2rad);$
$Y= EarthMoon*sin(PI/2.-dec_moon*deg2rad)*sin(ra_moon*deg2rad);$
$Z= EarthMoon*cos(PI/2.-dec_moon*deg2rad);$</p>

<p>where EarthMoon is the distance between Earth and Moon. Further, I am converting them into Horizon Coordinates (topocentric) w.r.t to an observer at a specific location by using my subroutine and this part done.</p>

<p>Further, I am initiating my simulated CR-particles from observer site. E.g. vCR[3]= {R,lat,lon}</p>

<p><em>vCR[3]={Rearth+2300, 31.30, 55.74}</em> //Geocentric CS (earth-based)</p>

<p>And converting them into Geocentric Cartesian coordinates(x,y,z). Finally, I have</p>

<p><em>vM[3]={X,Y,Z};</em> in Equatorial geocentric coordinate system<br>
<em>vCR[3]={x,y,z};</em> in Geocentric Coordinate System i.e. Earth based  </p>

<p>That is my particular question in which I want to make vM[moon position] and vCR[CR position] to lie in same coordinates to get my final result. i.e. transformation from Geocentric (R,lat,lon) into Equatorial Geocentric (h,R.A,Dec).<br>
<strong>Note</strong>: For vCR[3]: zero-longitude is the Prime Meridian, Greenwich whereas for vM[3] it’s vernal equinox in celestial sphere there is the difference.</p>

<earth><coordinate>
Transformation from Geocentric Coordinates into Equatorial Coordinates?
Saeed_2204
# Transformation from Geocentric Coordinates into Equatorial Coordinates?

(Asked by: username_0 on 2016-11-25)

I have the moon's position in equatorial coordinates (RA and Dec) and now I want to calculate same moon's position in terms of earth centered coordinates i.e. Geocentric (latitude & longitude). My main goal is to establish a c++-code that gives me this transformation from RA,Dec to Lat,Lon and vice versa.

*EDIT*: More precisely, I have moon’s position in equatorial geocentric coordinates with following details:

*Origin: Center of Earth*  
*Lat : Declination With fundamental Plane: Celestial Equator*  
*Lon : R.A. With Primary direction: Vernal Equinox*

And I am able to obtain the moon’s position corresponding to a specific Modified Julian Date (MJD). I am also able to calculate moon’s position in xyz-coordinates by following calculations

$X= EarthMoon\*sin(PI/2.-dec\_moon\*deg2rad)\*cos(ra\_moon\*deg2rad);$
$Y= EarthMoon\*sin(PI/2.-dec\_moon\*deg2rad)\*sin(ra\_moon\*deg2rad);$
$Z= EarthMoon\*cos(PI/2.-dec\_moon\*deg2rad);$

where EarthMoon is the distance between Earth and Moon. Further, I am converting them into Horizon Coordinates (topocentric) w.r.t to an observer at a specific location by using my subroutine and this part done.

Further, I am initiating my simulated CR-particles from observer site. E.g. vCR[3]= {R,lat,lon}

*vCR[3]={Rearth+2300, 31.30, 55.74}* //Geocentric CS (earth-based)

And converting them into Geocentric Cartesian coordinates(x,y,z). Finally, I have

*vM[3]={X,Y,Z};* in Equatorial geocentric coordinate system  
*vCR[3]={x,y,z};* in Geocentric Coordinate System i.e. Earth based

That is my particular question in which I want to make vM[moon position] and vCR[CR position] to lie in same coordinates to get my final result. i.e. transformation from Geocentric (R,lat,lon) into Equatorial Geocentric (h,R.A,Dec).  
**Note**: For vCR[3]: zero-longitude is the Prime Meridian, Greenwich whereas for vM[3] it’s vernal equinox in celestial sphere there is the difference.

**Tags:** earth, coordinate


---

## 2 answers

### Answer by username_1 on 2016-11-29. Score: 3

If I understand your question correctly than your problem is that the primary direction of vCR[3] is the intersection between the prime meridian and the Earth's equator, instead of the vernal equinox. The geographical latitude is the same as the declination, but to get the right ascension you will need to rotate your coordinates around the z-axis by an amount that is equal to the sidereal time at Greenwich ($\theta_G$). This is done, simply by replacing the the longitude (lon) with the sidereal time at your location $\theta = \theta_G-lon$.
x =  R* cos(lat) * cos(theta);
y=   R* cos(lat) * sin(theta);
z =  R* sin(lat);

vCR[3]={x,y,z};

where theta is the sidereal time $\theta$. 
The sidereal time is not a time but actually an angle that gives the right ascension of objects that are at that moment crossing the local meridian (i.e. the line between South and the Celestial north pole, for observers on the northern hemisphere). It is in a sense the longitude of your position on Earth if the geographical coordinate system were to rotate along with the celestial sphere.
EDIT: To calculate the Sidereal time, you can use the method explained in Astronomical Algorithms by Jean Meeus:
$$T = \frac{JD-2451545.0}{3625}$$
$$\theta_0 = 100.46061837 + 36000.770053608 T + 0.000387933 T^2 - \frac{T^3}{38710000}$$
The sidereal time is expressed in degrees.
Then express the UTC time as an angle: 
$$t = 15h+0.25m+\frac{0.25}{60}s$$
where $h$ is the number of hours, $m$, the number of minutes, and $s$ the number of seconds.
The sidereal time at Greenwich at the specified time is then:
$$\theta_G = \theta + 1.00273790935*t $$
and the local sidereal time is:
$$\theta = \theta_G - L$$
Where $L$ is the geographical longitude (positive west from Greenwich).

> **Comments:**
> **username_0**: Yes this time you understand my problem quite well and the only difference is in longitude and Right ascension (R.A).   According to my knowledge, sidereal time is the time taken by earth to spin with respect to the STARS not Sun. Further,    Hour Angle = Sidereal time -  R.A  and if I am not wrong then here you mention theta is basically Hour angle which is actually an angle. If this is the situation so I need to calculate first sidereal time w.r.t Greenwich. i.e. GST. So may you further guide me to how to calculate this? What I already have is modified Julian date (mjd) only.  
> **username_1**: No, the hour angle is the angle between the meridian (the line from south through zenith to the celestial north pole) and the longitudinal component of the position of the object. If RA = sidereal time then the hour angle is 0, i.e. the object is on the meridian. The sidereal time is, therefore, the RA of the objects that at that moment pass through the meridian. The sidereal time is NOT a time (which would also imply a date), it is an angle.  
> **username_0**: I am working on it and i hope it will work ..... thanks for all this  
> **username_0**: One more relevant question: If we want to convert geocentric (alt,lat,lon) into geocentric cartesian coordinates (x,y,z), we simply need to use spherical to cartesian transformation formulas i.e. x= R+h*sin(lat)*cos(lon), y= R+h*sin(lat)*cos(lon), z=R+h*cos(lat)  Or Same formulas with these modifications  lat= lat-90, lon = lon+180.  
> **username_1**: I'm not sure I understand your question correctly. If you have geocentric coordinates you have longitude and latitude **and distance** ($d$), I'm not sure what you mean by alt. To get the cartesian coordinates: $x=d\cos(lon)\cos(lat)$, $y=d\sin(lon)\cos(lat)$ and $z=d\sin(lat)$.  
> **username_0**: Exactly, I was just expressing *d* as **alt** here and these are the right relations, I just want to re-confirm. Thanks.  
> **username_0**: I got some results for local sidereal time by following formulation mentioned above but I have doubt either they are correct or not. Can you suggest me a way to re-check my results for further use.  
> **username_1**: You can use an online calculator such as [Skywatch](http://www.wwu.edu/skywise/skymobile/skywatch.html) from Western Washington University Planetarium  

---

### Answer by username_1 on 2016-11-25. Score: 1

I think, you are mixing two different concepts. Equatorial coordinates are coordinates in the equatorial coordinate system (as opposed to the ecliptical, galactic, super galactic, or horizontal coordinate systems). The coordinates also refer to a specific origin. This origin might be heliocentric (centre of the Sun), baryocentric (centre of mass of the Solar System), geocentric (centre of the Earth), or topocentric (a specific location on the Earth's ellipsoid).

So you may have heliocentric equatorial coordinates, geocentric equatorial coordinates, or topocentric equatorial coordinates.

From your question I infer that you have *geocentric* coordinates of the Moon and you want to convert them to *topocentric* (not geocentric!) coordinates for an observer at a specific location (latitude and longitude) on the Earth.

The best way to go about this would be to:

* First, convert you geocentric equatorial coordinates to its rectangular equivalent (i.e. find the $X\_M$, $Y\_M$, and $Z\_M$ equatorial coordinates).
* Second calculate the $X\_o$, $Y\_o$, and $Z\_o$ coordinates of the observer on Earth in the equatorial system.
* Third, subtract the $X\_o$, $Y\_o$, and $Z\_o$ coordinates of the observer from the $X\_M$, $Y\_M$, and $Z\_M$ coordinates of the Moon.
* Finally, convert the coordinates back to spherical coordinates, i.e. the $X$, $Y$, and $Z$ coordinates back to right ascension, declination, and distance.

If you have the geocentric right ascension $\alpha\_M$, declination $\delta\_M$, and distance $d\_M$, then you can get the rectangular coordinates from:

$$ X\_M = d\_M \cos(\alpha\_M) \cos(\delta\_M) $$
$$ Y\_M = d\_M \sin(\alpha\_M) \cos(\delta\_M) $$
$$ Z\_M = d\_M \sin(\delta\_M) $$

The $X$-axis is pointed towards the vernal equinox, and the $Z$-axis is pointed towards the celestial north pole (i.e. parallel with the Earth's rotation axis).

For the rectangular equatorial coordinates of the observer, you need the geographical latitude ($\phi$) and longitude ($L$), the elevation ($H$) and the sidereal time ($\theta$).

To calculate the rectangular coordinates of the observer is a bit more difficult as the Earth's surface is (approximately) an ellipsoid. The following is taken from [Jean Meeus book, Astronomical Algorithms](http://www.willbell.com/math/mc1.htm):

$$b' = 0.99664719$$

which is a measure of the ellipsoid.

$$ u = \arctan(b' \tan(\phi)) $$
$$ \rho\sin(\phi) = R\_E b' \sin(u) + H \sin(\phi)) $$
$$ \rho\cos(\phi) = R\_E \cos(u) + H \cos(\phi) $$

where $R\_E = 6378140.0 \textrm{m}$ is the Earth's radius.
We can then calculate the rectangular geocentric equatorial coordinates of the observer:

$$ X\_o = \rho \cos(\phi) \cos(\theta)$$
$$ Y\_o = \rho \cos(\phi) \sin(\theta)$$
$$ Z\_o = \rho \sin(\phi) $$

The topocentric rectangular equatorial coordinates of the Moon are then:

$$ X = X\_M - X\_o $$
$$ Y = Y\_M - Y\_o $$
$$ Z = Z\_M - Z\_o $$

Then convert back to spherical coordinates:

$$ d' = \sqrt{X^2 + Y^2 + Z^2} $$
$$ \alpha' = \arctan \left(\frac{Y}{X} \right) $$
$$ \delta' = \arcsin \left(\frac{Z}{d'} \right) $$

You then have the topocentric equatorial coordinates of the Moon: right ascension $\alpha'$, declination $\delta'$ and the distance $d'$.

You will have to make sure that $\alpha'$ is in the correct quadrant. Programmatically this can be easily achieved with the `atan2` function, i.e. `alpha = atan2(y,x)`.

I haven't tested these formulae so I hope that they are correct.

> **Comments:**
> **username_0**: First of all, thanks for your kind reply. Now directly come to my point. Actually, I am dealing with two things simultaneously. More precisely, I have moon’s position (yes) in equatorial geocentric coordinates with following details:  Origin: Center of Earth  Lat      : Declination With fundamental Plane: Celestial Equator  Lon     : R.A.  With Primary direction: Vernal Equinox And I am able to obtain the moon’s position corresponding to a specific Modified Julian Date (MJD) by recalling a subroutine like   moon_pos(mjd, &ra_moon, &dec_moon);  
> **username_1**: Then `ra_moon` will contain the right ascension of the moon ($\alpha_M$) and `dec_moon` will contain the declination of the moon ($\delta_M$), which you can use in the formulae above. You will, however, also need the distance to the moon, otherwise you will never be able to determine topocentric coordinates. You can only find the parallax if you know the distance.  
> **username_0**: the previous comment was not complete because of limitation of words here so i wrote it down again so sorry for this inconvenience.  

---

