Pomax / are-we-flying

Writing auto-pilots in JavaScript for MSFS
40 stars 2 forks source link

update flight path intercept code #20

Closed Pomax closed 8 months ago

Pomax commented 10 months ago

Stagger points along the flight path, past a transition, and (lerp-)target those (moving to next point(s) as we pass them), so that we get (back) on the flight path earlier.

Pomax commented 10 months ago

E.g. image

Pomax commented 10 months ago

This should hopefully avoid situations like this:

image

Pomax commented 9 months ago

See the socketless extras dir, and the Processing flightpath sketch.

Pomax commented 9 months ago

More specifically, see the new getLineCircleIntersection function in `utils.js:

function getLineCircleIntersection(
  { x, y },
  { x: x1, y: y1 },
  { x: x2, y: y2 },
  r
) {
  // work relative to (0,0)
  x1 -= x;
  y1 -= y;
  x2 -= x;
  y2 -= y;
  const dy = y2 - y1;
  const dx = x2 - x1;
  const m = (dx * dx + dy * dy) ** 0.5;
  const A = x1 * y2 - x2 * y1;
  const d = (r * r * m * m - A * A) ** 0.5;
  return {
    x: x + (d * dx + A * dy) / (m * m),
    y: y + (d * dy - A * dx) / (m * m),
  };
}
Pomax commented 8 months ago

this will be covered by the new tutorial, and has been implemented in the improved branch