9.6. Transformations

These functions perform coordinate transformations as wrappers for other functions. Unlike mappers, these wrappers do not change the dimensionality of the wrapped functions.

class cherab.core.math.transform.cylindrical.CylindricalTransform

Converts Cartesian coordinates to cylindrical coordinates and calls a 3D function defined in cylindrical coordinates, f(r, \(\phi\), z).

The angular coordinate is given in radians.

Positive angular coordinate is measured counterclockwise from the xz plane.

Parameters:

function3d (Function3D) – The function to be mapped. Must be defined in the interval (\(-\pi\), \(\pi\)] on the angular axis.

>>> from math import sqrt, cos
>>> from cherab.core.math import CylindricalTransform
>>>
>>> def my_func(r, phi, z):
>>>     return r * cos(phi)
>>>
>>> f = CylindricalTransform(my_func)
>>>
>>> f(1, 0, 0)
1.0
>>> f(0.5 * sqrt(3), 0.5, 0)
0.8660254037844385
class cherab.core.math.transform.cylindrical.VectorCylindricalTransform

Converts Cartesian coordinates to cylindrical coordinates, calls a 3D vector function defined in cylindrical coordinates, f(r, \(\phi\), z), then converts the returned 3D vector to Cartesian coordinates.

The angular coordinate is given in radians.

Positive angular coordinate is measured counterclockwise from the xz plane.

Parameters:

function3d (VectorFunction3D) – The function to be mapped. Must be defined in the interval (\(-\pi\), \(\pi\)] on the angular axis.

>>> from math import sqrt, cos
>>> from raysect.core.math import Vector3D
>>> from cherab.core.math import VectorCylindricalTransform
>>>
>>> def my_vec_func(r, phi, z):
>>>     v = Vector3D(0, 1, 0)
>>>     v.length = r * abs(cos(phi))
>>>     return v
>>>
>>> f = VectorCylindricalTransform(my_vec_func)
>>>
>>> f(1, 0, 0)
Vector3D(0.0, 1.0, 0.0)
>>> f(1/sqrt(2), 1/sqrt(2), 0)
Vector3D(-0.5, 0.5, 0.0)
class cherab.core.math.transform.periodic.PeriodicTransform1D

Extends a periodic 1D function to an infinite 1D space.

Parameters:
  • function1d (Function1D) – The periodic 1D function defined in the [0, period) interval.

  • period (double) – The period of the function.

>>> from cherab.core.math import PeriodicTransform1D
>>>
>>> def f1(x):
>>>     return x
>>>
>>> f2 = PeriodicTransform1D(f1, 1.)
>>>
>>> f2(1.5)
0.5
>>> f2(-0.3)
0.7
class cherab.core.math.transform.periodic.PeriodicTransform2D

Extends a periodic 2D function to an infinite 2D space.

Set period_x/period_y to 0 if the function is not periodic along x/y axis.

Parameters:
  • function2d (Function2D) – The periodic 2D function defined in the ([0, period_x), [0, period_y)) intervals.

  • period_x (double) – The period of the function along x-axis. 0 if not periodic.

  • period_y (double) – The period of the function along y-axis. 0 if not periodic.

>>> from cherab.core.math import PeriodicTransform2D
>>>
>>> def f1(x, y):
>>>     return x * y
>>>
>>> f2 = PeriodicTransform2D(f1, 1., 1.)
>>>
>>> f2(1.5, 1.5)
0.25
>>> f2(-0.3, -1.3)
0.49
>>>
>>> f3 = PeriodicTransform2D(f1, 1., 0)
>>>
>>> f3(1.5, 1.5)
0.75
>>> f3(-0.3, -1.3)
-0.91
class cherab.core.math.transform.periodic.PeriodicTransform3D

Extends a periodic 3D function to an infinite 3D space.

Set period_x/period_y/period_z to 0 if the function is not periodic along x/y/z axis.

Parameters:
  • function3d (Function3D) – The periodic 3D function defined in the ([0, period_x), [0, period_y), [0, period_z)) intervals.

  • period_x (double) – The period of the function along x-axis. 0 if not periodic.

  • period_y (double) – The period of the function along y-axis. 0 if not periodic.

  • period_z (double) – The period of the function along z-axis. 0 if not periodic.

>>> from cherab.core.math import PeriodicTransform3D
>>>
>>> def f1(x, y, z):
>>>     return x * y * z
>>>
>>> f2 = PeriodicTransform3D(f1, 1., 1., 1.)
>>>
>>> f2(1.5, 1.5, 1.5)
0.125
>>> f2(-0.3, -1.3, -2.3)
0.343
>>>
>>> f3 = PeriodicTransform3D(f1, 0, 1., 0)
>>>
>>> f3(1.5, 1.5, 1.5)
1.125
>>> f3(-0.3, -1.3, -0.3)
0.063
class cherab.core.math.transform.periodic.VectorPeriodicTransform1D

Extends a periodic 1D vector function to an infinite 1D space.

Parameters:
  • function1d (VectorFunction1D) – The periodic 1D vector function defined in the [0, period) interval.

  • period (double) – The period of the function.

>>> from raysect.core.math import Vector3D
>>> from cherab.core.math import VectorPeriodicTransform1D
>>>
>>> def f1(x):
>>>     return Vector3D(x, 0, 0)
>>>
>>> f2 = VectorPeriodicTransform1D(f1, 1.)
>>>
>>> f2(1.5)
Vector3D(0.5, 0, 0)
>>> f2(-0.3)
Vector3D(0.7, 0, 0)
class cherab.core.math.transform.periodic.VectorPeriodicTransform2D

Extends a periodic 2D vector function to an infinite 2D space.

Set period_x/period_y to 0 if the function is not periodic along x/y axis.

Parameters:
  • function2d (VectorFunction2D) – The periodic 2D vector function defined in the ([0, period_x), [0, period_y)) intervals.

  • period_x (double) – The period of the function along x-axis. 0 if not periodic.

  • period_y (double) – The period of the function along y-axis. 0 if not periodic.

>>> from cherab.core.math import VectorPeriodicTransform2D
>>>
>>> def f1(x, y):
>>>     return Vector3D(x, y, 0)
>>>
>>> f2 = VectorPeriodicTransform2D(f1, 1., 1.)
>>>
>>> f2(1.5, 1.5)
Vector3D(0.5, 0.5, 0)
>>> f2(-0.3, -1.3)
Vector3D(0.7, 0.7, 0)
>>>
>>> f3 = VectorPeriodicTransform2D(f1, 1., 0)
>>>
>>> f3(1.5, 1.5)
Vector3D(0.5, 1.5, 0)
>>> f3(-0.3, -1.3)
Vector3D(0.7, -1.3, 0)
class cherab.core.math.transform.periodic.VectorPeriodicTransform3D

Extends a periodic 3D vector function to an infinite 3D space.

Set period_x/period_y/period_z to 0 if the function is not periodic along x/y/z axis.

Parameters:
  • function3d (VectorFunction3D) – The periodic 3D vector function defined in the ([0, period_x), [0, period_y), [0, period_z)) intervals.

  • period_x (double) – The period of the function along x-axis. 0 if not periodic.

  • period_y (double) – The period of the function along y-axis. 0 if not periodic.

  • period_z (double) – The period of the function along z-axis. 0 if not periodic.

>>> from cherab.core.math import PeriodicTransform3D
>>>
>>> def f1(x, y, z):
>>>     return Vector3D(x, y, z)
>>>
>>> f2 = VectorPeriodicTransform3D(f1, 1., 1., 1.)
>>>
>>> f2(1.5, 1.5, 1.5)
Vector3D(0.5, 0.5, 0.5)
>>> f2(-0.3, -1.3, -2.3)
Vector3D(0.7, 0.7, 0.7)
>>>
>>> f3 = VectorPeriodicTransform3D(f1, 0, 1., 0)
>>>
>>> f3(1.5, 0.5, 1.5)
Vector3D(1.5, 0.5, 1.5)