Skip to content
Permalink
Browse files

direct formula for the stereographic (thanks, @jrus)

  • Loading branch information...
Fil committed Aug 11, 2019
1 parent 226a14a commit 4b9aee7f0bfd84cdc962f97e4dc1d2b9e001f926
Showing with 13 additions and 6 deletions.
  1. +13 −6 src/delaunay.js
@@ -1,25 +1,27 @@
//
// (c) 2018 Philippe Riviere
// (c) 2019 Philippe Riviere
//
// https://github.com/Fil/
//
// This software is distributed under the terms of the MIT License

import { Delaunay } from "d3-delaunay";
import { geoRotation, geoStereographic } from "d3-geo";
import { geoRotation, geoProjection } from "d3-geo";
import { extent } from "d3-array";
import {
asin,
atan2,
cos,
degrees,
halfPi,
max,
min,
pi,
radians,
sign,
sin,
sqrt
sqrt,
tan
} from "./math.js";
import {
cartesianNormalize as normalize,
@@ -110,6 +112,11 @@ function geo_find(neighbors, points) {
};
}

function stereo(lambda, phi) {
var r = tan(0.5 * (halfPi + phi));
return [cos(lambda) * r, -sin(lambda) * r];
}

function geo_delaunay_from(points) {
if (points.length < 2) return {};

@@ -118,17 +125,17 @@ function geo_delaunay_from(points) {
while (isNaN(points[pivot][0]+points[pivot][1]) && pivot++ < points.length) {}

const r = geoRotation(points[pivot]),
projection = geoStereographic()
projection = geoProjection(stereo)
.translate([0, 0])
.scale(1)
.rotate(r.invert([180, 0]));
.rotate(r.invert([0, 90]));
points = points.map(projection);

const zeros = [];
let max2 = 1;
for (let i = 0, n = points.length; i < n; i++) {
let m = points[i][0] ** 2 + points[i][1] ** 2;
if (!isFinite(m)) zeros.push(i);
if (m > 1e32) zeros.push(i);
else if (m > max2) max2 = m;
}

3 comments on commit 4b9aee7

@jrus

This comment has been minimized.

Copy link

replied Aug 12, 2019

How did this compare to the previous version in practice? Any concrete improvement at edge cases, etc.?

@Fil

This comment has been minimized.

Copy link
Owner Author

replied Aug 13, 2019

@Fil

This comment has been minimized.

Copy link
Owner Author

replied Aug 28, 2019

After extensive tests I realized that my code was wrong, and I wasn't able to fix it… went back to the d3 projection. We need to rotate the data so that we project the pivot point to Infinity. Here the tests were okay but the triangles, for instance, were broken (which means I need to add specific tests).

Please sign in to comment.
You can’t perform that action at this time.