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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1);
new IPoint(pt2);
new IPoint(pt3);
new IPoint(pt4);

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

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

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

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

ISurface surface2 = new 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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1);
new IPoint(pt2);
new IPoint(pt3);
new IPoint(pt4);

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

ICurve curve2 = curve1.dup();

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

ISurface surface2 = surface1.dup();

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

ISurface surface4 = surface3.cp(new 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).

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1).clr(0);
new IPoint(pt2).clr(0);
new IPoint(pt3).clr(0);
new IPoint(pt4).clr(0);

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

curve1.scale(2);

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

surface1.scale(2.5);
surface2.scale(new 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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1).clr(0);
new IPoint(pt2).clr(0);
new IPoint(pt3).clr(0);
new IPoint(pt4).clr(0);

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

// scaling in x direction
surface1.scale1d(new IVec(1,0,0), 2);

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

// just showing the scaling direction
new IVec(1,1,0).show(new 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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1).clr(0);
new IPoint(pt2).clr(0);
new IPoint(pt3).clr(0);
new IPoint(pt4).clr(0);

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

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

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

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

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

// just showing the rotation axis
new IVec(1,1,1).show(new 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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1).clr(0);
new IPoint(pt2).clr(0);
new IPoint(pt3).clr(0);
new IPoint(pt4).clr(0);

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

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

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

// reflect on yz-plane
surface1.ref(new IVec(1,0,0));

// reflect on zx-plane at (0,-20,0)
surface2.ref(new IVec(0,-20,0), new 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.

```import processing.opengl.*;
import igeo.*;

size(480,360,IG.GL);

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

// showing original location
new IPoint(pt1).clr(0);
new IPoint(pt2).clr(0);
new IPoint(pt3).clr(0);
new IPoint(pt4).clr(0);

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

// shearing in x
surface1.shearXY(1, 0);

// shearing in y
surface2.shearXY(new IVec(20,10,0), 0, -1.5);
```

(back to the list of tutorials)