pytha Axes and Directions - pytha-3d-cad/pytha-lua-api GitHub Wiki

By default, PYTHA uses the currently active coordinate system, i.e. either global XYZ coordinates or a user-defined local coordinate system. Some functions provide an optional parameter specifying u/v/w axes. These axes overwrite the active coordinate system in the function scope and allow for arbitrary positioning in space.

Specifying coordinate systems / axes

The origin is often an own parameter and has to be given as a table of three numbers {x, y, z}.

The axes are usually specified in a (options-) table.

Field Type Description
u_axis {x, y, z} or string Direction of the u-axis (i.e. the local coordinate system x-axes) specified in terms of the currently active coordinate system
v_axis {x, y, z} or string Direction of the v-axis (i.e. the local coordinate system y-axes) specified in terms of the currently active coordinate system
w_axis {x, y, z} or string Direction of the w-axis (i.e. the local coordinate system z-axes) specified in terms of the currently active coordinate system

The axes may also be specified as special string constants:

  • "x" equivalent to {1, 0, 0}
  • "y" equivalent to {0, 1, 0}
  • "z" equivalent to {0, 0, 1}
  • "-x" equivalent to {-1, 0, 0}
  • "-y" equivalent to {0, -1, 0}
  • "-z" equivalent to {0, 0, -1}

The basis vectors for the axes are automatically normalized. I.e. they do not need to be unit vectors. And they cannot be used for stretching parts.

Specifying two basis vectors is enough, because the given basis vectors are always corrected to a right-handed orthonormal set before they are used as a coordinate system.

Example

The following example creates a rotated block

local origin = {1000, 500, 0}
pytha.create_block(length, width, height, origin, {u_axis = {1,1,0}, w_axis = "z"}) 

Local Coordinates

Especially in situations, where several parts need to be created with a given placement (e.g. in a cabinet generator), local coordinate systems come in handy. By pushing a local coordinate system (push_local_coordinates), you can replace the active coordinate system with one that is better adapted to the situation at hand.

Let's expand the sample above and create two blocks next to each other. Instead of some possibly tricky calculations to obtain the origin of the second block, we can use local coordinates:

local origin = {1000, 500, 0}
pytha.push_local_coordinates(origin, {u_axis = {1,1,0}, w_axis = "z"}) 

pytha.create_block(length, width, height, {0, 0, 0}) 
pytha.create_block(length, width, 2 * height, {length, 0, 0}) 

pytha.pop_local_coordinates() 

Local coordinate systems are remembered until they are explicitly popped again. So, do not forget to pop_local_coordinates, when finished.

In more complex situations, it can be handy to nest local coordinate systems. The nested coordinates are always specified with respect to their direct ancestor. The pop operation removes the innermost nested coordinate system in a first-in-last-out stack.

See also

create_block, push_local_coordinates, pop_local_coordinates, create_block