CSTransform

Affine Transformations for primitives

class CSXCAD.CSTransform.CSTransform

This class can realize affine transformations for all CSPrimtivies. Individual tranformations can be concatenated to the previous. As a result the order of transformations is important.

AddTransform(transform, *args, **kw)

Add a transform by name and arguments.

Examples

Add a translation and 30° rotation around the z-axis:

>>> tr = CSTransform()
>>> tr.AddTransform('Translate', [10, 4,6])
>>> tr.AddTransform('RotateAxis', 'z', 30)

Add a rotation around the axis=[1, 1, 0] by pi/3 (30°):

>>> tr = CSTransform()
>>> tr.AddTransform('RotateOrigin', [1, 1, 0], np.pi/3, deg=False)

Available Transformation keywords:

  • RotateAxis : Rotate around x,y or z-axis

  • RotateOrigin : Rotate around a given axis

  • Translate : Translation vector

  • Scale : Scale value or vector

  • Matrix : A affine transformation matrix as (4,4) array

Parameters:

transform – str – transformation name or keyword.

GetMatrix()

Get the full 4x4 transformation matrix used for transformation.

Returns:

(4,4) array – transformation matrix

HasTransform()

Check if any transformations are set.

Reset()

Reset all transformations.

RotateAxis(ny, angle, deg=True, concatenate=True)

Add a rotation transformation around a cartesian axis (x,y or z).

Parameters:
  • ny – int or str – translation axis vector 0/1/2 or ‘x’/’y’/’z.

  • angle – float – rotation angle (default in degrees)

  • deg – bool – set degree or radiant for angle (default True)

RotateOrigin(vec, angle, deg=True, concatenate=True)

Add a rotation transformation around an arbitrary axis.

Parameters:
  • vec – (3,) array – translation axis vector.

  • angle – float – rotation angle (default in degrees)

  • deg – bool – set degree or radiant for angle (default True)

Scale(scale, concatenate=True)

Add a scaleing transformation.

Parameters:

scale – float or (3,) array – Scaling factor

SetMatrix(mat, concatenate=True)

Add an arbitrary (invertable) trsanslation matrix.

Parameters:

mat – (3,) array – translation vector

SetPostMultiply()

Set all following transformations as post multiply (default)

SetPreMultiply()

Set all following transformations as pre multiply (default is post multiply)

Transform(coord, invers)

Apply a transformation to the given coordinate.

Parameters:
  • coord – (3,) array – coordinate to transform

  • invers – bool – do an invers transformation

Returns:

(3,) array – transformed coordinates

Translate(vec, concatenate=True)

Add a trsanslation transformation.

Parameters:

vec – (3,) array – translation vector