deck.gl icon indicating copy to clipboard operation
deck.gl copied to clipboard

Access to arc parametric parameters?

Open chrbradley opened this issue 6 years ago • 1 comments

Is there a way to access the point on an arc relative to the arc length?

Everything I see returned in the hover info object is in 2d space: either pixel (x, y) or map (lng, lat). I need to access where I am relative to origin, starting at 0?, and destination, ending at either 1 if length is normalized or a value of the arc length.

Is this possible?

chrbradley avatar Sep 28 '20 14:09 chrbradley

The paraboloid is calculated in the common space. You can estimate the ratio along these lines:

function distance(p1, p2) {
  return Math.sqrt(
    (p1[0] - p2[0]) ** 2 +
    (p1[1] - p2[1]) ** 2 +
    (p1[2] - p2[2]) ** 2);
}

function onHover({layer, object, coordinate}) {
  const {viewport} = layer.context;
  const source = viewport.projectPosition(object.sourcePosition);
  const target = viewport.projectPosition(object.targetPosition);
  const current = viewport.projectPosition(coordinate);

  return distance(current, source) / distance(target, source);
}

Pessimistress avatar Sep 28 '20 15:09 Pessimistress