| 1 | import {asin, atan2, cos, sin, sqrt} from "./math.js";
|
|---|
| 2 |
|
|---|
| 3 | export function spherical(cartesian) {
|
|---|
| 4 | return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
|
|---|
| 5 | }
|
|---|
| 6 |
|
|---|
| 7 | export function cartesian(spherical) {
|
|---|
| 8 | var lambda = spherical[0], phi = spherical[1], cosPhi = cos(phi);
|
|---|
| 9 | return [cosPhi * cos(lambda), cosPhi * sin(lambda), sin(phi)];
|
|---|
| 10 | }
|
|---|
| 11 |
|
|---|
| 12 | export function cartesianDot(a, b) {
|
|---|
| 13 | return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
|
|---|
| 14 | }
|
|---|
| 15 |
|
|---|
| 16 | export function cartesianCross(a, b) {
|
|---|
| 17 | return [a[1] * b[2] - a[2] * b[1], a[2] * b[0] - a[0] * b[2], a[0] * b[1] - a[1] * b[0]];
|
|---|
| 18 | }
|
|---|
| 19 |
|
|---|
| 20 | // TODO return a
|
|---|
| 21 | export function cartesianAddInPlace(a, b) {
|
|---|
| 22 | a[0] += b[0], a[1] += b[1], a[2] += b[2];
|
|---|
| 23 | }
|
|---|
| 24 |
|
|---|
| 25 | export function cartesianScale(vector, k) {
|
|---|
| 26 | return [vector[0] * k, vector[1] * k, vector[2] * k];
|
|---|
| 27 | }
|
|---|
| 28 |
|
|---|
| 29 | // TODO return d
|
|---|
| 30 | export function cartesianNormalizeInPlace(d) {
|
|---|
| 31 | var l = sqrt(d[0] * d[0] + d[1] * d[1] + d[2] * d[2]);
|
|---|
| 32 | d[0] /= l, d[1] /= l, d[2] /= l;
|
|---|
| 33 | }
|
|---|