Spherical:
Filter:
MathLib/Classes (extension) | Math | Libraries > MathLib > Cartesian &c.

Spherical
ExtensionExtension

Spherical coordinates

Description

Represents spherical coordinates.

Part of MathLib, a diverse library of mathematical functions.

Class Methods

.new

Create a new spherical coordinate with the given radius, rho, and angles in radians, theta and phi.

Arguments:

rho

radius

theta

azimuth angle

phi

elevation angle

Instance Methods

Accessing

.rho

Get or set the rho coordinate value.

.theta

Get or set the theta coordinate value.

.phi

Get or set the phi coordinate value.

Testing

==

Answers a Boolean whether the receiver equals the argument.

.hash

Returns a hash value for the receiver.

Math

+

-

*

/

The math operations of addition, subtraction, multiplication and division are accomplished by first converting to cartesian coordinates, then answering to spherical coordinates.

.scale

Scale the radius by some value.

.rotate

Rotation about the origin in the XY plane by the angle given in radians.

Discussion:

Positive values rotate from +X towards +Y

.tilt

Rotation about the origin in the YZ plane by the angle given in radians.

Discussion:

Positive values rotate from +Y towards +Z

.tumble

Rotation about the origin in the XZ plane by the angle given in radians.

Discussion:

Positive values rotate from +X towards +Z

.rotateXY

Rotation about the origin in the XY plane by the angle given in radians.

Discussion:

A synonym for rotate.

.rotateYZ

Rotation about the origin in the YZ plane by the angle given in radians.

Discussion:

A synonym for tilt.

.rotateXZ

Rotation about the origin in the XZ plane by the angle given in radians.

Discussion:

A synonym for tumble.

.mirrorX

Mirror x, reflecting across the YZ plane.

.mirrorY

Mirror y, reflecting across the XZ plane.

.mirrorZ

Mirror z, reflecting across the XY plane.

.mirrorO

Mirror across the origin.

.neg

Rotate theta by pi and negate phi.

Discussion:

This operation is equivalent to negating rho, and is a synonym for mirrorO.

Conversion

.magnitude

Answer the radius.

.angle

Answer the azimuth angle, theta, in radians.

.phase

Answer the azimuth angle, theta, in radians.

.angles

Answer the azimuth and elevation angles, theta and phi, in radians.

Returns:

[ theta, phi ]

.phases

Answer the azimuth and elevation angles, theta and phi, in radians.

Returns:

[ theta, phi ]

.x

Answer the cartesian coordinate x of the receiver.

.y

Answer the cartesian coordinate y of the receiver.

.z

Answer the cartesian coordinate z of the receiver.

.real

Answer the cartesian coordinate x of the receiver.

.imag

Answer the cartesian coordinate y of the receiver.

.asSpherical

Returns the receiver.

.asPolar

Convert to Polar, discarding z.

.asComplex

Answers a Complex with x as the real part and y as the imaginary part, discarding z.

.asPoint

Convert to Point, discarding z.

.asCartesian

Convert to Cartesian.

Authors

Joseph Anderson, 2011.