### Author Topic: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic  (Read 15805 times)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« on: 2009-Nov-19 »
Bezier Curves Library - 2d and 3d, Linear, Quadratic,  and Cubic
Created By Neil Silver(aks Hemlos), November 18,2009
These math functions are documented on Wikipedia:
http://en.wikipedia.org/wiki/B%C3%A9zier_curve

Usage of this math is up to your imagination.
Really, this functionality gives alot of power.
You can merge this array with other structures of math to create some awesome stuff.
These curvatures can be applied to structures in middle of the line, or anywhere on it.
You can do alot, you could create tradjectories, or paths.
You can use these with polyvectors to make dynamic flexing objects.
If done proper, you could apply these to 3d object creations also.
The sky is the limit here, and i wish i had more time to makes more samples, but i dont.

6 function library:
LinearBezier2d
LinearBezier3d
CubicBezier2d
CubicBezier3d

Here is the lib with 3 sample projects:
sample1 draws the 2d curves.
sample2 draws a bezier spline
sample3 is a game player and an AI critter following a path

« Last Edit: 2014-Aug-15 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Kitty Hello

• code monkey
• Prof. Inline
• Posts: 10739
• here on my island the sea says 'hello'
##### Re: Bezier Curves Library - Linear, Quadratic, and Cubic
« Reply #1 on: 2009-Nov-19 »
Excellent! I had once need for that but dropped the idea.

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2668
##### Re: Bezier Curves Library - Linear, Quadratic, and Cubic
« Reply #2 on: 2009-Nov-19 »
Yes Beziers have multiple uses, well done Hemlos!
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

#### codegit

• Dr. Type
• Posts: 270
##### Re: Bezier Curves Library - Linear, Quadratic, and Cubic
« Reply #3 on: 2009-Nov-19 »
Thank you very much. I have played with curves before and this is definitely going into my toolbox.
------------------------------------------
1 X Acer TravelMate 4270, laptop, XP PRO
1 X Dell Studio 17 laptop, Windows 7
1 X MacBook Pro 2,2 GHz Core 2 Duo, 2 GB RAM, 160 GB HDD, 9400M
2 X iTouch
1 X HTC Desire (Android 2.1)

#### Qube

• Mr. Polyvector
• Posts: 157
##### Re: Bezier Curves Library - Linear, Quadratic, and Cubic
« Reply #4 on: 2009-Nov-19 »
Nice work, thanks for sharing

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #5 on: 2009-Nov-22 »
Np,

The complete library with sample is in the first message of this thread.
I think i covered all the curves needed.

Unless anyone can think of a really good use for a higher order curve, im leaving this lib as is.

Edit:
You might be able to create a Bezier-Bones, cpu-based 3d bone system, with this lib.
Goodluck, enjoy.

« Last Edit: 2009-Nov-23 by Hemlos »
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #6 on: 2009-Nov-23 »
I updated the library, it has 3 samples now, top of thread.
I included a simple program where a game player follows a path.

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### bigsofty

• Community Developer
• Prof. Inline
• Posts: 2668
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #7 on: 2009-Nov-23 »
Ooh 3D Beziers, nice addition, thanks buddy!
Cheers,

Ian.

“It is practically impossible to teach good programming style to students that have had prior exposure to BASIC.  As potential programmers, they are mentally mutilated beyond hope of regeneration.”
(E. W. Dijkstra)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #8 on: 2009-Dec-06 »
Ooh 3D Beziers, nice addition, thanks buddy!

Yup, you can create curvy paths or lines in 3d space.

I am going to use the 3d quadratic beziers, for homing missles paths, and radar tracking systems for my helicopter HUD.

Also, i was thinking about a 2d vector font system for GLBasic....this should actually be easy to make fonts with...i dont have the time for this now though.
And if youre crafty enough, you could use the 3d beziers for making 3d fonts too.
Vector fonts, like windows font, can be sized, colored, italics, bold, and even line resolution(number of segments, to change font style automatically).
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Ian Price

• Prof. Inline
• Posts: 4158
• On the shoulders of giants.
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #9 on: 2010-Jan-14 »
Hi Hemlos

I came. I saw. I played.

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #10 on: 2010-Jan-14 »
Hi Ian,

The link is above the screenshots.

Here is a shortcut to it:

http://www.glbasic.com/forum/index.php?action=dlattach;topic=3839.0;attach=1279
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Ian Price

• Prof. Inline
• Posts: 4158
• On the shoulders of giants.
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #11 on: 2010-Jan-14 »
D'oh! I missed it, thinking it was the screenshot link!

Cheers
I came. I saw. I played.

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #12 on: 2010-Feb-22 »
Hi Hemlos,

excellent work, I only stumbled across it today.  Thanks for posting it.  Did you ever consider other methods of interpolation?   Longer ago than I care to admit I once dabbled with interpolating cubic and quintic splines, would be nice to have those in GLB as well.

cheers
Ocean

What this lib currently contains for 2d and 3d array structures:

Quintic....i assume this is the form with 2 ends and 3 handles?
Do you need quintic?

I was going to add this, but thought to myself, 'Who in the world would use this?'.
Using quintic only seems to me, to be a daunting task, applying it to something useful.

Please explain to me, what do you mean by 'other methods of interpolation'

Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #13 on: 2010-Apr-01 »
Interpolating can be done by scanning the array.
This library only contains beziers 2d and 3d array structures, for orders of these degrees:
1st 2nd 3rd (linear, quadratic, cubic, respectively)

Im currently trying to create orders of 4th(quartic) and possibly a 5th(named?) degree.
No guarantees...first test run has not been so good...as im missing something in my formula.
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

#### Hemlos

• To boldy go where no pixel has gone before!
• Global Moderator
• Prof. Inline
• Posts: 1635
• Particle Hawk
##### Re: Bezier Curves Library - 2d and 3d, Linear, Quadratic, and Cubic
« Reply #14 on: 2010-Apr-01 »
Knots, handles, control points, are NOT part of the curves.
For 3D animation BÃƒÂ©zier curves are often used to define 3D paths as well as 2D curves for keyframe interpolation.
Linear BÃƒÂ©zier curves are equivalent to linear interpolation.