Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

Newcomers DBPro Corner / Bézier Curve Information

Author
Message
MatriX
21
Years of Service
User Offline
Joined: 19th Oct 2003
Location: Deer Park, New York
Posted: 9th Nov 2003 09:34 Edited at: 7th Jan 2009 02:37
Here's a some information on Bezier Curves. Although I've used them for 12 years I never understood the math before. I learned this today and would like to make it simple for others.

Bezier (Bézier) math is an easy way to describe a curve between two points. Instead of having a two points with many individual points in between to describe a curve, you can have just two additional control points and be more accurate.

There are a few things you need to know about Bezier Curves.

1) You need 4 points in total for a typical bezier curve. They are:

Start Point (X0,Y0)

Control Point 1 (X1,Y1)

Control Point 2 (X2,Y2)

End Point (X3,Y3)


2) To find a point along the curve you will need to perform a two step calculation. The second calculation is based partly on the first so you need to do it in order.

First Set of Calculations:
cx = 3*(X1-X0)
bx = 3*(X2-X1)-cx
ax = X3-X0-Cx-Bx

cy = 3*(Y1 - Y0)
by = 3*(Y2 - Y1)-cy
ay = Y3-Y0-Cy-By


Second Set of Calculations:
Since you want to find a point along the curve you will need to figure out how far along the curve that point is in a decimal percentage. If 0 is the starting point and 1 is the ending point the curve lies inbetween 0 and 1. "t" will be the determining percentage value along the curve. For example to find a curve point at the 50% mark you set "t" to equal ".5"

X(t) = ax*t^3 + bx*t^2 + cx*t + X0

Y(t) = ay*t^3 + by*t^2 + cy*t + Y0

(Note that the "^" means "to the power" or how many times a number is multiplied by itself.)

-----------------------------------------------------
Ok here's an example of one point in a bezier curve. I could post a snippet later to draw this curve although there are other ones already here.

Starting Point:
X0=1
Y0=1

Control Point 1:
X1=3
Y1=5

Control Point 2:
X2=10
Y2=4

End Point:
X3=11
Y3=8

Step 1:
cx = 3*(3-1) (equals 6)
bx = 3*(10-3)-6 (equals 15)
ax = 11-1-6-15 (equals -11)

cy = 3*(5-1) (equals 12)
by = 3*(4-5)-12 (equals -15)
ay = 8-1-12-(-15) (equals 10)

Step 2:
Find the point half way (.5)

X = -11*.5^3 + 15*.5^2 + 6*t + 1 (Equals 6.375)
Y = 10*.5^3 + (-15)*.5^2 + 12*.5 + 1 (Equals 4.5)


Final answer X=6.375, Y=4.5

If you wanted to plot the whole curve you could use a "for next" statement and use the incrementing variable as your "t" value and step it through a small value like .02 (5o steps total etc.)

Good luck!

More info:
http://www.moshplant.com/direct-or/bezier/math.html

1/6/09 - updated this post as the word Bezier had become "Bézier" during a forum transition.

Wannabe Game Designer. Wannabe Programmer. Expert Dreamer.
Long Island Amateur Game Development Group http://www.meetup.com/LIAGDG/
Richard Davey
Retired Moderator
22
Years of Service
User Offline
Joined: 30th Apr 2002
Location: On the Jupiter Probe
Posted: 10th Nov 2003 02:47
Nice description. I posted code to create an interactive bezier curve to the CodeBase here a month or two ago. You can find it in there.

Cheers,

Rich

"It's easy to be mean when death equals a high score screen."
"You can take your Quake and go away, I'd rather play Bubble Bobble any day."

Login to post a reply

Server time is: 2024-11-25 16:51:03
Your offset time is: 2024-11-25 16:51:03