Learn R Programming

HiveR (version 0.2-16)

cart2sph: Convert spherical to Cartesian coordinates or vice versa

Description

These functions interconvert coordinate systems.

Usage

cart2sph(df)
sph2cart(df)

Arguments

df
For cart2sph, a data frame with columns named x, y and z containing the Cartesian coordinates to be converted. For sph2cart, a data frame with columns named r, theta and phi with the radius and angles (in spherical coordinates)

Value

  • A data frame with named columns containing the converted coordinates.

References

http://academic.depauw.edu/~hanson/HiveR/HiveR.html

Examples

Run this code
df.cart1 <- data.frame(x = rnorm(10), y = rnorm(10), z = rnorm(10))
df.sph <- cart2sph(df.cart1)
str(df.sph)
df.cart2 <- sph2cart(df.sph)
all.equal(df.cart1, df.cart2)

Run the code above in your browser using DataLab