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

Fundamental Geometries in iGeo

     Creating Points

The first simplest geometry to create would be a point. It can be created by instantiating a IPoint class. Three numbers in the arguments of IPoint constructor are x y z coordinates.

add_library('igeo')

size( 480, 360, IG.GL )

IPoint(0,0,0)
IPoint(20,0,0)
IPoint(20,20,0)
IPoint(0,20,0)


     Setting Color of Objects

To set color to iGeo objects, use clr() method with arguments of either float(0.0-1.0) or int (0-255) or hsb() method with float.

add_library('igeo')

size( 480, 360, IG.GL )

IPoint(0,0,0).clr(255,0,0) # RGB in int
IPoint(20,0,0).clr(0,0.3,0.9) # RGB in float or double
IPoint(20,20,0).hsb(0.5,1.0,0.9) # HSB in float or double
IPoint(0,20,0).clr(255) # grayscale in int, float or double


     Creating Lines

To create line objects, use ICurve class (a line is seen as a type of a curve). Put x, y, z of the start point and x, y, z of the end point in the argument.

add_library('igeo')

size( 480, 360, IG.GL )

ICurve(0,0,0, 30,30,30)
ICurve(0,-10,0, 30,10,20).clr(0.5,0,0)
ICurve(0,-20,0, 30,-10,10).clr(1.0,0,0) # NOTE: float is put in clr()
ICurve(0,-30,0, 30,-30,0).clr(1,0,0) # NOTE: int is put in clr() and the range of int in color is 0-255


     Creating NURBS Curves

To create NURBS(Non-Uniform Rational Basis Spline) curve objects, use also ICurve class. Put array of x, y, z as control points and degree of the curve in the argument. The array of x, y, z needs to be 2D array. Note that to create degree 2 curve you need more than 3 control points and for degree 3, more than 4.

add_library('igeo')

size( 480, 360, IG.GL )

controlPoints1 = [[0,0,0], [20,20,20], [-20,20,0]]
ICurve(controlPoints1, 2) # degree = 2

# to put number inside
ICurve([[0,15,0], [20,35,20], [-20,35,0]], 2).clr(1.,0,0)

# degree 1 curve (polyline)
controlPoints2 = [[-60,-30,0], [-60,-10,0], [-40,-30,0], [-40,-10,0]]
ICurve(controlPoints2, 1).clr(0,1.,1.)

# or you can omit the degree argument for polyline
controlPoints3 = [[-30,-30,0], [-30,-10,0], [-10,-30,0], [-10,-10,0]]
ICurve(controlPoints3).clr(0,0.5,1.)

# degree 2 curve
controlPoints4 = [[0,-30,0], [0,-10,0], [20,-30,0], [20,-10,0]]
ICurve(controlPoints4,2).clr(.5,0,1.)

# degree 3 curve
controlPoints5 = [[30,-30,0], [30,-10,0], [50,-30,0], [50,-10,0]]
ICurve(controlPoints5,3).clr(1.,0,1.)


     Creating Simple Surfaces

Here is an example of creating surfaces specifying 3 or 4 corner points. Use ISurface class to create a surface. Put 3 or 4 of x, y, z coordinates in the argument.

add_library('igeo')

size( 480, 360, IG.GL )

ISurface(0,0,0, 40,40,40, 80,0,0, 40,-40,40)

# 3 corner points (triangle)
ISurface(-50,40,0, -10,40,0, -50,0,0).clr(0,0,1.)

# rectangle
ISurface(-50,-10,0, -10,-10,0, -10,-40,0, -50,-40,0).clr(0,1.,1.)


     Creating NURBS Surfaces

To create NURBS surface specifying degree number, use also ISurface class. The first argument is 2D array of control points in u and v direction of x y z coordinates array. The second argument is u degree and the third is v degree. Note again that to have degree 2 you need more than 3 control points in u or v direction and for degree 3, more than 4.

add_library('igeo')

size( 480, 360, IG.GL )

# 4 points in u direction, 3 points in v direction
controlPoints = \
  [[[-30,-30, 10], [-30,  0,-20], [-30, 30,  0]], \
   [[  0,-30,-10], [  0, 20,-50], [  0, 30,-20]], \
   [[ 30,-30,-20], [ 30, 20, 60], [ 30, 30, 30]], \
   [[ 60,-30,  0], [ 60,  0, 40], [ 60, 30, 30]]]

# u degree = 3, v degree = 2
ISurface(controlPoints, 3, 2).clr(1,.8,0)


(back to the list of tutorials)

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