POV-Ray : Newsgroups : povray.general : Procedurally generating bicubic patches Server Time
6 Nov 2024 22:15:48 EST (-0500)
  Procedurally generating bicubic patches (Message 1 to 4 of 4)  
From: Greg M  Johnson
Subject: Procedurally generating bicubic patches
Date: 17 Mar 2004 22:22:23
Message: <405915ef$1@news.povray.org>
My next ambition is to make procedurally-generated bicubic patches.  I'm
trying to figure out exactly what the math is behind the control points,
especially for something as simple as a circle-- a cylinder.

I made a circle of four points in Hamapath with radius 0.5.  I then extruded
it one unit. I think I understand all of the math except the control points.
Does anyone understand the math to get a control point that suggests a
circle?  What's the formula in terms of pi and r?   I'm trying to figure out
what the 0.273 means, also a way to generate it to more significant digits.
I'm guessing it's like pi*r*some_constant_I_cannot_fathom.

Example scene below:


camera{
 location < 0.000, 5.000, -20.000 >
 look_at < 0.000, 0.000, 0.000 >
 angle 40.000
}

background{ rgb <0/255,0/255,0/255> }


light_source{<100,100,-100> rgb 1}
light_source{<0,10,-1000> rgb 1}


global_settings{
 adc_bailout 0.0039
 ambient_light rgb <255/255,255/255,255/255>
 assumed_gamma 2.200
 hf_gray_16 0
 irid_wavelength rgb <68/255,46/255,36/255>
 max_intersections 64
 max_trace_level 10
 number_of_waves 10
 radiosity{
  brightness 3.300
  count 100
  distance_maximum 0.000
  error_bound 0.400
  gray_threshold 0.500
  low_error_factor 0.800
  minimum_reuse 0.0150
  nearest_count 6
  recursion_limit 1
 }
}

//patch_obj_00
union{
 bicubic_patch {
  type 1
  flatness 0
  u_steps 3
  v_steps 3
  <-0.500, 0.000, 2.018> <-0.500, 0.273, 2.018> <-0.273, 0.500, 2.018>
<0.000, 0.500, 2.018>
  <-0.500, 0.000, 1.413> <-0.500, 0.273, 1.413> <-0.273, 0.500, 1.413>
<0.000, 0.500, 1.413>
  <-0.500, 0.000, 0.605> <-0.500, 0.273, 0.605> <-0.273, 0.500, 0.605>
<0.000, 0.500, 0.605>
  <-0.500, 0.000, 0.000> <-0.500, 0.273, 0.000> <-0.273, 0.500, 0.000>
<0.000, 0.500, 0.000>
 }
 bicubic_patch {
  type 1
  flatness 0
  u_steps 3
  v_steps 3
  <0.000, 0.500, 2.018> <0.273, 0.500, 2.018> <0.500, 0.273, 2.018> <0.500,
0.000, 2.018>
  <0.000, 0.500, 1.413> <0.273, 0.500, 1.413> <0.500, 0.273, 1.413> <0.500,
0.000, 1.413>
  <0.000, 0.500, 0.605> <0.273, 0.500, 0.605> <0.500, 0.273, 0.605> <0.500,
0.000, 0.605>
  <0.000, 0.500, 0.000> <0.273, 0.500, 0.000> <0.500, 0.273, 0.000> <0.500,
0.000, 0.000>
 }
 bicubic_patch {
  type 1
  flatness 0
  u_steps 3
  v_steps 3
  <0.500, 0.000, 2.018> <0.500, -0.273, 2.018> <0.273, -0.500, 2.018>
<0.000, -0.500, 2.018>
  <0.500, 0.000, 1.413> <0.500, -0.273, 1.413> <0.273, -0.500, 1.413>
<0.000, -0.500, 1.413>
  <0.500, 0.000, 0.605> <0.500, -0.273, 0.605> <0.273, -0.500, 0.605>
<0.000, -0.500, 0.605>
  <0.500, 0.000, 0.000> <0.500, -0.273, 0.000> <0.273, -0.500, 0.000>
<0.000, -0.500, 0.000>
 }
 bicubic_patch {
  type 1
  flatness 0
  u_steps 3
  v_steps 3
  <0.000, -0.500, 2.018> <-0.273, -0.500, 2.018> <-0.500, -0.273, 2.018>
<-0.500, 0.000, 2.018>
  <0.000, -0.500, 1.413> <-0.273, -0.500, 1.413> <-0.500, -0.273, 1.413>
<-0.500, 0.000, 1.413>
  <0.000, -0.500, 0.605> <-0.273, -0.500, 0.605> <-0.500, -0.273, 0.605>
<-0.500, 0.000, 0.605>
  <0.000, -0.500, 0.000> <-0.273, -0.500, 0.000> <-0.500, -0.273, 0.000>
<-0.500, 0.000, 0.000>
 }
 pigment{rgb <235/255, 44/255, 169/255>}
 finish{phong 1}

}


Post a reply to this message

From: Christian Walther
Subject: Re: Procedurally generating bicubic patches
Date: 18 Mar 2004 04:19:06
Message: <pan.2004.03.18.09.19.17.607867@gmx.ch>
Greg M. Johnson wrote:

> I'm trying to figure out exactly what the math is behind the control
> points.

A short introduction to the formulas behind cubic bezier curves is at
<http://moshplant.com/direct-or/bezier/math.html>. You'll probably find
the ones for cubic bezier patches somewhere too, but it'll probably help
understanding the curves first.

> I made a circle of four points in Hamapath with radius 0.5.  I then
> extruded it one unit. I think I understand all of the math except the
> control points. Does anyone understand the math to get a control point
> that suggests a circle?  What's the formula in terms of pi and r?   I'm
> trying to figure out what the 0.273 means, also a way to generate it to
> more significant digits. I'm guessing it's like
> pi*r*some_constant_I_cannot_fathom.

That number comes out of the solution to the problem "How to approximate a
quarter-circle by a cubic bezier curve". You cannot represent a circular
arc exactly by a cubic bezier curve, but you can approximate it
very closely, sufficient for most purposes.

I solved that problem numerically one day. The exact formulation is: find
h such that the cubic bezier curve given by the points <1, 0>, <1, h>, <h,
1>, <0, 1> most closely approximates a quarter circle.

If you want to minimize the integral along the curve of the square of the
difference between the radius (distance to the origin) of the bezier curve
and the real circle radius (1), the solution is h = 0.551967589. In that
case, the radius difference is between -1.682e-4 and 2.059e-4. The curve
is inside of the circle about in the middle third and outside in the first
and last.

If you want the whole curve to lie outside of the circle, you have to take
h = 4/3*(sqrt(2) - 1) = 0.552284750. Then, the radius difference is
between 0 and 2.725e-4.

If you want the whole curve to lie inside the circle, take h = (sqrt(7) -
1)/3 = 0.548583770. In that case, the radius difference is between
-1.963e-3 and 0.

So, your 0.273 is some bad approximation of r*h for your radius r = 0.5.

If you're interested, I can give you the Matlab file I used for the
numeric optimization. I don't remember how I got the exact results
(with sqrts etc.), probably I used my TI-92 calculator there.

Hope that helps

 -Christian


Post a reply to this message

From: Greg M  Johnson
Subject: Re: Procedurally generating bicubic patches
Date: 18 Mar 2004 07:08:43
Message: <4059914b$1@news.povray.org>
"Christian Walther" <cwa### [at] gmxch> wrote in message
news:pan### [at] gmxch...
> If you want the whole curve to lie outside of the circle, you have to take
> h = 4/3*(sqrt(2) - 1) = 0.552284750. Then, the radius difference is
> between 0 and 2.725e-4.
>


Great, thanks.  I'll use these constants for now and study that link in the
case that I should want to try something more ambitious-- perhaps an eight
point circle.  I'm eventually considering making an extrusion in the shape
of an arm or leg, one that moves.


Post a reply to this message

From: Chambers
Subject: Re: Procedurally generating bicubic patches
Date: 18 Mar 2004 15:37:34
Message: <405a088e$1@news.povray.org>
"Greg M. Johnson" <gregj;-)565### [at] aolcom> wrote in message
news:405915ef$1@news.povray.org...
> My next ambition is to make procedurally-generated bicubic patches.  I'm
> trying to figure out exactly what the math is behind the control points,
> especially for something as simple as a circle-- a cylinder.
>
> I made a circle of four points in Hamapath with radius 0.5.  I then
extruded
> it one unit. I think I understand all of the math except the control
points.
> Does anyone understand the math to get a control point that suggests a
> circle?  What's the formula in terms of pi and r?   I'm trying to figure
out
> what the 0.273 means, also a way to generate it to more significant
digits.
> I'm guessing it's like pi*r*some_constant_I_cannot_fathom.

<disclaimer> Well, you can't exactly model a sphere / cylinder, sine waves,
or anything like that with a bezier patch because it's a cubic function
</disclaimer>

That being said, you *can* get awfully close :)

In terms of how they work, it helps to work with a 2d spline first.  Say you
have two points, A and D, and two control points B and C (between A and D).
The spline will start at A, pointed at B.  It will end at D, as if it were
coming from C.  Or, in other words, the slope at point A is the vector from
A to B, and the slope at D is the vector from C to D.  The spline more or
less smoothly "blends" between the two :)

Working in 3D, it's similar.  Say we have 16 control points p(0..3, 0..3).
The normal at p(00) is perpendicular to the plane formed by p(00), p(01) and
p(10).  The other three corners are also found by finding the planes formed
by the two adjacent control points and the corner.  Understanding this, it's
pretty easy to hand craft patches that roughly give the shape you want
(though visual modellers help), and trivial to generate patches that
seamlessly fit together via a script.

-- 
...Chambers
http://www.geocities.com/bdchambers79


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.