# Bézier Curve and Gravitational Pull

Okay, so I'm trying to manipulate an object programmatically. When it gets near another object, lets say a globe. I want the globe to have a gravitational pull on the original object. This isn't so much a programming question as it is a math question.

Mathematically how could I figure out the three points of the Bézier curve (2nd, 3rd, and end -- I already know the initial point) and give it a weight depending on it's distance (further away = less pull) from the globe.

Think of a spaceship slingshotting around the moon.

Thanks!

-
If you want to calculate the effect of the gravitational pull of one object on another you can use the inverse square law: the magnitude of the gravitational pull is $Gm_1m_2/r^2$ where $m_1$ and $m_2$ are the masses of the two objects, $r$ is the distance between them and $G$ is a constant. The pull is along the line joining the two objects, and it is directed towards the object doing the pulling. Unless I've misunderstood your question, I don't think there's any need to bring bezier curves into it. –  Chris Taylor Jun 6 '11 at 7:51
Unfortunately, I'm writing a game in which the only real way to approach the problem is with bezier curves. I really do appreciate you taking the time to respond though. –  switz Jun 6 '11 at 8:09

Alas, you can't exactly represent the orbit of a satellite around Earth with a Bezier curve. You can approximate it pretty closely, though -- "a four-piece cubic Bézier curve can approximate a circle, with a maximum radial error of less than one part in a thousand". (A Bezier curve can approximate an elliptic or hyperbolic orbit with about the same accuracy). See How elliptic arc can be represented by cubic Bezier curve? .

Perhaps you could use current position, the current velocity, and the current acceleration to approximate a parabolic path (pretty accurate for "shorter" times and distances, increasingly inaccurate for "longer" distances). The acceleration is proportional to the sum of all the forces on the ship -- gravitational force, thrust due to rockets, and any other forces. There's a way to convert the starting position, starting velocity, and starting acceleration (which define a parabolic path) to a cubic Bezier curve ... but there's probably some other not-perfectly-parabolic approach that better takes advantage of the flexibility of the cubic Bezier curve. The Derivatives of a Bézier Curve are:

• Position: B(t) = (1-t)^3 P0 + 3t(1-t)^2 P1 + 3t^2(1-t) P2 + t^3 P3.
• Velocity: B'(t) = 3( (1-t)^2 (P1-P0) + t(1-t) (P2-P1) + t^2 (P3-P2) )
• Acceleration: B''(t) = 2*3( (1-t) ( P2 - 2*P1 + P0 ) + t ( P3 - 2*P2 + P1 ) )

• Initial position = B(0) = P0 (as you already pointed out)

• Initial velocity = B'(0) = 3 (P1 - P0 ) = v0; therefore control point P1 = P0 + v0/3
• Initial acceleration = B''(0) = 6( P2 - 2*P1 + P0 ) = a0; therefore P2 = 2*P1 - P0 + a0/6

This is for endpoint P0 at t=0 seconds, and endpoint P3 at t=1 second. You'll probably want a single Bezier curve to cover minutes or hours (the Bezier "t=1" location corresponding to the location at, say, 2 hours), so you need to scale the acceleration and velocity correspondingly.

Where to place P3 in order to maximize accuracy? Perhaps you could place P3 at some random location -- say, the same place as P2 -- and then, instead of drawing the full Bezier curve from t=0 to t=1 (i.e., from P0 to P3), you could draw just the early, more-accurate part of the Bezier -- where the location of P3 has little effect -- perhaps t=0 to t=1/8 -- and then re-calculate a new acceleration and a completely new Bezier curve starting from that point. I suspect there may be a better approach.

-