Table of Contents
Chevron DownDeveloper Guide
Chevron DownAPI Reference

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

See also Wikipedia, Wolfram MathWorld.

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

Conversion from spherical to Cartesian (rectilinear) coordinates:

x=ρcosθφ y=ρcosθφ z=ρcosθφ

Conversion from Cartesian (rectilinear) to spherical coordinates:

r= x2+ y2+ z2 θ=arccoszr φ=arctanyx

Ranges

r0 θ0 φ0

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

phi

theta

radius

altitude

// lnglatZ coordinates

lng

lat

z

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?

check()

Remarks

  • Inspired by THREE.js THREE.Spherical class