source: node_modules/d3-geo/src/cartesian.js@ e4c61dd

Last change on this file since e4c61dd was e4c61dd, checked in by istevanoska <ilinastevanoska@…>, 6 months ago

Prototype 1.1

  • Property mode set to 100644
File size: 932 bytes
Line 
1import {asin, atan2, cos, sin, sqrt} from "./math.js";
2
3export function spherical(cartesian) {
4 return [atan2(cartesian[1], cartesian[0]), asin(cartesian[2])];
5}
6
7export 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
12export function cartesianDot(a, b) {
13 return a[0] * b[0] + a[1] * b[1] + a[2] * b[2];
14}
15
16export 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
21export function cartesianAddInPlace(a, b) {
22 a[0] += b[0], a[1] += b[1], a[2] += b[2];
23}
24
25export function cartesianScale(vector, k) {
26 return [vector[0] * k, vector[1] * k, vector[2] * k];
27}
28
29// TODO return d
30export 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}
Note: See TracBrowser for help on using the repository browser.