Tutorials | (back to the list of tutorials) |
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] cpts1=new IVec[]{new IVec(-60,0,0),new IVec(-40,0,0), new IVec(-40,20,0),new IVec(-60,20,0) }; ICurve curve1 = new ICurve(cpts1).clr(0); IG.offset(curve1, 5.0).clr(1.0,0,0); IVec[] cpts2=new IVec[]{new IVec(-20,0,0),new IVec(-10,20,0), new IVec(-10,0,0) }; ICurve curve2 = new ICurve(cpts2, true).clr(0); IG.offset(curve2, 5).clr(1.0,0,0); IVec[] cpts3=new IVec[]{new IVec(10,0,0),new IVec(20,20,0), new IVec(20,0,0) }; ICurve curve3 = new ICurve(cpts3, 2).clr(0); IG.offset(curve3, 5).clr(1.,0,0); IVec[] cpts4=new IVec[]{new IVec(40,0,0),new IVec(50,20,0), new IVec(50,0,0)}; ICurve curve4 = new ICurve(cpts4, 2, true).clr(0); IG.offset(curve4, 5).clr(1.,0,0); IVec[] cpts5=new IVec[]{new IVec(-20,60,0),new IVec(10,60,0), new IVec(10,60,20)}; ICurve curve5 = new ICurve(cpts5, true).clr(0); IG.offset(curve5, 5).clr(1.,0,0); IVec[] cpts6=new IVec[]{new IVec(80,0,0),new IVec(90,0,20), new IVec(100,0,20),new IVec(100,20,20), new IVec(80,20,0)}; ICurve curve6 = new ICurve(cpts6, true).clr(0); IG.offset(curve6, 5).clr(1.,0,0);
The offset distance of degree 1 curve can have
constant distance between the original curve (polyline) and
the offset one, like the curve1 and curve2 in
the code above.
However, if the curve's degree is more than 2 and
curving, the distance between two curve is not constant,
like curve3 and curve4 on the code,
because it's simply taking offset vertices of a degree 1 curve
as its control points.
If an input curve is not planar curve,
offset curve is deformed accordingly and also non-planar, like
the curve6 on the code.
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] cpts1 = new IVec[]{new IVec(-50,0,0),new IVec(-30,0,0), new IVec(-30,-20,0),new IVec(-50,-20,0)}; ICurve curve1 = new ICurve(cpts1).clr(1.,0,1.); IVec[] cpts2 = new IVec[]{new IVec(-40,20,30),new IVec(-30,20,30), new IVec(-30,0,30),new IVec(-40,0,30)}; ICurve curve2 = new ICurve(cpts2).clr(1.,0,1.); // loft of two curves IG.loft(curve1, curve2).clr(0.2); IVec[] cpts3 = new IVec[]{new IVec(-20,0,0),new IVec(10,0,0), new IVec(10,-20,0),new IVec(-20,-20,0)}; ICurve curve3 = new ICurve(cpts3,3,true).clr(1.,1.,0); IVec[] cpts4 = new IVec[]{new IVec(-10,0,20),new IVec(0,0,20), new IVec(0,-20,20),new IVec(-10,-20,20)}; ICurve curve4 = new ICurve(cpts4,3,true).clr(1.,1.,0); IVec[] cpts5 = new IVec[]{new IVec(-20,20,40),new IVec(10,20,40), new IVec(10,-20,40),new IVec(-20,-20,40)}; ICurve curve5 = new ICurve(cpts5,3,true).clr(1.,1.,0); // loft of multiple curves in an array (degre=1, straight) IG.loft(new ICurve[]{ curve3, curve4, curve5 }).clr(0.2); ICurve curve6 = curve3.dup().mv(40,0,0).clr(0,1.,1); ICurve curve7 = curve4.dup().mv(40,0,0).clr(0,1.,1); ICurve curve8 = curve5.dup().mv(40,0,0).clr(0,1.,1); // degree 2 curved lofting IG.loft(new ICurve[]{ curve6, curve7, curve8 }, 2 ).clr(0.2);
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] pts1=new IVec[]{new IVec(-50,-20,0),new IVec(-30,-20,0), new IVec(-30,0,0),new IVec(-50,0,0)}; // extrude points to their normal direction IG.extrude(pts1, 30).clr(0.2); IVec[] pts2=new IVec[]{new IVec(-20,0,0),new IVec(10,0,0), new IVec(10,-20,0),new IVec(-20,-20,0) }; // extrude degree 2 closed profile IG.extrude(pts2, 2, true, -20).clr(0.2); IVec[] pts3=new IVec[]{new IVec(20,0,0),new IVec(50,0,0), new IVec(50,-20,0),new IVec(20,-20,0) }; // extrude in the direction specified by a vector IG.extrude(pts3, 1, true, new IVec(10,20,30)).clr(0.2);
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] pts1 = new IVec[]{new IVec(-50,-20,0),new IVec(-30,-20,0), new IVec(-30,0,0),new IVec(-50,0,0)}; ICurve curve1 = new ICurve(pts1).clr(1.,0,1.); IG.extrude(curve1, 30).clr(0.2); IVec[] pts2 = new IVec[]{new IVec(-20,0,0),new IVec(10,0,0), new IVec(10,-20,0),new IVec(-20,-20,0) }; ICurve curve2 = new ICurve(pts2, 2, true).clr(1.,1.,0); IG.extrude(curve2, -20).clr(0.2); IVec[] pts3 = new IVec[]{new IVec(20,0,0),new IVec(50,0,0), new IVec(50,-20,0),new IVec(20,-20,0) }; ICurve curve3 = new ICurve(pts3, 1, true).clr(0,1.,1.); IG.extrude(curve3, new IVec(10,20,30)).clr(0.2);
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] profile1 = new IVec[]{new IVec(5,0,0),new IVec(5,5,0), new IVec(0,5,0)}; IVec[] rail1 = new IVec[]{new IVec(-40,0,-20),new IVec(-30,0,10), new IVec(-50,0,20)}; // sweeping open profile and open rail IG.sweep(profile1, rail1).clr(0.2); IVec[] profile2 = new IVec[]{new IVec(0,0,0),new IVec(10,0,0), new IVec(10,10,0),new IVec(0,10,0)}; IVec[] rail2 = new IVec[]{new IVec(0,20,-20),new IVec(0,0,20), new IVec(0,-20,-20)}; // sweeping degree 2 closed profile and degree 2 open rail IG.sweep(profile2, 3, true, rail2, 2, false).clr(0.5,0,0); IVec[] profile3 = new IVec[]{new IVec(-5,0,0),new IVec(0,5,0), new IVec(0,-5,0)}; IVec[] rail3 = new IVec[]{new IVec(40,20,-20),new IVec(40,0,20), new IVec(40,-20,-20)}; // sweeping degree 2 closed profile and degree 2 open rail IG.sweep(profile3, 1, true, rail3, 1, true).clr(0,0,0.5);
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); IVec[] profile1 = new IVec[]{new IVec(0,0,0),new IVec(10,0,0), new IVec(10,10,0),new IVec(0,10,0)}; ICurve profileCrv1 = new ICurve(profile1,3).clr(0,1.,1.); IVec[] rail1 = new IVec[]{new IVec(-50,0,-30),new IVec(-30,0,0), new IVec(-30,0,30)}; ICurve railCrv1 = new ICurve(rail1).clr(1.,1.,0); // sweeping open profile and open rail IG.sweep(profileCrv1, railCrv1).clr(0.2); // ellipse profile ICurve profileCrv2 = new ICircle(0,0,0,10,5).clr(0,1.,1.); IVec[] rail2 = new IVec[]{new IVec(0,20,-20),new IVec(0,0,20), new IVec(0,-20,-20)}; ICurve railCrv2 = new ICurve(rail2, 2).clr(1.,1.,0); // sweeping degree 2 closed profile and degree 2 open rail IG.sweep(profileCrv2, railCrv2).clr(0.5,0,0); IVec[] profile3 = new IVec[]{new IVec(-5,0,0),new IVec(0,5,0), new IVec(0,-5,0)}; ICurve profileCrv3 = new ICurve(profile3,true).clr(0,1.,1.); // circle profile ICurve railCrv3 = new ICircle(new IVec(40,0,0),new IVec(1,0,0),30).clr(1.,1.,0); // sweeping degree 2 closed profile and degree 2 open rail IG.sweep(profileCrv3, railCrv3).clr(0,0,0.5);
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); ICurve curve1 = new ICurve(new IVec(-40,0,-20),new IVec(-30,20,30)); IG.pipe(curve1, 2).clr(.2); ICurve curve2 = new ICurve(new IVec[]{new IVec(-10,0,-30), new IVec(-10,-10,-10), new IVec(-10,10,10), new IVec(-10,0,30) }); IG.pipe(curve2,6).clr(0.5,0,0); ICurve curve3 = new ICircle(new IVec(20,0,0),new IVec(1,0,0),20); IG.pipe(curve3,4).clr(1.0,0,0.5); ICurve curve4 = new ICurve(new IVec[]{new IVec(50, -20, 20), new IVec(40, 30, 0), new IVec(70, 0, 40), new IVec(50, -10, -10), new IVec(60, -40, -10)}, 2, true); IG.pipe(curve4, 4).clr(0,0,0.8);
In the same way with creating circular pipes, you can also create rectangular or square pipes with IG.rectPipe(ICurve,double,double) or IG.squarePipe(ICurve,double).
import processing.opengl.*; import igeo.*; size(480, 360, IG.GL); ICurve curve1 = new ICurve(new IVec(-40,0,-20),new IVec(-30,20,30)); IG.rectPipe(curve1, 10,2).clr(.2); ICurve curve2 = new ICurve(new IVec[]{new IVec(-10,0,-30), new IVec(-10,-10,-10), new IVec(-10,10,10), new IVec(-10,0,30) }); IG.rectPipe(curve2,5,10).clr(0.5,0,0); ICurve curve3 = new ICircle(new IVec(20,0,0),new IVec(1,0,0),20); IG.squarePipe(curve3,8).clr(1.0,0,0.5); ICurve curve4 = new ICurve(new IVec[]{new IVec(50, -20, 20), new IVec(40, 30, 0), new IVec(70, 0, 40), new IVec(50, -10, -10), new IVec(60, -40, -10)}, 2, true); IG.squarePipe(curve4,8).clr(0,0,0.8);