-1

I've an example of how to get a geocentric position of Mars (x,y,z cords) relative to the Earth, using class skyfield.positionlib.Geocentric(position_au, velocity_au_per_d=None, t=None, center=None, target=None) (without accounting for light-travel time or the effect of relativity on the light itself).

There it is:

t = ts.utc(2022, 9, 16)  

e = earth.at(t) 
m = mars.at(t)  

p = e.position.au - m.position.au 
if e.velocity is None or m.velocity is None:     
   v = None 
else:     
   v = e.velocity.au_per_d - m.velocity.au_per_d  

astrometric = e.observe(mars).xyz 
geocentric = Geocentric(p, v, e.t).xyz  

print(astrometric) 
print(geocentric) 

Output:

[0.24429594 0.77369215 0.31846684] au

[-0.24426364 -0.77375285 -0.31849556] au

Is it good? And why second coords are < 0?

P.S. Sun coords are more confusing! Why?

[-0.99764586 0.11540818 0.05003455] au

[ 0.99764586 -0.11540813 -0.05003453] au

denken
  • 11
  • 3
  • You should rephrase your question to be "why are these coordinates negative?" since that makes clear to readers that you have already done the work of generating the coordinates, but don't understand their mathematical sign. Asking "Please give an example" maybe makes it sound like you want other programmers to write you a new program for free, which they will consider offensive, and down-vote your question. – Brandon Rhodes Sep 16 '22 at 15:13
  • You are right! Title changed. Thanks! – denken Sep 17 '22 at 07:17

1 Answers1

0

The way that vector math works, a positive vector +v goes toward that position, whereas a negative vector -v goes backwards away from that position to the origin. So if you say a - b with two vectors, you are asking to be taken mathematically from the place where b is and to the place where a is.

So your math for v = is backwards. You are asking for the vector going Mars → Earth, or, in other words, for the mars-centric position of Earth, whereas you really want the opposite.

Brandon Rhodes
  • 83,755
  • 16
  • 106
  • 147