Bezier Curves Maths Problem
- SantoNinoDeCebu
-
SantoNinoDeCebu
- Member since: Jul. 20, 2002
- Offline.
-
- Forum Stats
- Supporter
- Level 32
- Programmer
Its not actually a programming problem, rather the maths behind the code (but there is no maths forum here!) Just figured there might be someone here who knows this stuff!
I'm currently playing with bezier curves on Opengl to make some cool curves that could potentially become rollercoasters or somthing!
I'm currently trying to calculate the parameter (t) of a cubic bezier curve that is a certain distance along the curve from a previous known point. Here's a specific made up example of what I'm trying to calculate.
Bezier curve has control points (1,1), (2,7),(8,6), (12,2)
I have an object attached to it at parameter t = 0.4 - this coordinate comes out to be (4.152,5.096) (I use deCasteljau algorithm to calculate this in my program)
Now I have worked out that I would like to move the object 1.5 units along the curve.
Is there any methods for calculating the value of t at this new position of 1.5 units along the curve from (4.152,5.096) - were t = 0.4
If anyone has an idea about bezzie curves and has an idea on this problem that would be great ;)
Thanks.
- henke37
-
henke37
- Member since: Sep. 10, 2004
- Offline.
-
- Forum Stats
- Member
- Level 30
- Blank Slate
Here is what I did: I phrased the x position on the curve as a series of equations, inserted them into each other and finally solved for t. Then it's just a matter of inserting the data and getting the corresponding t values. If you have the y position as well, you should be able to repeat this and crossrefference the solutions, the ones that are shared are t value for that point.
Each time someone abuses hittest, God kills a kitten. Please, learn real collision testing.
- GustTheASGuy
-
GustTheASGuy
- Member since: Nov. 2, 2005
- Offline.
-
- Send Private Message
- Browse All Posts (12,016)
- Block
-
- Forum Stats
- Member
- Level 08
- Blank Slate
- Glaiel-Gamer
-
Glaiel-Gamer
- Member since: Dec. 28, 2004
- Offline.
-
- Forum Stats
- Member
- Level 28
- Game Developer
At 12/30/09 03:59 PM, SantoNinoDeCebu wrote: If anyone has an idea about bezzie curves and has an idea on this problem that would be great ;)
Thanks.
This requires calculus I believe (probably can reduce it down simpler).
Anyway first grab the equation for X and the equation for Y of the curve (+Z, +W, and so on)
Integral length formula for parametric equation is integral(sqrt((dx/dt)^2+(dy/dt)^2)) I believe, so differentiate each equation, square, and add together. This reduces into just a polynomial in t, with constants. Then integrating the square root of that is difficult, so just use a numeric solver for that (adding up lengths until you pass the target length). That's all I can think of right now, there probably is a discreet equation mapping T to distance, but I can't remember.
- eerr
-
eerr
- Member since: Dec. 26, 2009
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
At 1/1/10 11:40 AM, Glaiel-Gamer wrote:At 12/30/09 03:59 PM, SantoNinoDeCebu wrote: If anyone has an idea about bezzie curves and has an idea on this problem that would be great ;)This requires calculus I believe (probably can reduce it down simpler).
Thanks.
Anyway first grab the equation for X and the equation for Y of the curve (+Z, +W, and so on)
Integral length formula for parametric equation is integral(sqrt((dx/dt)^2+(dy/dt)^2)) I believe, so differentiate each equation, square, and add together. This reduces into just a polynomial in t, with constants. Then integrating the square root of that is difficult, so just use a numeric solver for that (adding up lengths until you pass the target length). That's all I can think of right now, there probably is a discreet equation mapping T to distance, but I can't remember.
if x=(a function of t)
and
y= (a function of t)
you can find the arc length from t=0, to t=a
using http://www.wolframalpha.com/,
differentiate the formula for x
type in something like d/dt(3t^2)
differentiate the formula for y
type in something like d/dt(1+5t^3)
copy and paste dx and dy into
integral sqrt((dx)^2 + (dy)^2)
then plug in a, returning the value of a from 0 to T.
Also, ignore the following Incoherent ramble, unless you want a way to approximate arclength.
Ah nevermind, I'll cut it.
- SantoNinoDeCebu
-
SantoNinoDeCebu
- Member since: Jul. 20, 2002
- Offline.
-
- Forum Stats
- Supporter
- Level 32
- Programmer
Hey thanks for the info guys, I should be able to work out what I need from that!
I'm guessing I would jsut add dz into the integral in the same fashion? sqrt(dx^2 + dy^2 + dz^2)/dt
Cheers
- DougyTheFreshmaker
-
DougyTheFreshmaker
- Member since: Jul. 30, 2007
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
We should take care not to make the intellect our god; it has, of course, powerful muscles, but no personality.
Freshmaking
Brainscrape
- eerr
-
eerr
- Member since: Dec. 26, 2009
- Offline.
-
- Forum Stats
- Member
- Level 02
- Blank Slate
I have 50/50 odds that wolfram alpha can take it like a man. but that was with just dx and dy
From what I can tell, you need to use the formula twice.
i=?integral( sqrt(dx^2 + dy^2)
di=sqrt(dx^2+dy^2)
L=integral sqrt(dz^2 + di^2)
L=integral sqrt(dz^2 sqrt(dx^2 + dy^2)^2)
Ah nevermind, the dervivative, integral, cube and cube root all cancel.
Funny eh?
L=integral sqrt(dz^2 +dx^2 + dy^2)

