Overview
Developer Guide
@math.gl/culling
@math.gl/geospatial
@math.gl/sun
@math.gl/web-mercator
API Reference
@math.gl/culling
@math.gl/geospatial
@math.gl/polygon
@math.gl/sun
@math.gl/web-mercator
Concepts

# SphericalCoordinates (Experimental)

Note this class is considered experimental and must be imported from the `experimental` namespace. This documentation is incomplete and may be incorrect

``class SphericalCoordinates``

• The poles (phi) are at the positive and negative y axis.
• The equator starts at positive z.

Conversion from spherical to Cartesian (rectilinear) coordinates:

$\begin{array}{}x=\rho \mathrm{cos}\theta \phi \\ y=\rho \mathrm{cos}\theta \phi \\ z=\rho \mathrm{cos}\theta \phi \end{array}$

Conversion from Cartesian (rectilinear) to spherical coordinates:

$\begin{array}{}r=\sqrt{{x}^{2}+{y}^{2}+{z}^{2}}\\ \theta =arccos\frac{z}{r}\\ \phi =arctan\frac{y}{x}\end{array}$

Ranges

$\begin{array}{}r\ge 0\\ \theta \ge 0\\ \phi \ge 0\end{array}$

## Usage

``import {_SphericalCoordinates as SphericalCoordinates} from '@math.gl/core';``

Creating a SphericalCoordinates object

``````const spherical = new SphericalCoordinates({phi: 0, theta: 0});
const spherical = new SphericalCoordinates({pitch: 0, bearing: 0});
const spherical = new SphericalCoordinates({longitude: 0, latitude: 0});``````

Converting to a direction `Vector3`

``const direction = new SphericalCoordinates().toVector3();``

Manipulating spherical coordinates;

``````spherical.bearing += 3; // Add three degrees to bearing
spherical.theta -= Math.PI / 4; // Subtract PI/4 radians from theta.``````

## Members

// Standard spherical coordinates

### altitude

// lnglatZ coordinates

## Methods

### constructor

``````SphericalCoordinates({phi = 0, theta = 0, radius = 1.0})
SphericalCoordinates({bearing = 0, pitch = 0, altitude = 1.0})
SphericalCoordinates({longitude = 0, latitude = 0, z = 1.0})``````
• phi=0 - rotation around X (latitude)
• theta=0 - rotation around Y (longitude)
• radius=1 - Distance from center

### set

`set(radius, phi, theta)`

### clone

`clone()`

### copy

`copy(other)`

### fromLngLatZ

`fromLngLatZ([lng, lat, z])`

### fromVector3

`fromVector3(v)`

### makeSafe

`makeSafe()`

// restrict phi to be betwee EPS and PI-EPS

### toVector3

`toVector3(center = [0, 0, 0])`

// TODO - add parameter for orientation of sphere? up vector etc?

## Remarks

• Inspired by THREE.js `THREE.Spherical` class