Point, vector, helper functions.
ZenCad has some math helpers and functions for working with them.
Some ZenCad functions use points or point arrays as parameters. You can use the
point3 function to create a point object. In addition, often a function can itself form points from a list or a tuple of coordinates.
point3(0,3,6) #Equivalent calls interpolate([point3(0,0,0), point3(0,0,10), point3(10,0,10)]) interpolate([(0,0,0), (0,0,10), (10,0,10)]) interpolate(points([(0,0,0), (0,0,10), (10,0,10)]))
A point can be displayed with the display function as the corresponding vertex for such a point.
Sometimes, in addition to specifying points, vector objects are used to indicate directions. The principle of working with vectors is similar to working with points.
vector3(1,2,3) interpolate(pnts=[(0,0,0), (0,0,10), (10,0,10)], tangs=[(0,0,1), (1,0,0), (0,1,0)])
The vector cannot be displayed directly. Unlike a point, a vector ignores translation during transformations.
Point and vector arrays
The vectors and points functions explicitly create arrays of points from arrays of coordinates. points2 creates a two-dimensional array of points from a two-dimensional list.
points([(0,0,0), (0,0,10), (10,0,10)]) vectors([(0,0,1), (1,0,0), (0,1,0)]) points2([ [(0,0,0), (0,0,10), (10,0,10)], [(1,6,0), (0,5,10), (10,5,10)] ])
Incremental array of points
Creates an array of points based on offsets.
points_incremental([(0,2,0), (0,0,10), (5,0,0), (5,0,0)]) # Создаёт масив точек: # (0,2,0) # (0,2,10) # (5,2,10) # (10,2,10)
Operations on points and vectors
Points and vectors can be used in mathematical operations according to the rules of linear algebra.
pnt - pnt -> vec pnt + vec -> pnt vec + vec -> vec vec - vec -> vec
Empty primitive. nullshape
Empty primitive. Can participate in boolean operations.
An example of use in a loop:
it = nullshape() for i in range(7): it = it + box(20).translate(10*i,10*i,10*i) #alternate: union([box(20).translate(10*i,10*i,10*i) for i in range(7)])
Conversion of angular values. Radians and degrees
The zencad API uses radians to define angles. Using degrees requires scaling a numerical factor. This is exactly what the deg function does (synonymous with deg2rad):
deg (180) matches
The reverse conversion is performed by the rad2deg function.
# Convert degrees to radians: def deg2rad(grad) def deg(grad) # Convert radians to degrees: def rad2deg(rad)
Function code deg2rad, rad2deg:
def deg2rad(grad): return float(grad) / 180.0 * math.pi def rad2deg(rad): return float(rad) * 180.0 / math.pi
Register FreeType font in system.