Difference between revisions of "Reference:Lathe"

From POV-Wiki
Jump to navigation Jump to search
m (1 revision: Reference Migration Initial Load)
m (clean up and user contributed additions)
Line 3: Line 3:
 
{{#indexentry:lathe, keyword}}
 
{{#indexentry:lathe, keyword}}
 
{{#indexentry:keyword, lathe}}  
 
{{#indexentry:keyword, lathe}}  
<p>The <code>lathe</code> is an object generated from rotating a
+
<p>The <code>lathe</code> is an object generated from rotating a two-dimensional curve about an axis. This curve is defined by a set of points which are connected by linear, quadratic, cubic or bezier spline curves. The syntax is:</p>
two-dimensional curve about an axis. This curve is defined by a set of points
 
which are connected by linear, quadratic, cubic or bezier spline curves. The
 
syntax is:</p>
 
 
<pre>
 
<pre>
 
LATHE:
 
LATHE:
Line 29: Line 26:
 
{{#indexentry:linear_spline, lathe}}
 
{{#indexentry:linear_spline, lathe}}
 
{{#indexentry:keyword, linear_spline}}
 
{{#indexentry:keyword, linear_spline}}
<p>The first item is a keyword specifying the type of spline. The default if
+
<p>The first item is a keyword specifying the type of spline. The default if none is specified is <code>linear_spline</code>. The required integer value <em><code>Number_Of_Points</code></em> specifies how many two-dimensional points are used to define the curve. The points follow and are specified by 2-D vectors. The curve is not automatically closed, i.e. the first and last
none is specified is <code>linear_spline</code>. The required integer value
+
points are not automatically connected. You will have to do this yourself if you want a closed curve. The curve thus defined is rotated about the y-axis to form the lathe object, centered at the origin.</p>
<em><code>Number_Of_Points</code></em> specifies how many two-dimensional
+
<p>The following example creates a simple lathe object that looks like a thick cylinder, i.e. a cylinder with a thick wall:</p>
points are used to define the curve. The points follow and are specified by
 
2-D vectors. The curve is not automatically closed, i.e. the first and last
 
points are not automatically connected. You will have to do this yourself
 
if you want a closed curve. The curve thus defined is rotated about the
 
y-axis to form the lathe object, centered at the origin.</p>
 
<p>
 
The following examples creates a simple lathe object that looks like a thick
 
cylinder, i.e. a cylinder with a thick wall:</p>
 
 
<pre>
 
<pre>
 
lathe {
 
lathe {
Line 49: Line 38:
 
</pre>
 
</pre>
  
<p>The cylinder has an inner radius of 2 and an outer radius of 3, giving a
+
<p>The cylinder has an inner radius of 2 and an outer radius of 3, giving a wall width of 1. It's height is 5 and it's located at the origin pointing up, i.e. the rotation axis is the y-axis.</p>
wall width of 1. It's height is 5 and it's located at the origin
 
pointing up, i.e. the rotation axis is the y-axis.</p>
 
 
<p class="Note"><strong>Note:</strong> The first and last point are equal to get a closed curve.</p>
 
<p class="Note"><strong>Note:</strong> The first and last point are equal to get a closed curve.</p>
<p>
+
<p>The splines that are used by the lathe and prism objects are a little bit difficult to understand. The basic concept of splines is to draw a curve through a given set of points in a determined way. The default <code>linear_spline</code> is the simplest spline because it's nothing more than connecting consecutive points with a line. This means the curve that is drawn between two points only depends on those two points. No additional information is taken into account. The other splines are different in that they do take other points into account when connecting two points. This creates a smooth curve and, in the case of the cubic spline, produces smoother transitions at each point.</p>
The splines that are used by the lathe and prism objects are a little bit
 
difficult to understand. The basic concept of splines is to draw a curve
 
through a given set of points in a determined way. The default <code>
 
linear_spline</code> is the simplest spline because it's nothing more
 
than connecting consecutive points with a line. This means the curve
 
that is drawn between two points only depends on those two points. No
 
additional information is taken into account. The other splines are different
 
in that they do take other points into account when connecting two points.
 
This creates a smooth curve and, in the case of the cubic spline, produces
 
smoother transitions at each point.</p>
 
  
 
{{#indexentry:quadratic_spline, lathe}}
 
{{#indexentry:quadratic_spline, lathe}}
 
{{#indexentry:keyword, quadratic_spline}}
 
{{#indexentry:keyword, quadratic_spline}}
<p>The <code>quadratic_spline</code> keyword creates splines that are made of
+
<p>The <code>quadratic_spline</code> keyword creates splines that are made of quadratic curves. Each of them connects two consecutive points. Since those two points (call them second and third point) are not sufficient to describe a quadratic curve, the predecessor of the second point is taken into account when the curve is drawn. Mathematically, the relationship (their relative locations on the 2-D plane) between the first and second point determines the slope of the curve at the second point. The slope of the curve at the third point is out of control. Thus quadratic splines look much smoother than linear splines but
quadratic curves. Each of them connects two consecutive points. Since those
+
the transitions at each point are generally not smooth because the slopes on both sides of the point are different.</p>
two points (call them second and third point) are not sufficient to describe
 
a quadratic curve, the predecessor of the second point is taken into account
 
when the curve is drawn. Mathematically, the relationship (their relative locations on
 
the 2-D plane) between the first and second point determines the slope of the
 
curve at the second point. The slope of the curve at the third point is out
 
of control. Thus quadratic splines look much smoother than linear splines but
 
the transitions at each point are generally not smooth because the slopes on
 
both sides of the point are different.</p>
 
  
 
{{#indexentry:cubic_spline, lathe}}
 
{{#indexentry:cubic_spline, lathe}}
 
{{#indexentry:keyword, cubic_spline}}
 
{{#indexentry:keyword, cubic_spline}}
<p>The <code>cubic_spline</code> keyword creates splines which overcome the
+
<p>The <code>cubic_spline</code> keyword creates splines which overcome the transition problem of quadratic splines because they also take a fourth point into account when drawing the curve between the second and third point. The slope at the fourth point is under control now and allows a smooth transition at each point. Thus cubic splines produce the most flexible and
transition problem of quadratic splines because they also take a fourth
 
point into account when drawing the curve between the second and third point.
 
The slope at the fourth point is under control now and allows a smooth
 
transition at each point. Thus cubic splines produce the most flexible and
 
 
smooth curves.</p>
 
smooth curves.</p>
  
 
{{#indexentry:bezier_spline, lathe}}
 
{{#indexentry:bezier_spline, lathe}}
 
{{#indexentry:keyword, bezier_spline}}
 
{{#indexentry:keyword, bezier_spline}}
<p>The <code>bezier_spline</code> is an alternate kind of cubic spline. Points
+
<p>The <code>bezier_spline</code> is an alternate kind of cubic spline. Points 1 and 4 specify the end points of a segment and points 2 and 3 are control points which specify the slope at the endpoints. Points 2 and 3 do not actually lie on the spline. They adjust the slope of the spline. If you draw an imaginary line between point 1 and 2, it represents the slope at point 1.
1 and 4 specify the end points of a segment and points 2 and 3 are control
+
It is a line tangent to the curve at point 1. The greater the distance between 1 and 2, the flatter the curve. With a short tangent the spline can bend more. The same holds true for control point 3 and endpoint 4. If you want the spline to be smooth between segments, points 3 and 4 on one segment and points 1 and 2 on the next segment must form a straight line and point 4 of one segment must be the same as point 1 on the next segment.</p>
points which specify the slope at the endpoints. Points 2 and 3 do not
+
<p>You should note that the number of spline segments, i. e. curves between two points, depends on the spline type used. For linear splines you get n-1 segments connecting the points P[i], i=1,...,n. A quadratic spline gives you n-2 segments because the last point is only used for determining the slope, as explained above (thus you will need at least three points to define a
actually lie on the spline. They adjust the slope of the spline. If you draw
+
quadratic spline). The same holds for cubic splines where you get n-3 segments with the first and last point used only for slope calculations (thus needing at least four points). The bezier spline requires 4 points per segment, creating n/4 segments.</p>
an imaginary line between point 1 and 2, it represents the slope at point 1.
+
<p>If you want to get a closed quadratic and cubic spline with smooth transitions at the end points you have to make sure that in the cubic case P[n-1] = P[2] (to get a closed curve), P[n] = P[3] and P[n-2] = P[1] (to smooth the transition). In the quadratic case P[n-1] = P[1] (to close the curve) and P[n] = P[2].</p>
It is a line tangent to the curve at point 1. The greater the distance
+
 
between 1 and 2, the flatter the curve. With a short tangent the spline can
+
<p>The surface normal determination for lathes depends upon the order in which the splines points are specified. The following code, where the bezier spline point order is <em>counter-clockwise</em> in the xy plane, will render with the color Red on the outside and the color Blue on the inside.</p>
bend more. The same holds true for control point 3 and endpoint 4. If you
+
<pre>
want the spline to be smooth between segments, points 3 and 4 on one segment
+
#declare Lathe_CounterClockwise = lathe {
and points 1 and 2 on the next segment must form a straight line and point 4
+
    bezier_spline
of one segment must be the same as point 1 on the next segment.</p>
+
    16,
<p>
+
    <0.45,0>,<0.45,0.0828427>,<0.382843,0.15>,<0.3,0.15>
You should note that the number of spline segments, i. e. curves between two
+
    <0.3,0.15>,<0.217157,0.15>,<0.15,0.0828427>,<0.15,0>
points, depends on the spline type used. For linear splines you get n-1
+
    <0.15,0>,<0.15,-0.0828427>,<0.217157,-0.15>,<0.3,-0.15>
segments connecting the points P[i], i=1,...,n. A quadratic spline gives you
+
    <0.3,-0.15>,<0.382843,-0.15>,<0.45,-0.0828427>,<0.45,0>
n-2 segments because the last point is only used for determining the slope, as
+
    sturm
explained above (thus you will need at least three points to define a
+
    texture          { pigment { Red } }
quadratic spline). The same holds for cubic splines where you get n-3
+
    interior_texture { pigment { Blue } }
segments with the first and last point used only for slope calculations (thus
+
}
needing at least four points). The bezier spline requires 4 points per
+
</pre>
segment, creating n/4 segments.</p>
+
<p>While the following example, where the point order for the bezier spine is <em>clockwise</em> in the xy plane, will render inside-out, with the color Blue on the outside and the color Red on the inside.</p>
<p>
+
<pre>
If you want to get a closed quadratic and cubic spline with smooth
+
#declare Lathe_Clockwise = lathe {
transitions at the end points you have to make sure that in the cubic case
+
    bezier_spline
P[n-1] = P[2] (to get a closed curve), P[n] = P[3] and P[n-2] = P[1] (to
+
    16,
smooth the transition). In the quadratic case P[n-1] = P[1] (to close the
+
    <0.45,0>,<0.45,-0.0828427>,<0.382843,-0.15>,<0.3,-0.15>
curve) and P[n] = P[2].</p>
+
    <0.3,-0.15>,<0.217157,-0.15>,<0.15,-0.0828427>,<0.15,0>
 +
    <0.15,0>,<0.15,0.0828427>,<0.217157,0.15>,<0.3,0.15>
 +
    <0.3,0.15>,<0.382843,0.15>,<0.45,0.0828427>,<0.45,0>
 +
    sturm
 +
    texture          { pigment { Red } }
 +
    interior_texture { pigment { Blue } }
 +
}
 +
</pre>
 +
<p>The actual normal determination is a bit more complicated than just <em>clockwise</em> vs <em>counter-clockwise</em> orientation for complex splines. If the surface normal is important to the visual result, it is best to check how the lathe is being rendered by testing with substantially different inside and outside textures.</p>
 +
<p class="Note"><strong>Note:</strong> With the bezier spline, unlike all the other spline types used with the lathe, it is possible to create independent closed curves within a single lathe definition.</p>
  
 
{{#indexentry:sturm, lathe}}
 
{{#indexentry:sturm, lathe}}
 
{{#indexentry:keyword, sturm}}
 
{{#indexentry:keyword, sturm}}
<p>The <code>sturm</code> keyword can be used to specify that the slower, but
+
<p>The <code>sturm</code> keyword can be used to specify that the slower, but more accurate, Sturmian root solver should be used. Use it, if the shape does not render properly. Since a quadratic polynomial has to be solved for the linear spline lathe, the Sturmian root solver is not needed.</p>
more accurate, Sturmian root solver should be used. Use it, if the shape does not render properly. Since a quadratic polynomial has to be solved for the linear spline lathe, the Sturmian root solver is not needed.</p>
 

Revision as of 22:38, 25 May 2016

The lathe is an object generated from rotating a two-dimensional curve about an axis. This curve is defined by a set of points which are connected by linear, quadratic, cubic or bezier spline curves. The syntax is:

LATHE:
  lathe {
    [SPLINE_TYPE] Number_Of_Points, <Point_1>
    <Point_2>... <Point_n>
    [LATHE_MODIFIER...]
    }
SPLINE_TYPE:
  linear_spline | quadratic_spline | cubic_spline | bezier_spline
LATHE_MODIFIER:
  sturm | OBJECT_MODIFIER

Lathe default values:

SPLINE_TYPE   : linear_spline
sturm         : off

The first item is a keyword specifying the type of spline. The default if none is specified is linear_spline. The required integer value Number_Of_Points specifies how many two-dimensional points are used to define the curve. The points follow and are specified by 2-D vectors. The curve is not automatically closed, i.e. the first and last points are not automatically connected. You will have to do this yourself if you want a closed curve. The curve thus defined is rotated about the y-axis to form the lathe object, centered at the origin.

The following example creates a simple lathe object that looks like a thick cylinder, i.e. a cylinder with a thick wall:

lathe {
  linear_spline
  5,
  <2, 0>, <3, 0>, <3, 5>, <2, 5>, <2, 0>
  pigment {Red}
  }

The cylinder has an inner radius of 2 and an outer radius of 3, giving a wall width of 1. It's height is 5 and it's located at the origin pointing up, i.e. the rotation axis is the y-axis.

Note: The first and last point are equal to get a closed curve.

The splines that are used by the lathe and prism objects are a little bit difficult to understand. The basic concept of splines is to draw a curve through a given set of points in a determined way. The default linear_spline is the simplest spline because it's nothing more than connecting consecutive points with a line. This means the curve that is drawn between two points only depends on those two points. No additional information is taken into account. The other splines are different in that they do take other points into account when connecting two points. This creates a smooth curve and, in the case of the cubic spline, produces smoother transitions at each point.

The quadratic_spline keyword creates splines that are made of quadratic curves. Each of them connects two consecutive points. Since those two points (call them second and third point) are not sufficient to describe a quadratic curve, the predecessor of the second point is taken into account when the curve is drawn. Mathematically, the relationship (their relative locations on the 2-D plane) between the first and second point determines the slope of the curve at the second point. The slope of the curve at the third point is out of control. Thus quadratic splines look much smoother than linear splines but the transitions at each point are generally not smooth because the slopes on both sides of the point are different.

The cubic_spline keyword creates splines which overcome the transition problem of quadratic splines because they also take a fourth point into account when drawing the curve between the second and third point. The slope at the fourth point is under control now and allows a smooth transition at each point. Thus cubic splines produce the most flexible and smooth curves.

The bezier_spline is an alternate kind of cubic spline. Points 1 and 4 specify the end points of a segment and points 2 and 3 are control points which specify the slope at the endpoints. Points 2 and 3 do not actually lie on the spline. They adjust the slope of the spline. If you draw an imaginary line between point 1 and 2, it represents the slope at point 1. It is a line tangent to the curve at point 1. The greater the distance between 1 and 2, the flatter the curve. With a short tangent the spline can bend more. The same holds true for control point 3 and endpoint 4. If you want the spline to be smooth between segments, points 3 and 4 on one segment and points 1 and 2 on the next segment must form a straight line and point 4 of one segment must be the same as point 1 on the next segment.

You should note that the number of spline segments, i. e. curves between two points, depends on the spline type used. For linear splines you get n-1 segments connecting the points P[i], i=1,...,n. A quadratic spline gives you n-2 segments because the last point is only used for determining the slope, as explained above (thus you will need at least three points to define a quadratic spline). The same holds for cubic splines where you get n-3 segments with the first and last point used only for slope calculations (thus needing at least four points). The bezier spline requires 4 points per segment, creating n/4 segments.

If you want to get a closed quadratic and cubic spline with smooth transitions at the end points you have to make sure that in the cubic case P[n-1] = P[2] (to get a closed curve), P[n] = P[3] and P[n-2] = P[1] (to smooth the transition). In the quadratic case P[n-1] = P[1] (to close the curve) and P[n] = P[2].

The surface normal determination for lathes depends upon the order in which the splines points are specified. The following code, where the bezier spline point order is counter-clockwise in the xy plane, will render with the color Red on the outside and the color Blue on the inside.

#declare Lathe_CounterClockwise = lathe {
    bezier_spline
    16,
    <0.45,0>,<0.45,0.0828427>,<0.382843,0.15>,<0.3,0.15>
    <0.3,0.15>,<0.217157,0.15>,<0.15,0.0828427>,<0.15,0>
    <0.15,0>,<0.15,-0.0828427>,<0.217157,-0.15>,<0.3,-0.15>
    <0.3,-0.15>,<0.382843,-0.15>,<0.45,-0.0828427>,<0.45,0>
    sturm
    texture          { pigment { Red } }
    interior_texture { pigment { Blue } }
}

While the following example, where the point order for the bezier spine is clockwise in the xy plane, will render inside-out, with the color Blue on the outside and the color Red on the inside.

#declare Lathe_Clockwise = lathe {
    bezier_spline
    16,
    <0.45,0>,<0.45,-0.0828427>,<0.382843,-0.15>,<0.3,-0.15>
    <0.3,-0.15>,<0.217157,-0.15>,<0.15,-0.0828427>,<0.15,0>
    <0.15,0>,<0.15,0.0828427>,<0.217157,0.15>,<0.3,0.15>
    <0.3,0.15>,<0.382843,0.15>,<0.45,0.0828427>,<0.45,0>
    sturm
    texture          { pigment { Red } }
    interior_texture { pigment { Blue } }
}

The actual normal determination is a bit more complicated than just clockwise vs counter-clockwise orientation for complex splines. If the surface normal is important to the visual result, it is best to check how the lathe is being rendered by testing with substantially different inside and outside textures.

Note: With the bezier spline, unlike all the other spline types used with the lathe, it is possible to create independent closed curves within a single lathe definition.

The sturm keyword can be used to specify that the slower, but more accurate, Sturmian root solver should be used. Use it, if the shape does not render properly. Since a quadratic polynomial has to be solved for the linear spline lathe, the Sturmian root solver is not needed.