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!
 A: 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 Bézier 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.
