| Home < Solutions < Generic Tutorial Rev2.0 |
| The POV-Ray Cyclopedia |
| www.spiritone.com/~english/cyclopedia/ |
Bezier Patches are incredibly handy, but also incredible complicated to use. Each one needs 16 control points, and joining two bezier patches smoothy is a bit of a headache. The POV-Ray 3.5 documentation gives a good explination, but hardly helps towards automating the process. Hence I have written this document to explain bezier patches in POV-Ray, but we will step back to working with bezier curves, since they are much simpler to work with.
This tutorial requires the following file:
| Part One | |
| Bezier Curves | |
The first include file we will work with is Using bezier.inc, we can draw a simple curve with the following code:
#include "bezier.inc"
#declare A = <-1,-0.8,0>;
#declare B = <-0.5,0.5,0>;
#declare C = < 0.5,0.5,0>;
#declare D = < 1,-0.7,0>;
#declare Spline = array[4] { A,B,C,D }
#declare BezRad = 0.01;
#declare FullCurve = true;
DrawSpline(Spline)
There is a nice interactive java applet at Bill Casselman's bezier page. Using a compass and ruler we can construct a bezier curve. Simply find the midpoints of the lines AB, BC, and CD. These are points E,F, and G on image 2. Then find the midpoints of lines EF and FG (points H and I), and connect these points and find the midpoint of this line (point J). Point J lies on the curve, and notice that there are two curves we can calculate: A to F using E and H as the control points, and F to D using I and G as the conrol points. Finding 10 points not on the curve to finding one point on the curve is wasteful. Fortunately there is a parametric equation we can use to find any point on the curve. If we parametrize the curve so that P(0)=A and P(1) = D, we can declare use the following equation:
So lets take a look at connecting two bezier curves together |
|
| Part Two | |
| Connecting Bezier Curves | |
|
Image 3 shows another bezier curve and it's control points and a target point G. To make another bezier curver we need to declare two more control points, E and F, to define a smooth curve. The important thing to remember is that point E needs to be on the same lind as C and D. The easiest way to find point E is to declare E = 2D-C or E = D -(C-D). Image 4 shows how this works. Of course I just put in an arbitraty value for F. Image 5 shows several curves with various values for F. Notice that all of them are smoothly connected at point D. Now what if we have an array of points that we want to curve to pass through? |
|
| Part Three | |
| Automatically Connecting Splines | |
|
This part of the lesson uses another include file, Consider the points A,B, and C in image 6. They are connected using multispline.inc with the following code:
#include "multispline.inc"
#declare A = <-1,-0.8,0>;
#declare B = <-0.5,0.7,0>;
#declare C = <0.5,-0.6,0>;
#declare D = <1,0.5,0>;
#declare Spline = array[4] { A,B,C,D }
#declare longSpline = MakeLongSpline(Spline,0,0)
DrawLongSpline(longSpline)
The MakeLongSpline macro takes the array of four position vectors and creates an array of 10 position vectors, four are from the original points, four of which are generated automatically, and two that have user control. In image 7 we see that the line from A2 to B1 are on the same line, and this line is calculated to be parallel with AC. The line from B2 to C1 is also parallel to BD. The only points that MakeLongSpline allows for user input are the points A1 and C2 (or the last control point). The two parameters after the array name are the initial offset and the terminal offset. We will leave them here for now, but there is more information in the multipline.inc documentation. You can create an array of any number of points (3 or more) and MakeLongSpline will connect them with a smooth curve. This page was a breif introduction to multisplines, but lets move on to automatically creating arrays of bezier patches --> |
|
Send feedback, or head back to the Cyclopedia.
This page was last updated on 31 Aug 2001 15:19 .