Jump to content
• Advertisement

Eliminating Bezier Parameter

This topic is 5404 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

If you intended to correct an error in the post then please contact us.

Recommended Posts

I'm trying to find a formula to map X values to Y values using a simple Bezier curve. The curve has two endpoints - (0,0) and (1,Q) - and one control point, (Xc, Yc). I've been treating the curve as parametric so far, and thus formulated:
X(t) = (0)(1-t) + (Xc)(2t(1-t)) + (1)t = (2t - 2t^2)Xc + t
Y(t) = (0)(1-t) + (Yc)(2t(1-t)) + (Q)t = (2t - 2t^2)Yc + Qt

with the intention of eliminating the parameter. Rearranging the formulae to isolate (2t - 2t^2), I then equated:
(X(t) - t)/Xc = (Y(t) - Qt)/Yc

and eventually
Y(t) = (Yc/Xc)X(t) - t( (Yc/Xc) - Q)

where I'm stuck. Can anyone help me eliminate the remaining t, leaving Y(t) in terms of X(t)?

Share this post

Share on other sites
Advertisement
Seems there would be a problem since nothing guarantees that 0<xc<1 so potentially you have two y values for some values of x.

Share this post

Share on other sites
Oh - I can guarantee that :)

Share this post

Share on other sites
Quote:
 Original post by superpigX(t) = (0)(1-t) + (Xc)(2t(1-t)) + (1)t = (2t - 2t^2)Xc + tY(t) = (0)(1-t) + (Yc)(2t(1-t)) + (Q)t = (2t - 2t^2)Yc + Qt

Wasn't the formula:

X(t) = (0)(1-t)^2 + (Xc)(2t(1-t)) + (1)t^2 = (2t - 2t^2)Xc + t^2Y(t) = (0)(1-t)^2 + (Yc)(2t(1-t)) + (Q)t^2 = (2t - 2t^2)Yc + Q*t^2

Crap.

Yes :-/

*reworks*

Share this post

Share on other sites
X(t) = (0)(1-t)^2 + (Xc)(2t(1-t)) + (1)t^2 = (2t - 2t^2)Xc + t^2 = XY(t) = (0)(1-t)^2 + (Yc)(2t(1-t)) + (Q)t^2 = (2t - 2t^2)Yc + Q*t^2 = YThen solve the first equation for t:X = t^2*(1-2*Xc) + 2*t*Xct = -Xc/(1-2*Xc) + sqrt(Xc^2 + X*(1-2*Xc))/(1-2*Xc)since 0 <= t <= 1Then solve the second equation for Y with the t found...Y = (X - 2*t*Xc)*(Q-2*Yc)/(1-2*Xc) + 2*t*Yc

Share this post

Share on other sites
OK, but I have to boil this down further.

To help things out, I'm going to limit things such that Q always equals 1.

I have to rearrange it to get Y on its own, and if possible, I need to eliminate the square roots (I'm going to try and do these calculations on vertex shader 1.1 hardware).

If I let Xp = 1 - 2Xc, and Yp = 1 - 2Yc, I get:

YpXc + sqrt(YpYpXcXc + YpYpXpX) = XpYc + sqrt(XpXpYcYc + XpXpYpY)

How can I solve that to get Y on its own, without any square roots around the X on the other side? (Square roots around constant values are fine, I can calculate those on the CPU).

Share this post

Share on other sites
Quote:
 Original post by superpigIf I let Xp = 1 - 2Xc, and Yp = 1 - 2Yc, I get:YpXc + sqrt(YpYpXcXc + YpYpXpX) = XpYc + sqrt(XpXpYcYc + XpXpYpY)

Heinous, its not gonna be a good performance function:

(YpXc-XpYc) + sqrt(YpYpXcXc + YpYpXpX) = sqrt(XpXpYcYc + XpXpYpY)

square the whole equation, and you'll be left with one swrt (namely with sqrt(YpYpXcXc + YpYpXpX) in your second term on the left side). Take everything but the sqrt to the right and square again. Turn your in disgust at the look of the new equation and then try and sort it out the best u can. Or find a way to work with the original, elegant, parameter equation.

Share this post

Share on other sites
You are using a bezier curve of second order. So I don't believe you can bring it down to a linear equation or something.

And why not calculate the sqrt ? You can do it very fast with some approximation. Or does it have to be exact ?

The equation right now looks like this, assuming Xc and Yc do not change:

t = a + sqrt(b + X * c)
and
Y = d * X + e * t

which gives

Y = d * X + l + e * sqrt(m + X * n)

Share this post

Share on other sites
Thanks for the help guys, I've been told to forget beziers and just use linear interpolation [grin]

Share this post

Share on other sites

• Advertisement
• Advertisement

• Popular Now

• 21
• 13
• 9
• 17
• 13
• Advertisement
×

Important Information

By using GameDev.net, you agree to our community Guidelines, Terms of Use, and Privacy Policy.

GameDev.net is your game development community. Create an account for your GameDev Portfolio and participate in the largest developer community in the games industry.

Sign me up!