# 3D Coordinate Conversion (G Dataflow)

Last Modified: January 12, 2018

Converts coordinates between the Cartesian, cylindrical, and spherical coordinate systems.

## axis 1

X-coordinate in a Cartesian coordinate system, rho-coordinate in a cylindrical coordinate system, or radius-coordinate in a spherical coordinate system.

This input accepts the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## axis 2

Y-coordinate in a Cartesian coordinate system, theta-coordinate in a cylindrical coordinate system, or theta-coordinate in a spherical coordinate system.

This input accepts the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## axis 3

Z-coordinate in a Cartesian coordinate system, z-coordinate in a cylindrical coordinate system, or phi-coordinate in a spherical coordinate system.

This input accepts the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## conversion type

Type of conversion to perform.

Name Value Description
Cartesian to Spherical 0 Converts a coordinate from the Cartesian coordinate system to the spherical coordinate system.
Spherical to Cartesian 1 Converts a coordinate from the spherical coordinate system to the Cartesian coordinate system.
Cartesian to Cylindrical 2 Converts a coordinate from the Cartesian coordinate system to the cylindrical coordinate system.
Cylindrical to Cartesian 3 Converts a coordinate from the cylindrical coordinate system to the Cartesian coordinate system.
Spherical to Cylindrical 4 Converts a coordinate from the spherical coordinate system to the cylindrical coordinate system.
Cylindrical to Spherical 5 Converts a coordinate from the cylindrical coordinate system to the spherical coordinate system.

Default: Cartesian to Spherical

## error in

Error conditions that occur before this node runs.

The node responds to this input according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

Default: No error

## converted axis 1

Coordinate on the first axis in the new coordinate system.

This output can return the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## converted axis 2

Coordinate on the second axis in the new coordinate system.

This output can return the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## converted axis 3

Coordinate on the third axis in the new coordinate system.

This output can return the following data types:

• Double-precision, floating-point number
• 1D array of double-precision, floating-point numbers

## error out

Error information.

The node produces this output according to standard error behavior.

Standard Error Behavior

Many nodes provide an error in input and an error out output so that the node can respond to and communicate errors that occur while code is running. The value of error in specifies whether an error occurred before the node runs. Most nodes respond to values of error in in a standard, predictable way.

error in does not contain an error error in contains an error
If no error occurred before the node runs, the node begins execution normally.

If no error occurs while the node runs, it returns no error. If an error does occur while the node runs, it returns that error information as error out.

If an error occurred before the node runs, the node does not execute. Instead, it returns the error in value as error out.

## Comparing the Cartesian, Cylindrical, and Spherical Coordinate Systems

The Cartesian, or rectangular, coordinate system is the most widely used coordinate system. The cylindrical coordinate system is a generalization of two-dimensional polar coordinates to three dimensions. The spherical coordinate system is a system of curvilinear coordinates that is natural for describing positions on a sphere.

The following figure show a point P in different three-dimensional coordinate systems.

## Algorithm for Converting Between Cartesian Coordinates and Cylindrical Coordinates

The following equations describe the relationship between a Cartesian coordinate (x,y,z) and a cylindrical coordinate (ρ,θ,z):

$\left\{\begin{array}{c}x=\rho \cdot \mathrm{cos}\theta \\ y=\rho \cdot \mathrm{sin}\theta \\ z=z\end{array}$

where

• ρ is the radial coordinate
• θ (-π < θ ≤ π) is the azimuthal coordinate

## Algorithm for Converting Between Cartesian Coordinates and Spherical Coordinates

The following equations describe the relationship between a Cartesian coordinate (x,y,z) and a spherical coordinate (r,θ,φ):

$\left\{\begin{array}{c}x=r\cdot \mathrm{sin}\theta \cdot \mathrm{cos}\phi \\ y=r\cdot \mathrm{sin}\theta \cdot \mathrm{sin}\phi \\ z=r\cdot \mathrm{cos}\theta \end{array}$

where

• r is the distance from point P to the origin
• θ (-π < θ ≤ π) is the polar angle in the spherical coordinate system
• φ (0 ≤ φ ≤ π) is azimuthal angle in the spherical coordinate system

## Algorithm for Converting Between Spherical Coordinates and Cylindrical Coordinates

The following equations describe the relationship between a spherical coordinate (r,θ,φ) and a cylindrical coordinate (ρ,θ,z):

$\left\{\begin{array}{c}r=\sqrt{{\rho }^{2}+{z}^{2}}\\ {\theta }_{\mathrm{spherical}}=\mathrm{atan2}\left(\rho ,\text{\hspace{0.17em}}z\right)\\ \phi ={\theta }_{\mathrm{cylindrical}}\end{array}$

where

• ρ is the radial distance
• z is the height
• θspherical (-π < θπ) is the polar angle in a spherical coordinate system
• θcylindrical (-π < θπ) is the azimuthal angle in a cylindrical coordinate system

Where This Node Can Run:

Desktop OS: Windows

FPGA: Not supported

Web Server: Not supported in VIs that run in a web application