transform#

_TUPLE2AXES

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object's (key, value) pairs dict(iterable) -> new dictionary initialized as if via: d = {} for k, v in iterable: d[k] = v dict(**kwargs) -> new dictionary initialized with the name=value pairs in the keyword argument list. For example: dict(one=1, two=2).

euler_matrix(ai, aj, ak[, axes])

Return homogeneous rotation matrix from Euler angles and axis sequence.

sphere2cart(r, theta, phi)

Spherical to Cartesian coordinates.

cart2sphere(x, y, z)

Return angles for Cartesian 3D coordinates x, y, and z.

translate(translation)

Return transformation matrix for translation array.

rotate(quat)

Return transformation matrix for rotation quaternion.

scale(scales)

Return transformation matrix for scales array.

apply_transformation(vertices, transformation)

Multiplying transformation matrix with vertices

transform_from_matrix(matrix)

Returns translation, rotation and scale arrays from transformation matrix.

_TUPLE2AXES#

fury.transform._TUPLE2AXES()#

dict() -> new empty dictionary dict(mapping) -> new dictionary initialized from a mapping object’s

(key, value) pairs

dict(iterable) -> new dictionary initialized as if via:

d = {} for k, v in iterable:

d[k] = v

dict(**kwargs) -> new dictionary initialized with the name=value pairs

in the keyword argument list. For example: dict(one=1, two=2)

euler_matrix#

fury.transform.euler_matrix(ai, aj, ak, axes='sxyz')[source]#

Return homogeneous rotation matrix from Euler angles and axis sequence.

Code modified from the work of Christoph Gohlke link provided here http://www.lfd.uci.edu/~gohlke/code/transformations.py.html

Parameters:
  • ai (Euler's roll, pitch and yaw angles) –

  • aj (Euler's roll, pitch and yaw angles) –

  • ak (Euler's roll, pitch and yaw angles) –

  • axes (One of 24 axis sequences as string or encoded tuple) –

Returns:

  • matrix (ndarray (4, 4))

  • Code modified from the work of Christoph Gohlke link provided here

  • http (//www.lfd.uci.edu/~gohlke/code/transformations.py.html)

Examples

>>> import numpy
>>> R = euler_matrix(1, 2, 3, 'syxz')
>>> numpy.allclose(numpy.sum(R[0]), -1.34786452)
True
>>> R = euler_matrix(1, 2, 3, (0, 1, 0, 1))
>>> numpy.allclose(numpy.sum(R[0]), -0.383436184)
True
>>> ai, aj, ak = (4.0*math.pi) * (numpy.random.random(3) - 0.5)
>>> for axes in _AXES2TUPLE.keys():
...    _ = euler_matrix(ai, aj, ak, axes)
>>> for axes in _TUPLE2AXES.keys():
...    _ = euler_matrix(ai, aj, ak, axes)

sphere2cart#

fury.transform.sphere2cart(r, theta, phi)[source]#

Spherical to Cartesian coordinates.

This is the standard physics convention where theta is the inclination (polar) angle, and phi is the azimuth angle.

Imagine a sphere with center (0,0,0). Orient it with the z axis running south-north, the y axis running west-east and the x axis from posterior to anterior. theta (the inclination angle) is the angle to rotate from the z-axis (the zenith) around the y-axis, towards the x axis. Thus the rotation is counter-clockwise from the point of view of positive y. phi (azimuth) gives the angle of rotation around the z-axis towards the y axis. The rotation is counter-clockwise from the point of view of positive z.

Equivalently, given a point P on the sphere, with coordinates x, y, z, theta is the angle between P and the z-axis, and phi is the angle between the projection of P onto the XY plane, and the X axis.

Geographical nomenclature designates theta as ‘co-latitude’, and phi as ‘longitude’

Parameters:
  • r (array_like) – radius

  • theta (array_like) – inclination or polar angle

  • phi (array_like) – azimuth angle

Returns:

  • x (array) – x coordinate(s) in Cartesian space

  • y (array) – y coordinate(s) in Cartesian space

  • z (array) – z coordinate

Notes

See these pages:

for excellent discussion of the many different conventions possible. Here we use the physics conventions, used in the wikipedia page.

Derivations of the formulae are simple. Consider a vector x, y, z of length r (norm of x, y, z). The inclination angle (theta) can be found from: cos(theta) == z / r -> z == r * cos(theta). This gives the hypotenuse of the projection onto the XY plane, which we will call Q. Q == r*sin(theta). Now x / Q == cos(phi) -> x == r * sin(theta) * cos(phi) and so on.

We have deliberately named this function sphere2cart rather than sph2cart to distinguish it from the Matlab function of that name, because the Matlab function uses an unusual convention for the angles that we did not want to replicate. The Matlab function is trivial to implement with the formulae given in the Matlab help.

cart2sphere#

fury.transform.cart2sphere(x, y, z)[source]#

Return angles for Cartesian 3D coordinates x, y, and z.

See doc for sphere2cart for angle conventions and derivation of the formulae.

$0lethetamathrm{(theta)}lepi$ and $-pilephimathrm{(phi)}lepi$

Parameters:
  • x (array_like) – x coordinate in Cartesian space

  • y (array_like) – y coordinate in Cartesian space

  • z (array_like) – z coordinate

Returns:

  • r (array) – radius

  • theta (array) – inclination (polar) angle

  • phi (array) – azimuth angle

translate#

fury.transform.translate(translation)[source]#

Return transformation matrix for translation array.

Parameters:

translation (ndarray) – translation in x, y and z directions.

Returns:

translation – Numpy array of shape 4,4 containing translation parameter in the last column of the matrix.

Return type:

ndarray (4, 4)

Examples

>>> import numpy as np
>>> tran = np.array([0.3, 0.2, 0.25])
>>> transform = translate(tran)
>>> transform
>>> [[1.  0.  0.  0.3 ]
     [0.  1.  0.  0.2 ]
     [0.  0.  1.  0.25]
     [0.  0.  0.  1.  ]]

rotate#

fury.transform.rotate(quat)[source]#

Return transformation matrix for rotation quaternion.

Parameters:

quat (ndarray (4, )) – rotation quaternion.

Returns:

rotation_mat – Transformation matrix of shape (4, 4) to rotate a vector.

Return type:

ndarray (4, 4)

Examples

>>> import numpy as np
>>> quat = np.array([0.259, 0.0, 0.0, 0.966])
>>> rotation = rotate(quat)
>>> rotation
>>> [[1.  0.      0.     0.]
     [0.  0.866  -0.5    0.]
     [0.  0.5     0.866  0.]
     [0.  0.      0.     1.]]

scale#

fury.transform.scale(scales)[source]#

Return transformation matrix for scales array.

Parameters:

scales (ndarray) – scales in x, y and z directions.

Returns:

scale_mat – Numpy array of shape 4,4 containing elements of scale matrix along the diagonal.

Return type:

ndarray (4, 4)

Examples

>>> import numpy as np
>>> scales = np.array([2.0, 1.0, 0.5])
>>> transform = scale(scales)
>>> transform
>>> [[2.  0.  0.   0.]
     [0.  1.  0.   0.]
     [0.  0.  0.5  0.]
     [0.  0.  0.   1.]]

apply_transformation#

fury.transform.apply_transformation(vertices, transformation)[source]#

Multiplying transformation matrix with vertices

Parameters:
  • vertices (ndarray (n, 3)) – vertices of the mesh

  • transformation (ndarray (4, 4)) – transformation matrix

Returns:

vertices – transformed vertices of the mesh

Return type:

ndarray (n, 3)

transform_from_matrix#

fury.transform.transform_from_matrix(matrix)[source]#

Returns translation, rotation and scale arrays from transformation matrix.

Parameters:

matrix (ndarray (4, 4)) – the transformation matrix of shape 4*4

Returns:

  • translate (ndarray (3, )) – translation component from the transformation matrix

  • rotate (ndarray (4, )) – rotation component from the transformation matrix

  • scale (ndarray (3, )) – scale component from the transformation matrix.