BASIC

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

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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
QuadraticBezier2d
QuadraticBezier3d
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




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

Offline Kitty Hello

  • code monkey
  • Administrator
  • Prof. Inline
  • *******
  • Posts: 10723
  • here on my island the sea says 'hello'
    • View Profile
    • http://www.glbasic.com
Excellent! I had once need for that but dropped the idea.

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Yes Beziers have multiple uses, well done Hemlos!  :good:
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)

Offline codegit

  • Dr. Type
  • ****
  • Posts: 270
    • View Profile
Thank you very much. I have played with curves before and this is definitely going into my toolbox.  :good:
------------------------------------------
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)
iPad soon to be added

Offline Qube

  • Mr. Polyvector
  • ***
  • Posts: 157
    • View Profile
Nice work, thanks for sharing  :good:

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
I updated the library, it has 3 samples now, top of thread.
I included a simple program where a game player follows a path.


[attachment deleted by admin]
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)

Offline bigsofty

  • Community Developer
  • Prof. Inline
  • ******
  • Posts: 2640
    • View Profile
Ooh 3D Beziers, nice addition, thanks buddy!  :good:
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)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
Ooh 3D Beziers, nice addition, thanks buddy!  :good:

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)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4152
  • On the shoulders of giants.
    • View Profile
    • My Apps
Hi Hemlos

Have you removed the link for this library? Is it still available for download?
I came. I saw. I played.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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)

Offline Ian Price

  • Administrator
  • Prof. Inline
  • *******
  • Posts: 4152
  • On the shoulders of giants.
    • View Profile
    • My Apps
D'oh! I missed it, thinking it was the screenshot link!

Cheers :)
I came. I saw. I played.

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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:
 Linear, quadratic, and cubic.


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)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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)

Offline Hemlos

  • To boldy go where no pixel has gone before!
  • Global Moderator
  • Prof. Inline
  • *******
  • Posts: 1635
  • Particle Hawk
    • View Profile
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.
Quadratic Bézier curves are quadratic interpolations.
Etc etc..

There are many resources on the internet explaining in great detail how bezier interpolation works.
For further in-depth, examination of this formula set, refer to this link:
http://en.wikipedia.org/wiki/B%C3%A9zier_curve
Volume_of_Earth(km^3) = 4/3*3.14*POW(6371.392896,3)