geoclide.transform module#

class geoclide.transform.Transform(m=None, mInv=None)#

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 | 2-D ndarray | 3-D ndarray, optional

The matrix of the transformation(s)

mInvTransform | 2-D ndarray | 3-D ndarray, optional

The inverse matrix of the transformation(s)

Methods

__call__(c[, diag_calc, flatten])

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)

rotateX(angle)

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

rotateY(angle)

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

rotateZ(angle)

Update the self transformation(s) by adding a rotateZ 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.]] )
mInv=
array(
[[1. 0. 0. 0.]
[0. 1. 0. 0.]
[0. 0. 1. 0.]
[0. 0. 0. 1.]] )
__call__(c, diag_calc=False, flatten=False)#

Apply the transformations

Parameters:
cVector | Point | Normal | Ray | 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:
outVector | Point | Normal | Ray | BBox | 1-D array

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()#

Inverse the transformation(s) matrix

Parameters:
tTransform

The transformation(s) to be inversed

Returns:
outTransform

The inversed transformation(s)

is_identity()#
rotate(angle, axis, diag_calc=False)#

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 | 1-D ndarray

The angle(s) in degrees for the rotation(s)

axisVector | 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:
tTransform

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

rotateX(angle)#

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

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the x axis

Returns:
tTransform

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

rotateY(angle)#

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

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the y axis

Returns:
tTransform

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

rotateZ(angle)#

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

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the Z axis

Returns:
tTransform

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

scale(v)#

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

Parameters:
vVector

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

Returns:
tTransform

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

translate(v)#

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

Parameters:
vVector

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

Returns:
tTransform

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.]] )
mInv=
array(
[[ 1.  0.  0. -5.]
[ 0.  1.  0.  0.]
[ 0.  0.  1.  0.]
[ 0.  0.  0.  1.]] )
geoclide.transform.get_inverse_tf(t)#

Get the inverse transformation(s)

Parameters:
tTransform

The transformation(s) to be inversed

Returns:
outTransform

The inversed transformation(s)

geoclide.transform.get_rotateX_tf(angle)#

Get the rotateX transformation(s)

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the x axis

Returns:
tTransform

The rotateX transformation(s)

geoclide.transform.get_rotateY_tf(angle)#

Get the rotateY transformation(s)

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the y axis

Returns:
tTransform

The rotateY transformation(s)

geoclide.transform.get_rotateZ_tf(angle)#

Get the rotateZ transformation(s)

Parameters:
anglefloat | 1-D ndarray

The angle(s) in degrees for the rotation(s) around the Z axis

Returns:
tTransform

The rotateZ transformation(s)

geoclide.transform.get_rotate_tf(angle, axis, diag_calc=False)#

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 | 1-D ndarray

The angle(s) in degrees for the rotation(s)

axisVector | 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:
tTransform

The rotate transformation(s)

geoclide.transform.get_scale_tf(v)#

Get the scale transformation(s)

Parameters:
vVector

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

Returns:
tTransform

The scale transformation(s)

geoclide.transform.get_translate_tf(v)#

Get the translate transformation(s)

Parameters:
vVector

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

Returns:
tTransform

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.]] )
mInv=
array(
[[ 1.  0.  0. -5.]
[ 0.  1.  0. -0.]
[ 0.  0.  1. -0.]
[ 0.  0.  0.  1.]] )