[Home]

[Dave G's Animation System]

[Download]

[Links]

Welcome to Bezier Curves for POV-Ray

Dave G's Bezier Curve System (DGBZ) and Dave G's Multiple Curve System (DGMBZ) are written to give fill a void I found in POV-Ray.

Why DGBZ and DGMBZ?

POV-Ray is an incredibly powerful renderer, but other than the supplied clock variable there are not too many facilities for animation. If you want to move a particle along a curve, or a complex path, you've been out of luck so far.

There have been some external path utilities, but they're system specific. If you don't use DOS then the DOS utilities are useless to you.

There have been a few bezier curve files around but they have two limitations.

  1. They use the simple method of calculating points along a bezier curve. The curve can't be broken up into equal length segments.
  2. They don't join curves in a path. And without the ability to travel along a curve at a consistent rate it is hard to simulate multiple curves in a path.

So how do I use it for a single curve?

Both systems are just include files. Three include files make up the system (DGBZ.INC and DGMBZ.INC which you include, and DGBZINT.INC which is called by the first two include files).

For single bezier curves it is very simple. To calculate a traditional (and fast) bezier curve position, here is all you have to do.

You simply define the curve or path and call the file.

I use the notation of C0 through C3, which seems to be the standard in all textbooks on computer graphics and curves.

Simply fill in the value and DGBZ will calculate the point for you.

#declare DGBZCommand = "POSITION"
#declare DGBZC0 = <0,0,0>
#declare DGBZC1 = <0,1,0>
#declare DGBZC2 = <5,1,3>
#declare DGBZC3 = <5,0,3>
#declare DGBZAmount = clock
#include "DGBZ.INC"

// The result is stored in...
DGBZPosition

If you want to find an accurate position along the length of the curve, you simply add one line before the #include:

To change the calculation, just specify an exact calculation rather than an approximate one.

There is a downside to this accuracy. The calculation takes a long time. Many seconds, not just a fraction of a second.

#declare DGBZCalc_Type = "EXACT"

How Does It Find an Exact Position Along a Curve?

Its actually very simple. I fake it. Instead of re-learning calculus and advanced math I simply use brute force. I integrate the curve the old fashioned way. Watch, and I'll step through the process. Maybe this will help explain why it takes so long.

First step through the curve using the traditional calculation. Since the points along the curve are not equally spaced I default to 1000 increments to give more precision. (You can change the number of steps if you need finer control)

As each step is calculated DGBZ finds the length from the previous position. It keeps a running total that allows it to approximate the length of the curve.

Then, with the total length calculated DGBZ finds out how far through the curve the point has to be.

Next, it re-steps along the curve. Calculating a running total of the curves length as it goes. As soon as its running total oversteps the distance it is trying to find DGBZ stops and declares the latest step the correct position.

And to Calculate a Point on a Path?

The second part of the bezier system Dave G's Multiple Curve System (DGMBZ) simply takes the previous method to its logical (but possibly extreme) conclusion.

A path is just curves that are travelled one after the other. Since DGBZ can calculate the length of a single curve, DGMBZ can calculate the length of a path by totalling the length of the individual curves. With that total in hand it can calculate which curve the point is on, how far through that curve the point is, and then calculate the point itself. (wheww... does that make sense?)

Step through each curve in the path and calculate its length.

Find the distance through the total path.

Find which which specific curve the point is within, and how far the point is within that curve.

Calculate the point along the curve and voila, the correct position.

And this is why paths take longer than curves. If a path is made up of ten curve, then ten curve lengths must be computed, and then a distance through a single curve calculated as well. All in all it can take a while. But if you are calculating only a few paths for each frame (the camera and a main object, for instance) then the overhead isn't too bad.

How Do I Define a Path?

Instead of DGBZC0 through DGBZC3 there are new variables to be set.

DGMBZxxC0 through DGMBZxxC3 are used to store the points of the individual curves. DGMBZCurves stores the number of curves in the current path.

There can be up to 99 curves in a path. I added that many for computer programs that generate POV-Ray code. They could automatically type as complicated a curve as you might wish for.

If even this two curve path seems like a lot of work, don't panic. Remember system is designed so that you only have to enter the values once for any path. During the course of an animation POV-Ray will calculate the correct value for each frame.

#declare DGMBZCurves = 2
#declare DGMBZAmount = clock

#declare DGMBZ01C0 = <0,0,0>
#declare DGMBZ01C1 = <0,1,0>
#declare DGMBZ01C2 = <5,4,2>
#declare DGMBZ01C3 = <5,5,2>

#declare DGMBZ02C0 = <5,5,2>
#declare DGMBZ02C1 = <5,6,2>
#declare DGMBZ02C2 = <25,50,5>
#declare DGMBZ02C3 = <30,55,10>
#include "DGMBZ.INC"

// Position returned in:
DGMBZPosition

[ Go Home ]

Hosted by Geocities, your free personal home page on the web.

This page copyright David Govoni 1997

Any comments, or suggestions?
E-mail me
.

1