| Home < Solutions < Generic Tutorial Rev2.0 |
| The POV-Ray Cyclopedia |
| www.spiritone.com/~english/cyclopedia/ |
This is part two of a discussion of bezier objects. You may want to read the first Bezier tutorial first.
This tutorial requires the following files:
| Part One | |
| A Basic Bezier (Bicubic) Patch | |
We start with a standard bicubic patch object and its control points in image 1. I've declared the points in an array of arrays to make the automation easier later on. These sixteen points define one patch. The only points that the patch will always touch are the four corner points. The rest are influential in the direction of the patch, but won't always touch the patch.
#declare f = array[4][4]
{{<-1.5, 0, 1.5>, <-1.5, 0 , 0.5>, <-1.5,-0.5,-0.5>, <-1.5,-0.5,-1.5>},
{<-0.5, 0.1, 1.5>, <-0.5,-0.5, 0.5>, <-0.5,-0.5,-0.5>, <-0.5, 0.1,-1.5>},
{< 0.5,-0.1, 1.5>, < 0.5,-0.5, 0.5>, < 0.5,-0.5,-0.5>, < 0.5,-0.1,-1.5>},
{< 1.5, 0.5, 1.5>, < 1.5, 0 , 0.5>, < 1.5, 0,-0.5>, < 1.5, 0,-1.5>}}
bicubic_patch {
type 1 flatness 0.001
u_steps 4 v_steps 4
uv_vectors
<0,0> <1,0> <1,1> <0,1>
f[0][0], f[0][1], f[0][2], f[0][3]
f[1][0], f[1][1], f[1][2], f[1][3]
f[2][0], f[2][1], f[2][2], f[2][3]
f[3][0], f[3][1], f[3][2], f[3][3]
pigment { rgbf <1,1,1,0.5>}
finish {specular 1}
no_shadow }
One thing to notice is that the edges behave just like normal bezier curves described in my bezier tutorial. Consider the following code:
#declare Spline = array[4] { f[0][3], f[1][3], f[2][3], f[3][3]}
DrawSpline(Spline)
#declare Spline = array[4] { f[0][0], f[1][0], f[2][0], f[3][0]}
DrawSpline(Spline)
#declare Spline = array[4] { f[3][0], f[3][1], f[3][2], f[3][3]}
DrawSpline(Spline)
#declare Spline = array[4] { f[0][0], f[0][1], f[0][2], f[0][3]}
DrawSpline(Spline)
This gives us image 2. The four curves follow the edges of the patch, forming a wireframe of the patch. This will prove valuable in the next section. When looking at the code, however, keep in mind that the point |
|
| Part Two | |
| Connecting Two Patches | |
Now if we want to join another patch to the one we have, we can declare the following array and draw another patch with these points.
#declare g = array[4][4]
{ {<1.5, 0.5, 1.5>, <1.5, 0, 0.5>, <1.5, 0,-0.5>, <1.5, 0,-1.5>},
{<2.5, 0.1, 1.5>, <2.5,-0.5, 0.5>, <2.5, 0.5,-0.5>, <2.5,-0.1,-1.5>},
{<3.5, 0.1, 1.5>, <3.5, 0.5, 0.5>, <3.5,-0.5,-0.5>, <3.5, 0.1,-1.5>},
{<4.5, 0.5, 1.5>, <4.5, 0, 0.5>, <4.5, 0,-0.5>, <4.5, 0,-1.5>}}
Notice that the first array in
{2*f[3][0]-f[2][0],2*f[3][1]-f[2][1],2*f[3][2]-f[2][2],2*f[3][3]-f[2][3]}
And image 4 shows what the result of this change is. The seam is gone and the connection is smooth. Doing this for several patches is not a pleasant coding experience, so what remains is to automate the procedure. |
|
| Part Three | |
| Automatically Connecting Patches | |
Before we can automate this procedure, we need to explore a few things. Below I have declare an array
#declare p = array[3][3]
{{<-1.5,0, 1.5>,<0,0, 1.5>,<1.5,0, 1.5>},
{<-1.5,0, 0>,<0,0, 0>,<1.5,0, 0>},
{<-1.5,0,-1.5>,<0,0,-1.5>,<1.5,0,-1.5>}}
When we took several points in a line and created a multispline out of them, the macro creates a new array using several more points. We need to do the same thing here, except it covers two dimensions, so these nine points become an array of 49 points. We can feed each row and column into an one-dimensionalarray and create a multispline out of it. This will give us more control points to work with. Image 6 shows our nine points (which I've moved around for interest) and the multispline "wireframe" of the four bicubic patches we need to build. The yellow control points are the ones that we found by calling the Now we need to fill out the remaining four points on all of our patches. Image 7 shows our patches with seveal points highlighted. These are the points that we need to consider when placing points A1, A2, A3, and A4. There are two methods that are used to find these points, completing the parallelogram, and finding the parallel. (Finding the parallel is the method used in finding control points the
Point A1 is the easiest to find. Since A1 is in the top left corner, it doesn't need to be colinear with any other points, so we can complete the parallelogram using the corner point, plus the two closest control points that we found in the previous step (shown here as F and H). A2 must be colinear with B1, so we can use points I and H to find the parallel. Later on when we find B1 we use H and I (in that order) to find the parallel, and A2 and B1 will be colinear. A3 must be colinear with C1, and so we can use points G and F to find the parallel. A4 must be colinear with C2 and B3. Infact, D1,B3,C2, and A4 must form a parallelogram in their own right, with the central point being on the same plane as the other four. This turns out to be easy. The control point between B3 and A4 is colinear with with point between D1 and C2 because they were generated by finding the parallel using three original points of our grid. Similarly, the control point between C2 and A4 is colinear with the point between D1 and B3. So to find A4 (and D1, C2, and B3 for that matter) is to complete the parallelogram. So two methods help us find the remaining four points for each patch. The next thing to program is the decision of which method to use. A1,A2,A3, and A4 are all the "upper left" control point, and there are two methods for finding these points. The macro I use to do this has to decide which patch we're looking at. Consider two questions: Is the patch along the top? Is the patch along the left side? For the point A1 the answers are Yes and Yes. For the point A2 the answers are No and Yes. For A3 we have Yes and No, and for A4 we have No and No. These answers tell us which method to use. Assume that all the other missing control points are labeled in a similar manner. The questions will change. For the B points, the questions are Is the patch along the top? Is the Patch along the right side?. The questions for C are: Is the patch along the bottom side? Is the patch along the left side? The questions for D are similar (bottom right). By determing which questions to ask, we can code the points and complete all of our smooth patches. Image 8 shows these four patches with an image map applied via uv-mapping. To learn how I to pull this off, please see my "UV Mapping on Bicubic Patches" tutorial. |
|
Send feedback, or head back to the Cyclopedia.
This page was last updated on 31 Aug 2001 15:19 .