[ODE] vector force

David Taylor dajt at tpg.com.au
Fri Feb 2 19:00:28 MST 2007


Hi,

Thanks for the answer to my question about gravity and planets from a few days ago. I believe the information below is the answer to my next question...

So to manually add the force of gravity to a spaceship in a space sim, I would make a vector from each spaceship to each gravity source (star, planets), normalise it, and then set the length of the vector to whatever the force of gravity would be at the distance from the body to the spaceship?

Regards,
David Taylor.

> To get a vector V that points from point A to point B:
> 
> V = ( B.x - A.x  ,  B.y - A.y  ,   B.z - A.z )
> 
> Done. The vector's length L is proportional to the euclidean distance
> between A and B. That is:
> 
> L = sqrt(V.x^2 + V.y^2 + V.z^2)
> 
> If you divide each component in V by L, you get a "normalized vector"
> V', that has the same direction as V, but with length 1.
> 
> V' = ( V.x/L  ,   V.y/L  ,  V.z/L )
> 
> Now, if you want a vector W with length 10, just multiply each component
> in V' by 10:
> 
> W = ( V'.x*10  ,  V'.y*10  ,  V'.z*10 )



More information about the ODE mailing list