Version 0.55.1

Modifiers

One construct that was silently used throughout this manual's examples but that hasn't been explained yet is the concept of modifiers. A modifier is an object that acts on a solid and modifies it in some way. Typical kinds of a modifiers are transformations or a color applications.

Modifiers can be of different data types (although there is also a specific modifier data type). A modifier is defined just like any other objects, i.e. by declaring a variables or by calling its constructors. In this section we will show how to use the translation transformation as example of a modifier. Its constructor translation( vector ) takes one vector as single argument. This defines a relative shift in space that is applied to a solid when the modifier is used on it.

The '>>' operator

A modifier is applied to a solid by using the '>>' operator. This operator expects a modifier to its left and a solid to its right hand side. The following example creates a box that is shifted two units into the X direction:

Example

make translation( <[2.0,0.0,0.0]> ) >> box()

Multiple modifiers can be applied at once by using multiple '>>' operators. One rule is, that the operators are right-associative (see https://en.wikipedia.org/wiki/Operator_associativity ), meaning that onto the solid (that stands on the far right side of the expression) the modifier to its left is applied first, then the modifier one step further to the left and so on. (This behavior equals the application of vector space operators like matrices in a mathematical notation.) The following example shifts the box two units in X direction first and then three units into Z direction:

Example

make translation( <[0.0,0.0,3.0]> ) >> translation( <[2.0,0.0,0.0]> ) >> box()

In the case of translations the order of the application plays of course no role but for other transformations like rotations it does. It is therefore useful to know about the application order.

Remark

Certain modifiers can also be applied onto other data types than solids. One example are transformation that can be used to transform vector values as well.

The modifier data type

Sometimes it might be useful to "conserve" a certain set of successive modifiers or to pass it to a function etc. This is possible by using the data type modifier that is a generalization of all special modifiers (in a similar way as solid is a generalization of e.g. the primitive data types):

Example

modifier m = translation( <[0.0,0.0,3.0]> ) >> translation( <[2.0,0.0,0.0]> )
make m >> box()

The '<<=' operator

Like many other binary operators, the '>>' operators has a brother that applies the operation directly to a variable on its left hand side. This is the '<<=' operator. Note that the direction of the angle brackets have changed since the expression on the right is now applied to the variable on the left and not in the "left to right" fashion of '>>':

Example

modifier m = rotation( <[0.0, 1.0, 1.0]>, rad( 20.0 ) )
solid s = box()
s <<= m
make s

🗙

Search results for