@@ -637,24 +637,24 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
637637// extra_pts = Number of extra control points to add to provide additional freedom to control undesirable oscillations. Default: 0
638638// smooth = Smoothness criterion used with extra control points. Set to 1 (minimize control-polygon length), 2 (minimize control-polygon bending) or 3 (minimize curve bending energy). Default: 3
639639//
640- // Example(2D): Clamped curve (default)
640+ // Example(2D): 2D Clamped curve (default)
641641// data = [[0,0], [10,30], [25,15], [40,35], [60,10], [80,25]];
642- // path = nurbs_curve(nurbs_interp(data, 3));
643- // stroke(path);
644- // color("red") move_copies(data) circle(r=1, $fn=16);
642+ // debug_nurbs_interp(data, 3);
645643//
646- // Example(2D): Closed curve - Do NOT repeat the first point at the end.
644+ // Example(2D,VPT=[40,12,0],VPD = 200 ): Closed curve - Do NOT repeat the first point at the end.
647645// data = [[0,0], [30,50], [60,40], [80,10], [50,-20], [20,-10]];
648- // path = nurbs_curve(nurbs_interp(data, 3, closed = true));
649- // stroke(path, closed = true);
650- // color("red") move_copies(data) circle(r=1, $fn=16);
646+ // debug_nurbs_interp(data, 3, closed = true);
651647//
652- // Example(2D): Closed polygon - All data points lie exactly on the polygon boundary.
648+ // Example(2D, VPT=[40,12,0],VPD = 200 ): Closed polygon - All data points lie exactly on the polygon boundary.
653649// data = [[0,0], [30,50], [60,40], [80,10], [50,-20], [20,-10]];
654650// path = nurbs_curve(nurbs_interp(data, 3, closed=true), splinesteps=16);
655651// polygon(path);
656652// color("red") move_copies(data) circle(r=1, $fn=16);
657653//
654+ // Example(3D,VPT=[0,0,10],VPR=[60,0,330],VPD=120): 3D closed curve
655+ // data3d = [[20,0,0],[0,20,20],[-20,0,0],[0,-20,10]];
656+ // debug_nurbs_interp(data3d, 3, splinesteps=32, closed=true);
657+ //
658658// Example(2D): Get just the path
659659// data = [[0,0], [10,30], [25,15], [40,35], [60,10], [80,25]];
660660// path = nurbs_curve(nurbs_interp(data, 3), splinesteps=16);
@@ -668,17 +668,17 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
668668// stroke(curve, width=0.5);
669669// color("red") move_copies(data) circle(r=1, $fn=16);
670670//
671- // Example(2D,Med): Endpoint tangent control - Specify start and/or end tangent vectors. Each vector is automatically scaled by the total chord length; a unit vector produces natural arc-length speed. Magnitude > 1 increases pull, < 1 weakens it.
671+ // Example(2D,Med,VPT=[40,20,0],VPD=160 ): Endpoint tangent control - Specify start and/or end tangent vectors. Each vector is automatically scaled by the total chord length; a unit vector produces natural arc-length speed. Magnitude > 1 increases pull, < 1 weakens it.
672672// data = [[0,0], [20,30], [50,25], [80,0]];
673673// // No tangent control (natural):
674- // color("gray ") stroke(nurbs_curve(nurbs_interp(data, 3)), width=0.3);
674+ // color("lime ") stroke(nurbs_curve(nurbs_interp(data, 3)), width=0.3);
675675// // Start going straight up, end going straight down:
676676// color("blue") stroke(
677677// nurbs_curve(nurbs_interp(data, 3, start_deriv=[0,1], end_deriv=[0,-1])), width=0.3);
678678// // Start going right, end going right:
679679// color("red") stroke(
680680// nurbs_curve(nurbs_interp(data, 3, start_deriv=[1,0], end_deriv=[1,0])), width=0.3);
681- // color("black") move_copies(data) circle(r=0.5 , $fn=16);
681+ // color("black") move_copies(data) circle(r=0.75 , $fn=16);
682682//
683683// Example(2D,Huge,NoAxes,VPT=[55,50,0],VPR=[0,0,0],VPD=600): Controlling the start and end of an otherwise unconstrained NURBS curve using derivitives.
684684// data = [[0,0], [20,30], [30,90], [36,111],[50,25], [80,0]];
@@ -702,7 +702,7 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
702702// Example(2D,Huge,NoAxes,VPT=[45,50,0],VPR=[0,0,0],VPD=600): Controlling the shape with derivatives and corners
703703// data = [[0,0], [20,30], [30,90], [36,111],[50,25], [80,0]];
704704// xdistribute(110){
705- // union(){
705+ // back(20) union(){
706706// debug_nurbs_interp(data,3, splinesteps=32, data_size=1,
707707// deriv=[2*RIGHT,[0,1],undef,undef,undef,RIGHT],
708708// );
@@ -714,18 +714,18 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
714714// );
715715// fwd(15)text("derivs at pts 1, 4",size=6);
716716// }
717- // union(){
717+ // fwd(20) union(){
718718// debug_nurbs_interp(data,3, splinesteps=32, data_size=1,
719719// deriv=[undef,[0,1],undef,undef,NAN,undef],
720720// );
721721// fwd(15)text("corner and pt 1 deriv",size=6);
722722// }
723723// }
724724//
725- // Example(2D,Huge,NoAxes,VPT=[70,50,0],VPR=[0,0,0],VPD=725):
725+ // Example(2D,Huge,NoAxes,VPT=[70,50,0],VPR=[0,0,0],VPD=725): Specifying the curvature at select points. In the middle example shows continuous curvature joins to arcs at each end.
726726// data = [[0,0], [20,30], [30,90], [36,111],[50,25], [80,0]];
727727// xdistribute(110){
728- // union(){
728+ // back(30) union(){
729729// debug_nurbs_interp(data,3, splinesteps=32, data_size=1,
730730// start_deriv=RIGHT,end_deriv=RIGHT, start_curvature=0,end_curvature=0
731731// );
@@ -741,7 +741,7 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
741741// }
742742// fwd(15)text("ends curvature>0",size=6);
743743// }
744- // union(){
744+ // fwd(30) union(){
745745// debug_nurbs_interp(data,3, splinesteps=32, data_size=1,
746746// deriv=[undef,[0,1],undef,[1,0],undef,undef],
747747// curvature=[undef,-1/10,undef,0,undef,undef]
@@ -750,6 +750,45 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
750750// }
751751// }
752752//
753+ // Example(2D,Huge,NoAxes,VPT=[45,50,0],VPR=[0,0,0],VPD=700): Closed NURBS curves
754+ // data = [[0,0], [20,30], [30,90], [36,111],[50,25], [80,0]];
755+ // xdistribute(120){
756+ // union(){
757+ // debug_nurbs_interp(data,3, splinesteps=32, data_size=1, closed = true
758+ // );
759+ // fwd(22)text("unconstrained",size=6);
760+ // }
761+ // union(){
762+ // debug_nurbs_interp(data,3, splinesteps=32, data_size=1, closed = true,
763+ // deriv=[[0,1]/4, undef, undef, undef, undef, [0,-1]/3]
764+ // );
765+ // fwd(15)text("deriv at pts 0 and 5",size=6);
766+ // }
767+ // union(){
768+ // debug_nurbs_interp(data,3, splinesteps=32, data_size=1, closed = true,
769+ // deriv=[undef,undef,undef,[1,0],undef,undef]
770+ // );
771+ // fwd(15)text("deriv at point 4",size=6);
772+ // }
773+ // }
774+ //
775+ // Example(2D,Huge,NoAxes,VPT=[45,50,0],VPR=[0,0,0],VPD=500): Closed NURBS curves with corners
776+ // data = [[0,0], [20,30], [30,90], [36,111],[50,25], [80,0]];
777+ // xdistribute(120){
778+ // union(){
779+ // debug_nurbs_interp(data,3, splinesteps=32, data_size=1, closed = true,
780+ // deriv=[undef,[0,1],undef,undef,NAN,undef]
781+ // );
782+ // fwd(20)text("pt 1 deriv and pt 4 corner",size=6);
783+ // }
784+ // union(){
785+ // debug_nurbs_interp(data,3, splinesteps=32, data_size=1, closed = true,
786+ // deriv=[undef,NAN,undef,undef,NAN,undef]
787+ // );
788+ // fwd(20)text("corners at pts 1 and 4", size=6);
789+ // }
790+ // }
791+ //
753792// Example(2D,NoAxes,Big): Unconstrained NURBS through the same data points vary depending on the paramaterization method chosen
754793// data = [[0,0], [20,30], [35,120], [50,30], [70,0]];
755794// method = ["length", "centripetal", "dynamic", "foley", "fang"];
@@ -815,13 +854,13 @@ module debug_nurbs(control,degree,splinesteps=16,width=1, size, mult,weights,typ
815854// curvature = [undef,-0.06,undef,undef,undef,undef,undef,-0.06]));
816855// right(75) stroke(path3, closed = true);
817856//
818- // Example(2D,Big ): Parameterization methods for sharp turns. For data with sudden direction changes or uneven chord spacing, "centripetal" and "dynamic" reduce unwanted oscillations.
819- // // "length" (blue), "centripetal" (red), "dynamic" (orange ) compared.
857+ // Example(2D,Med,VPT=[30,15,0],VPD=147 ): Parameterization methods for sharp turns. For data with sudden direction changes or uneven chord spacing, "centripetal" and "dynamic" reduce unwanted oscillations.
858+ // // "length" (blue), "centripetal" (red), "dynamic" (green ) compared.
820859// sharp = [[0,0], [5,40],[6,40], [10,0], [50,0], [55,40],[56,42], [60,0]];
821860// color("blue") stroke(nurbs_curve(nurbs_interp(sharp, 3, method = "centripetal"), splinesteps=32), width=0.25);
822861// color("red") stroke(nurbs_curve(nurbs_interp(sharp, 3, method="foley"), splinesteps=32), width=0.25);
823- // color("orange ") stroke(nurbs_curve(nurbs_interp(sharp, 3, method="dynamic"), splinesteps=32), width=0.25);
824- // color("green ") move_copies(sharp) circle(r=.5 , $fn=16);
862+ // color("lime ") stroke(nurbs_curve(nurbs_interp(sharp, 3, method="dynamic"), splinesteps=32), width=0.25);
863+ // color("black ") move_copies(sharp) circle(r=.6 , $fn=16);
825864
826865
827866function nurbs_interp(points, degree, method= "centripetal" , closed= false ,
0 commit comments