coords.Coords.cylindrical_to_cartesian#

Coords.cylindrical_to_cartesian(dir=(0, 1, 2), scale=(1.0, 1.0, 1.0), angle_spec=0.017453292519943295)#

Convert from cylindrical to cartesian coordinates.

A cylindrical coordinate system is defined by a longitudinal axis (z) and a radial axis (r). The cylindrical coordinates of a point are:

  • r: the radial distance from the z-axis,

  • theta: the circumferential angle measured positively around the z-axis starting from zero at the (r-z) halfplane,

  • z: the axial distance along the z-axis,

This function interpretes the 3 coordinates of the points as (r,theta,z) values and computes the corresponding global cartesian coordinates (x,y,z).

Parameters#

dir: tuple of 3 ints, optional

If provided, it is a permutation of (0,1,2) and specifies which of the current coordinates are interpreted as resp. distance (r), angle (theta) and height (z). Default order is (r,theta,z). Beware that if the permutation is not conserving the order of the axes, a left-handed system results, and the Coords will appear mirrored in the right-handed systems exclusively used by HelloTriangle.

scale: tuple of 3 floats, optional

Scaling factors that are applied on the values prior to make the conversion from cylindrical to cartesian coordinates. These factors are always given in the order (r,theta,z), irrespective of the permutation by dir.

angle_spec: float, at.DEG or RAD, optional

Multiplication factor for angle coordinates. The default (at.DEG) interpretes the angle in degrees. Use RAD to specify the angle in radians.

Returns#

Coords

The global (cartesian) coordinates of the points that were specified with cylindrical coordinates as input.

Notes#

The scaling can also be applied independently prior to transforming. X.cylindrical_to_cartesian(scale=s) is equivalent with X.scale(s).cylindrical_to_cartesian(). The scale option is provided here because in many cases you need at least to scale the theta direction to have proper angle values.

See Also#

Examples#

We want to create six points on a circle with radius 2. We start by creating the points in cylindrical coordinates with unit distances.

>>> X = Coords([[1.0, 0.0, 0.0],
...             [1.0, 1.0, 0.0],
...             [1.0, 2.0, 0.0],
...             [1.0, 3.0, 0.0],
...             [1.0, 4.0, 0.0],
...             [1.0, 5.0, 0.0]])

Remember these are (r,theta,z) coordinates of the points. So we will scale the r-direction with 2 (the target radius) and the angular direction theta with 360/6 = 60. Then we get the cartesian coordinates of the points from

>>> Y = X.cylindrical_to_cartesian(scale=(2.,60.,1.))
>>> print(Y)
[[ 2.      0.      0.    ]
 [ 1.      1.7321  0.    ]
 [-1.      1.7321  0.    ]
 [-2.     -0.      0.    ]
 [-1.     -1.7321  0.    ]
 [ 1.     -1.7321  0.    ]]

Going back to cylindrical coordinates yields

>>> print(Y.cartesian_to_cylindrical())
[[   2.    0.    0.]
 [   2.   60.    0.]
 [   2.  120.    0.]
 [   2. -180.    0.]
 [   2. -120.    0.]
 [   2.  -60.    0.]]

This differs from the original input X because of the scaling factors, and the wrapping around angles are reported in the range [-180,180].