Difference between revisions of "User:Le Forgeron/nurbs"

From POV-Wiki
Jump to navigation Jump to search
 
(3 intermediate revisions by the same user not shown)
Line 1: Line 1:
{{User:Le_Forgeron/HgPovray38/soon}}
+
{{User:Le_Forgeron/HgPovray38/available}}
  
  
 
== Nurbs ==
 
== Nurbs ==
  
'''nurbs''' is like '''spline''' : an invisible object
+
<code>nurbs</code> is like <code>spline</code> : an invisible object
  
 
NURBS means Non Uniform Rational B-Spline.
 
NURBS means Non Uniform Rational B-Spline.
Line 26: Line 26:
 
</pre>
 
</pre>
  
* The <code>order</code> must be at least 2 and at most `size` for each U & V coordinates.
+
* The '''order''' must be at least 2 and at most `size` for each U & V coordinates.
* Along a sequence of knots, the values must not be decreasing.
+
* Along a sequence of knots, the values must not be decreasing: the next value can be the same or bigger.
* '''nurbs''' is one of the UVMeshable objects
+
* <code>nurbs</code> is one of the [[User:Le_Forgeron/UVMeshable|UVMeshable]] objects
  
 
=== Drawing a nurbs ===
 
=== Drawing a nurbs ===
Line 105: Line 105:
  
 
[[Image:LeForgeronNurbs.png| Nurbs]]
 
[[Image:LeForgeronNurbs.png| Nurbs]]
 +
 +
=== closed nurbs ===
 +
 +
Closed nurbs are achieved by having some special arrangement for the control points and knot sequence. For example, the knot sequence [ 0., 0., 0., 0., 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0] with 7 control points (P1, P2,...to P7) will result in an open cubic B-spline curve (when the order is 3). If we change the knot sequence into [ -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75] and make P5=P1, P6=P2 and P7=P3, then the curve will become a closed cubic B-spline curve with C2 continuity at the joint.
 +
 +
[[Image:LeForgeronTorusNurbs.png| Nurbs illustration]]
 +
 +
<source lang="pov">
 +
#version 3.7;
 +
#global_settings{ max_trace_level 10 assumed_gamma 1.0 }
 +
#include "finish.inc"
 +
#declare Major=6;// Major radius of torus
 +
#declare Minor=5;// Minor radius of torus
 +
#declare MAX=5;// max order of nurbs to draw
 +
#declare SPACE=(Major+Minor)*1.404;// Room around each object (radius)
 +
#declare PTI=10;// number of minor circles along the major radius
 +
#declare PTJ=4;// number of points on each minor circle
 +
#declare RESOLUTION=64;// resolution of the mesh
 +
 +
 +
camera {  orthographic
 +
  location 130*y+SPACE*(MAX+1)*(x-z)-z*SPACE
 +
  direction -y
 +
  up (1+(MAX-1)*SPACE)*z*2
 +
  right (1+(MAX-1)*SPACE)*2*x*image_width/image_height
 +
}
 +
 +
#declare T = texture { pigment { uv_mapping checker
 +
    pigment{ color srgb <1,1,0> transmit 0.0 filter 0 }
 +
    pigment{ color srgb <0,1,1> transmit 0.0 filter 0 }
 +
    scale <1/4,1/4,1>
 +
} };
 +
 +
light_source { 10*y-10*x, 0.8 scale 10}
 +
light_source { 10*y-10*z, 2/3 scale 10}
 +
light_source { 10*y, 1/3 scale 10}
 +
light_source { -10*z, 1/3 scale 10}
 +
 +
#macro P(I,J)
 +
#local V=(mod(I,2)*Minor+Major)*x+(Minor)*<cos(pi*2*J/PTJ),sin(pi*2*J/PTJ),0>;
 +
#local W=vrotate(V, 360*I/(PTI)*y);
 +
W
 +
#end
 +
 +
#macro NURBS(OrderU, OrderV)
 +
  nurbs{
 +
    OrderU, OrderV,
 +
    #declare NBI=PTI+OrderU-1;
 +
    #declare NBJ=PTJ+OrderV-1;
 +
    NBI, NBJ,
 +
    #for(I,1,NBI+OrderU)
 +
    I,
 +
  #end
 +
  #for(J,1,NBJ+OrderV)
 +
  J,
 +
#end
 +
#for(J,1,NBJ)
 +
#for(I,1,NBI)
 +
#declare W= P(I,J);
 +
<W.x,W.y,W.z,1>
 +
#end
 +
#end
 +
}
 +
#end
 +
 +
 +
#include "NurbsMesh.inc"
 +
#for(X,2,MAX)
 +
#for(Y,2,MAX)
 +
#declare Nurbs=NURBS(X,Y);
 +
mesh {
 +
  UVMeshable( Nurbs, RESOLUTION, RESOLUTION )
 +
  texture { T } translate SPACE*2*(X*x-Y*z)
 +
}
 +
#end
 +
#end
 +
 +
#declare UN= union{
 +
  #for(J,1,NBJ)
 +
  #for(I,1,NBI)
 +
  #declare W=P(I,J);
 +
  sphere {W, 0.2 texture { pigment { color srgb <1,0,0>}}}
 +
  #declare OLD=W;
 +
  #declare W=P(I,J+1);
 +
  cylinder{OLD,W,0.1 texture { pigment { color srgb <0,1,0>}}}
 +
  #declare W=P(I+1,J);
 +
  cylinder{OLD,W,0.1 texture { pigment { color srgb <0,0,1>}}}
 +
#end
 +
#end
 +
}
 +
 +
object { UN translate SPACE*2*(x-2*z) }
 +
object { UN rotate 90*x translate SPACE*2*(x-4*z) }
 +
plane{ y,-Minor*2 texture { pigment { color srgb 0.5 } } }
 +
 +
</source>

Latest revision as of 08:31, 2 September 2018


Nurbs

nurbs is like spline : an invisible object

NURBS means Non Uniform Rational B-Spline.

syntax is

nurbs {
  Uorder, Vorder, 
  Usize, Vsize 
  UKNOTS
  VKNOTS
  ULINE (repeated Vsize time)
  [OBJECTS_MODIFIERS...] 
 }

ULINE := WEIGHTED_POINT (repeated Usize time)
WEIGHTED_POINT := < X, Y, Z, W >
UKNOTS := KNOT, (repeated Uorder+Usize time)
VKNOTS := KNOT, (repeated Vorder+Vsize time)
KNOT := float value
  • The order must be at least 2 and at most `size` for each U & V coordinates.
  • Along a sequence of knots, the values must not be decreasing: the next value can be the same or bigger.
  • nurbs is one of the UVMeshable objects

Drawing a nurbs

#version 3.7;
global_settings{ assumed_gamma 1.0 }

#declare UVMeshableObject = nurbs { 3,3,7,7
// u knots
0, 0, 0, 1/5, 2/5, 3/5, 4/5, 1, 1, 1
// v knots
0, 0, 0, 1/5, 2/5, 3/5, 4/5, 1, 1, 1
// first line of (x,y,z,w)
 <-4.1894,-5.4790,0.0000,1.0000> <-4.1894,-4.3181,2.0249,1.0000>
<-4.1894,-2.8825,0.0000,1.0000> <-4.1894,-1.5000,0.0000,1.0000>
<-4.1894,-0.5000,0.0000,1.0000> <-4.1894,0.5000,0.0000,1.0000>
<-4.1894,1.5000,0.0000,1.0000>

// second line of (x,y,z,w)
<-2.6808,-4.8585,0.6794,1.0000>
 <-2.6808,-4.3181,2.0249,1.0000> <-2.6808,-2.8825,0.0000,1.0000>
<-2.6808,-1.5000,3.2519,1.0000> <-2.6808,-0.5000,0.0000,1.0000>
<-2.6808,0.5000,0.0000,1.0000> <-2.6808,1.5000,3.2103,1.0000>

// third line of (x,y,z,w)
<-1.5000,-5.4790,0.0000,1.0000>
 <-1.5000,-4.3181,2.0249,1.0000> <-1.5000,-2.8825,0.0000,1.0000>
<-1.5000,-1.5000,0.0000,1.0000> <-1.5000,-0.5000,1.2319,1.0000>
<-1.5000,0.5000,0.0000,1.0000> <-1.5000,1.5000,0.0000,1.0000>

// fourth line of (x,y,z,w)
<-0.5000,-5.4790,0.0000,1.0000>
 <-0.5000,-4.3181,0.0000,1.0000> <-0.5000,-2.8825,1.7624,1.0000>
<-0.5000,-1.5000,0.0000,1.0000> <-0.5000,-0.5000,1.0000,1.0000>
<-0.5000,0.5000,1.0000,1.0000> <-0.5000,1.5000,0.0000,1.0000>

// fifth line of (x,y,z,w)
<0.5000,-5.4790,0.0000,1.0000>
 <0.5000,-4.3181,0.0000,1.0000> <0.5000,-2.8825,0.0000,1.0000>
<0.5000,-1.5000,1.1552,1.0000> <0.5000,-0.5000,1.0000,1.0000>
<0.5000,0.5000,1.0000,1.0000> <0.5000,1.5000,0.0000,1.0000>

// sixth line of (x,y,z,w)
<1.5000,-5.4790,1.9780,1.0000>
 <1.5000,-4.3181,0.0000,1.0000> <1.5000,-2.8825,1.7335,1.0000>
<1.5000,-1.5000,0.0000,1.0000> <1.5000,-0.5000,0.0000,1.0000>
<1.5000,0.5000,0.0000,1.0000> <1.5000,1.5000,1.5217,1.0000>

// seventh line of (x,y,z,w)
<2.9668,-5.4790,-0.2469,1.0000>
 <2.9668,-4.3181,0.0000,1.0000> <2.9668,-2.8825,0.0000,1.0000>
<2.9668,-1.5000,0.0000,1.0000> <2.9668,-0.5000,-2.9599,1.0000>
<2.9668,0.5000,0.0000,1.0000> <2.9668,1.5000,0.0000,1.0000>
};

#declare Texture = texture { checker texture { pigment { color blue 1 } } texture { pigment { color rgb <1,1,0> } } }

#include "NurbsMesh.inc"
#declare UResolution = 92;
#declare VResolution = 92;
mesh {
     UVMeshable( UVMeshableObject, UResolution, VResolution )
     texture { uv_mapping Texture scale <1/24, 1/24, 1> }
     }

light_source {+40*z+90*x, 1 }
camera { location uv_vertex( UVMeshableObject, 0.5, 0.5 ) +<0,0,40>
direction z
up y
right image_width/image_height*x
look_at uv_vertex( UVMeshableObject, 0.5, 0.5 )
angle 16
}

Nurbs

closed nurbs

Closed nurbs are achieved by having some special arrangement for the control points and knot sequence. For example, the knot sequence [ 0., 0., 0., 0., 0.25, 0.5, 0.75, 1.0, 1.0, 1.0, 1.0] with 7 control points (P1, P2,...to P7) will result in an open cubic B-spline curve (when the order is 3). If we change the knot sequence into [ -0.75, -0.5, -0.25, 0., 0.25, 0.5, 0.75, 1.0, 1.25, 1.5, 1.75] and make P5=P1, P6=P2 and P7=P3, then the curve will become a closed cubic B-spline curve with C2 continuity at the joint.

Nurbs illustration

#version 3.7;
#global_settings{ max_trace_level 10 assumed_gamma 1.0 }
#include "finish.inc"
#declare Major=6;// Major radius of torus
#declare Minor=5;// Minor radius of torus
#declare MAX=5;// max order of nurbs to draw
#declare SPACE=(Major+Minor)*1.404;// Room around each object (radius)
#declare PTI=10;// number of minor circles along the major radius
#declare PTJ=4;// number of points on each minor circle
#declare RESOLUTION=64;// resolution of the mesh


camera {  orthographic
  location 130*y+SPACE*(MAX+1)*(x-z)-z*SPACE
  direction -y
  up (1+(MAX-1)*SPACE)*z*2
  right (1+(MAX-1)*SPACE)*2*x*image_width/image_height
}

#declare T = texture { pigment { uv_mapping checker 
    pigment{ color srgb <1,1,0> transmit 0.0 filter 0 }
    pigment{ color srgb <0,1,1> transmit 0.0 filter 0 }
    scale <1/4,1/4,1>
} };

light_source { 10*y-10*x, 0.8 scale 10}
light_source { 10*y-10*z, 2/3 scale 10}
light_source { 10*y, 1/3 scale 10}
light_source { -10*z, 1/3 scale 10}

#macro P(I,J)
#local V=(mod(I,2)*Minor+Major)*x+(Minor)*<cos(pi*2*J/PTJ),sin(pi*2*J/PTJ),0>;
#local W=vrotate(V, 360*I/(PTI)*y);
W
#end

#macro NURBS(OrderU, OrderV)
  nurbs{
    OrderU, OrderV,
    #declare NBI=PTI+OrderU-1;
    #declare NBJ=PTJ+OrderV-1;
    NBI, NBJ,
    #for(I,1,NBI+OrderU)
    I,
  #end
  #for(J,1,NBJ+OrderV)
  J,
#end
#for(J,1,NBJ)
#for(I,1,NBI)
#declare W= P(I,J);
<W.x,W.y,W.z,1>
#end
#end
}
#end


#include "NurbsMesh.inc"
#for(X,2,MAX)
#for(Y,2,MAX)
#declare Nurbs=NURBS(X,Y);
mesh { 
  UVMeshable( Nurbs, RESOLUTION, RESOLUTION ) 
  texture { T } translate SPACE*2*(X*x-Y*z) 
}
#end
#end

#declare UN= union{
  #for(J,1,NBJ)
  #for(I,1,NBI)
  #declare W=P(I,J);
  sphere {W, 0.2 texture { pigment { color srgb <1,0,0>}}}
  #declare OLD=W;
  #declare W=P(I,J+1);
  cylinder{OLD,W,0.1 texture { pigment { color srgb <0,1,0>}}}
  #declare W=P(I+1,J);
  cylinder{OLD,W,0.1 texture { pigment { color srgb <0,0,1>}}}
#end
#end
}

object { UN translate SPACE*2*(x-2*z) }
object { UN rotate 90*x translate SPACE*2*(x-4*z) }
plane{ y,-Minor*2 texture { pigment { color srgb 0.5 } } }