home processing download documents tutorial python tutorial gallery source about
 Python Tutorials (back to the list of tutorials)

Transformation of Geometries

     Move (Add / Translate)

There are list of transformation methods for ICurve and ISurface objects similar to IVec methods.
The first shown here is move method. You can use mv() method providing vector to specify amount of movement. add() and translate() are alias of mv() and can be used in the same way.

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1)
IPoint(pt2)
IPoint(pt3)
IPoint(pt4)

curve1 = ICurve(pt1.dup(), pt2.dup())

curve1.mv(IVec(0,-20,30)).clr(0,0,1.)

surface1 = ISurface(pt1.dup(), pt2.dup(), pt3.dup(), pt4.dup())

surface1.mv(IVec(0,0,-20)).clr(.5,0,0)

surface2 = ISurface(pt1.dup(), pt2.dup(), pt3.dup(), pt4.dup())

surface2.mv(-60,0,0).clr(.5,.2,.5)


     Duplicate (Copy)

To duplicate geometry, please use dup() without an input argument. You can also use cp() without an argument or with argument of vector to copy and move the geometry.

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1)
IPoint(pt2)
IPoint(pt3)
IPoint(pt4)

curve1 = ICurve(pt1.cp(), pt2.cp())

curve2 = curve1.dup()

surface1 = ISurface(pt1.cp(), pt2.cp(), pt3.cp(), pt4.cp())

surface2 = surface1.dup()

surface3 = surface2.cp().clr(1.0,0,0)

surface4 = surface3.cp(IVec(-60, 0, 0))

     Scale

To scale up or down geometries, you can use scale() method with an argument of scaling factor. You can also use mul() in the same way. If you have a center location for scaling, you put the center location in scale() method. Without a center, geometries are scaled based on the origin (0,0,0).

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1).clr(0)
IPoint(pt2).clr(0)
IPoint(pt3).clr(0)
IPoint(pt4).clr(0)

curve1 = ICurve(pt1.cp(), pt2.cp()).clr(1.,0,0)

curve1.scale(2)

surface1 = ISurface(pt1.cp(),pt2.cp(),pt3.cp(),pt4.cp()).clr(1.)
surface2 = surface1.dup().clr(0,0,.5)

surface1.scale(2.5)
surface2.scale(IVec(20,10,0), 2)


     Scale in 1 Direction

You can scale geometries only in one direction with scale1d method either with two arguments of a scaling direction vector and scale factor or with three arguments of a center, a scaling direction vector and scale factor. If scaled without a center, the origin (0,0,0) is used as center.

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1).clr(0)
IPoint(pt2).clr(0)
IPoint(pt3).clr(0)
IPoint(pt4).clr(0)

surface1 = ISurface(pt1.cp(),pt2.cp(),pt3.cp(),pt4.cp()).clr(1.)
surface2 = surface1.dup().clr(0,0,.5)

# scaling in x direction
surface1.scale1d(IVec(1,0,0), 2)

# scaling in vector (1,1,0) direction from center (20,10,0).
surface2.scale1d(IVec(20,10,0), IVec(1,1,0), 3)

# just showing the scaling direction
IVec(1,1,0).show(IVec(20,10,0)).mul(50).size(10).clr(1.,0,0)


     Rotate

You can rotate geometries with rot() method. You put either two argument of a rotation axis vector and angle or three argument of a center, a rotation axis vector and angle. If you don't put a center, a geometry is rotated around the origin (0,0,0). The unit of rotation angle is radian and the positive direction of rotation is following the right hand screw rule.

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1).clr(0)
IPoint(pt2).clr(0)
IPoint(pt3).clr(0)
IPoint(pt4).clr(0)

curve1 = ICurve(pt1.cp(), pt2.cp()).clr(1.,0,0)

# rotation around y axis
curve1.rot(IVec(0,1,0), PI/4)

surface1 = ISurface(pt1.cp(),pt2.cp(),pt3.cp(),pt4.cp()).clr(1.)
surface2 = surface1.dup().clr(0,0,.5)

# rotation around z axis
surface1.rot(IVec(0,0,1), PI/4)

# rotation around vector (1,1,1) axis and center (20,10,0).
surface2.cp().rot(IVec(20,10,0), IVec(1,1,1), PI/6)

# just showing the rotation axis
IVec(1,1,1).show(IVec(20,10,0)).mul(10).clr(0)


     Reflect (Mirror)

To reflect geometry, you can use ref() method either with one argument of a normal vector of the reflection plane or with a center and a normal vector of the reflection plane. mirror() is alias of ref() and can be used in the same way.

add_library('igeo')

size(480,360,IG.GL)

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1).clr(0)
IPoint(pt2).clr(0)
IPoint(pt3).clr(0)
IPoint(pt4).clr(0)

curve1 = ICurve(pt1.cp(), pt2.cp()).clr(1.,0,0)

# reflect on a diagonal plane
curve1.cp().ref(IVec(0,-10,0), IVec(0,1,0))

surface1 = ISurface(pt1.cp(),pt2.cp(),pt3.cp(),pt4.cp()).clr(1.)
surface2 = surface1.dup().clr(0,0,.5)

# reflect on yz-plane
surface1.ref(IVec(1,0,0))

# reflect on zx-plane at (0,-20,0)
surface2.ref(IVec(0,-20,0), IVec(0,1,0))


     Shear

You can shear geometries on xy-plane by shearXY() either with two arguments of shear amount of x and of y or with three arguments of a center, shear amount of x and of y. There are also shearYZ() and shearZX() to shear in yz-plane and zx-plane.

add_library('igeo')

size(480,360,IG.GL) 

pt1 = IVec(0,0,0)
pt2 = IVec(40,0,0)
pt3 = IVec(40,20,0)
pt4 = IVec(0,20,0)

# showing original location
IPoint(pt1).clr(0)
IPoint(pt2).clr(0)
IPoint(pt3).clr(0)
IPoint(pt4).clr(0)

surface1 = ISurface(pt1.cp(),pt2.cp(),pt3.cp(),pt4.cp()).clr(1.)
surface2 = surface1.dup().clr(0,0,.5)

# shearing in x
surface1.shearXY(1, 0)

# shearing in y
surface2.shearXY(IVec(20,10,0), 0, -1.5)


(back to the list of tutorials)

HOME
FOR PROCESSING
DOWNLOAD
DOCUMENTS
TUTORIALS (Java / Python)
GALLERY
SOURCE CODE(GitHub)
ABOUT