geoclide.transform module#

Geometric transformations of the geoclide objects.

This module implements the Transform class, which encapsulates a 4x4 transformation matrix along with its inverse. A transform is applied by calling it directly on a Vector, Point, Normal, Ray or BBox, returning an object of the same nature, and two transforms can be combined by multiplication. Helper functions create the common transformations: translation, scale, and rotations around the x, y or z axis or around an arbitrary axis.

class geoclide.transform.Transform(m: Transform | ndarray | None = None, m_inv: ndarray | None = None)[source]#

Bases: object

Represents 3D geometric transformation(s) using a 4x4 matrix or ntx4x4 matrix, where nt is the number of transformations

It allows translation, rotation and scalling. It can be applied to vectors, points, normals and rays

Parameters:
mTransform or ndarray, optional

The matrix of the transformation(s), of shape (4, 4) or (nt, 4, 4) for a set of nt transformations

m_invTransform or ndarray, optional

The inverse matrix of the transformation(s), of shape (4, 4) or (nt, 4, 4) for a set of nt transformations

Methods

__call__(...)

Apply the transformations

inverse()

Inverse the transformation(s) matrix

rotate(angle, axis[, diag_calc])

Update the self transformation(s) by adding a rotate transformation(s)

rotate_x(angle)

Update the self transformation(s) by adding a rotate_x transformation(s)

rotate_y(angle)

Update the self transformation(s) by adding a rotate_y transformation(s)

rotate_z(angle)

Update the self transformation(s) by adding a rotate_z transformation(s)

scale(v)

Update the self transformation(s) by adding a scale transformation(s)

translate(v)

Update the self transformation(s) by adding a translate transformation(s)

is_identity

Examples

>>> import geoclide as gc
>>> t1 = gc.Transform()
>>> t1
m=
array(
 [[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]] )
m_inv=
array(
 [[1. 0. 0. 0.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]] )
__call__(c: Vector, diag_calc: bool = False, flatten: bool = False) Vector[source]#
__call__(c: Point, diag_calc: bool = False, flatten: bool = False) Point
__call__(c: Normal, diag_calc: bool = False, flatten: bool = False) Normal
__call__(c: Ray, diag_calc: bool = False, flatten: bool = False) Ray
__call__(c: BBox, diag_calc: bool = False, flatten: bool = False) BBox

Apply the transformations

Parameters:
cVector or Point or Normal or Ray or BBox

The vector(s)/point(s)/normal(s)/ray(s)/bounding box(es) to which the transformation is applied

diag_calcbool, optional

Perform diagonal calculations between c(i) and tranformation(i). The number of transformations must be equal to the number of vectors/points/ …

Returns:
Vector or Point or Normal or Ray or BBox or ndarray

The vector(s)/point(s)/normal(s)/ray(s)/bounding box(es) after the application of the transformation(s). In case of several transformations, it returns a 1-D ndarray of dtype equals to the c parameter type, but if flatten is True returns directly an object of same type as the c parameter.

Examples

>>> import geoclide as gc
>>> t = gc.get_translate_tf(gc.Vector(5., 5., 5.))
>>> p = gc.Point(0., 0., 0.)
>>> t[p]
Point(5.0, 5.0, 5.0)
inverse() Transform[source]#

Inverse the transformation(s) matrix

Parameters:
tTransform

The transformation(s) to be inversed

Returns:
Transform

The inversed transformation(s)

is_identity() bool[source]#
rotate(angle: float | ndarray, axis: Vector | Normal, diag_calc: bool = False) Transform[source]#

Update the self transformation(s) by adding a rotate transformation(s)

Warning

The angle parameter can be a 1-D array only if axis parameter is a Vector/Normal with scalar x, y, z components, or if the parameter diag_calc=True

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s). In case of an ndarray, it must be 1-D

axisVector or Normal

The rotation(s) is/are performed around the vector(s)/normal(s) axis/axes

diag_calcbool, optional

Perform diagonal calculations in case angle is a 1-D ndarray and axis is a Vector/Normal with 1-D ndarray x, y, z components. Use angle(i) with axis(i) to calculate transformation(i)

Returns:
Transform

The product of the self transformation(s) and the rotate transformation(s) matrices

rotate_x(angle: float | ndarray) Transform[source]#

Update the self transformation(s) by adding a rotate_x transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the x axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The product of the self transformation(s) and the rotate_x transformation(s) matrices

rotate_y(angle: float | ndarray) Transform[source]#

Update the self transformation(s) by adding a rotate_y transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the y axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The product of the self transformation(s) and the rotate_y transformation(s) matrices

rotate_z(angle: float | ndarray) Transform[source]#

Update the self transformation(s) by adding a rotate_z transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the Z axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The product of the initial transformation(s) and the rotate_z transformation(s) matrices

scale(v: Vector) Transform[source]#

Update the self transformation(s) by adding a scale transformation(s)

Parameters:
vVector

The vector(s) used for scale transformation(s)

Returns:
Transform

The product of the self transformation(s) and the scale transformation(s) matrices

translate(v: Vector) Transform[source]#

Update the self transformation(s) by adding a translate transformation(s)

Parameters:
vVector

The vector(s) used for the transformation(s)

Returns:
Transform

The product of the self transformation(s) and the translate transformation(s)

Examples

>>> import geoclide as gc
>>> t = Transform()
>>> t = t.translate(gc.Vector(5.,0.,0.))
>>> t
m=
array(
 [[1. 0. 0. 5.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]] )
m_inv=
array(
 [[ 1.  0.  0. -5.]
 [ 0.  1.  0.  0.]
 [ 0.  0.  1.  0.]
 [ 0.  0.  0.  1.]] )
geoclide.transform.get_inverse_tf(t: Transform) Transform[source]#

Get the inverse transformation(s)

Parameters:
tTransform

The transformation(s) to be inversed

Returns:
Transform

The inversed transformation(s)

geoclide.transform.get_rotate_tf(angle: float | ndarray, axis: Vector | Normal, diag_calc: bool = False) Transform[source]#

Get the rotate transformation(s) around a given axis/axes

Warning

The angle parameter can be a 1-D array only if axis parameter is a Vector/Normal with scalar x, y, z components, or if the parameter diag_calc=True

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s). In case of an ndarray, it must be 1-D

axisVector or Normal

The rotation(s) is/are performed around the vector(s)/normal(s) axis/axes

diag_calcbool, optional

Perform diagonal calculations in case angle is a 1-D ndarray and axis is a Vector/Normal with 1-D ndarray x, y, z components. Use angle(i) with axis(i) to calculate transformation(i)

Returns:
Transform

The rotate transformation(s)

geoclide.transform.get_rotate_x_tf(angle: float | ndarray) Transform[source]#

Get the rotate_x transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the x axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The rotate_x transformation(s)

geoclide.transform.get_rotate_y_tf(angle: float | ndarray) Transform[source]#

Get the rotate_y transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the y axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The rotate_y transformation(s)

geoclide.transform.get_rotate_z_tf(angle: float | ndarray) Transform[source]#

Get the rotate_z transformation(s)

Parameters:
anglefloat or ndarray

The angle(s) in degrees for the rotation(s) around the Z axis. In case of an ndarray, it must be 1-D

Returns:
Transform

The rotate_z transformation(s)

geoclide.transform.get_scale_tf(v: Vector) Transform[source]#

Get the scale transformation(s)

Parameters:
vVector

The vector(s) used for scale transformation(s)

Returns:
Transform

The scale transformation(s)

geoclide.transform.get_translate_tf(v: Vector) Transform[source]#

Get the translate transformation(s)

Parameters:
vVector

The vector(s) used for the translate transformation(s)

Returns:
Transform

The translate transformation(s)

Examples

>>> import geoclide as gc
>>> t = gc.get_translate_tf(gc.Vector(5.,0.,0.))
>>> t
m=
array(
 [[1. 0. 0. 5.]
 [0. 1. 0. 0.]
 [0. 0. 1. 0.]
 [0. 0. 0. 1.]] )
m_inv=
array(
 [[ 1.  0.  0. -5.]
 [ 0.  1.  0. -0.]
 [ 0.  0.  1. -0.]
 [ 0.  0.  0.  1.]] )