How to use the @mathigon/fermat.Point.distance function in @mathigon/fermat

To help you get started, we’ve selected a few @mathigon/fermat examples, based on popular ways it is used in public projects.

Secure your code as it's written. Use Snyk Code to scan source code in minutes - no build needed - and fix issues immediately.

github mathigon / textbooks / content / graph-theory / functions.js View on Github external
$bridge.on('pointerleave', (e) => {
        if (!map.drawing) return;
        let out = svgPointerPosn(e, $svg);
        if (Point.distance(enter || out, out) < 40) {
          crossed = false;
        } else {
          $bridge.addClass('green');
          totalCrossed += 1;
          if (totalCrossed === $bridges.length) {
            $solveds[i].enter();
            $skip.exit('pop');
            $section.score('bridge-' + i);
            success = true;
          }
        }
      });
github mathigon / textbooks / content / transformations-and-symmetry / functions.js View on Github external
function expandSegment($geopad, [e1, e2], line) {
  let swap = Point.distance(e1.val, line.p1) > Point.distance(e2.val, line.p1);
  $geopad.animatePoint(swap ? e2.name : e1.name, line.p1);
  $geopad.animatePoint(swap ? e1.name : e2.name, line.p2);
}
github mathigon / textbooks / content / polygons / functions.ts View on Github external
function round(a: Point, b: Point) {
  return Math.round(Point.distance(a, b) / 25) / 2;
}
github mathigon / textbooks / content / triangles-and-trigonometry / functions.js View on Github external
  function round(a, b) { return Math.round(Point.distance(a, b) / 25) / 2; }
  $step.model.set('roundD', round);
github mathigon / textbooks / content / chaos / components / pendulum.js View on Github external
reset() {
    this.clearTail();

    const q1 = this.model[this.points[0]];
    const q2 = this.model[this.points[1]];

    this.lengths = [Point.distance(this.center, q1), Point.distance(q1, q2)];
    this.state = [PI2 - q1.angle(this.center), PI2 - q2.angle(q1), 0, 0];
  }
}
github mathigon / textbooks / content / transformations / functions.ts View on Github external
function expandSegment($geopad: Geopad, [e1, e2]: GeoPoint[], line: Line) {
  let swap = Point.distance(e1.val!, line.p1) > Point.distance(e2.val!, line.p1);
  $geopad.animatePoint(swap ? e2.name : e1.name, line.p1);
  $geopad.animatePoint(swap ? e1.name : e2.name, line.p2);
}
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
function redraw() {
    if (points.length < 2) return $path.points = [];

    let matrix = repeat2D(0, points.length, points.length);
    for (let i = 0; i < points.length; ++i) {
      for (let j = 0; j < i; ++j) {
        matrix[i][j] = matrix[j][i] = Point.distance(points[i], points[j]);
      }
    }
    const tsm = travellingSalesman(matrix);
    $path.points = tsm.path!.map(i => points[i]);
  }
github mathigon / boost.js / src / events.ts View on Github external
$el.on('pointerup', (e: ScreenEvent) => {
    if (!start) return;
    const end = pointerPosition(e);
    if (Point.distance(start, end) < 6) $el.trigger('tap', e);
    start = undefined;
  });
github mathigon / textbooks / triangles-and-trigonometry / functions.js View on Github external
  function round(a, b) { return Math.round(Point.distance(a, b) / 25) / 2; }
  $step.model.set('roundD', round);