CartToPol: Transform Cartesian to Polar/Spherical Coordinates and Vice...

Description Usage Arguments Details Value Author(s) Examples

View source: R/DescTools.r

Description

Transform cartesian into polar coordinates, resp. to spherical coordinates and vice versa.

Usage

1
2
3
4
5
CartToPol(x, y)
PolToCart(r, theta)

CartToSph(x, y, z, up = TRUE)
SphToCart(r, theta, phi, up = TRUE)

Arguments

x, y, z

vectors with the xy-coordianates to be transformed.

r

a vector with the radius of the points.

theta

a vector with the angle(s) of the points.

phi

a vector with the angle(s) of the points.

up

logical. If set to TRUE (default) theta is measured from x-y plane, else theta is measured from the z-axis.

Details

Angles are in radians, not degrees (i.e., a right angle is pi/2). Use DegToRad to convert, if you don't wanna do it by yourself.
All parameters are recycled if necessary.

Value

PolToCart returns a list of x and y coordinates of the points.
CartToPol returns a list of r for the radius and theta for the angles of the given points.

Author(s)

Andri Signorell <andri@signorell.net>, Christian W. Hoffmann <christian@echoffmann.ch>

Examples

1
2
3
4
5
6
7
8
9
CartToPol(x=1, y=1)
CartToPol(x=c(1,2,3), y=c(1,1,1))
CartToPol(x=c(1,2,3), y=1)


PolToCart(r=1, theta=pi/2)
PolToCart(r=c(1,2,3), theta=pi/2)

CartToSph(x=1, y=2, z=3)   # r=3.741657, theta=0.930274, phi=1.107149

AndriSignorell/DescTools documentation built on April 8, 2021, 5:51 a.m.