How to use the @mathigon/fermat.Segment 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 / polyhedra / functions.ts View on Github external
$geo1.on('add:path', function (p) {
    const match = checkPathMatches(p, [
      new Segment(model.b, model.d),
      new Segment(model.a, model.c)
    ]);

    if (match >= 0) {
      p.$el.setAttr('target', 'diagonal');
      if (match === 1) model.set('o', true);
      $step.score('diagonal');
      $geo1.setActiveTool('move');
    } else {
      $step.addHint('not-a-diagonal-1');
    }
  });
}
github mathigon / textbooks / content / graph-theory / components / graph.ts View on Github external
export function edgeToSegment(e: Edge) {
  const p1 = new Point(e.vertices[0].posn.x, e.vertices[0].posn.y);
  const p2 = new Point(e.vertices[1].posn.x, e.vertices[1].posn.y);
  return new Segment(p1, p2);
}
github mathigon / textbooks / content / graph-theory / components / sketch.ts View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points as Point[];
    let line1 = new Segment(points1[points1.length - 2],
        points1[points1.length - 1]);

    for (let i = 0; i < this.paths.length - 1; ++i) {
      let path2 = this.paths[i];
      let points2 = path2.points as Point[];
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Segment(points2[j], points2[j + 1]);
        let t = Segment.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', {point: t, paths: [path1, path2]});
          return;
        }
      }
    }
  }
}
github mathigon / textbooks / content / graph-theory / components / sketch.ts View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points as Point[];
    let line1 = new Segment(points1[points1.length - 2],
        points1[points1.length - 1]);

    for (let i = 0; i < this.paths.length - 1; ++i) {
      let path2 = this.paths[i];
      let points2 = path2.points as Point[];
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Segment(points2[j], points2[j + 1]);
        let t = Segment.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', {point: t, paths: [path1, path2]});
          return;
        }
      }
    }
  }
}
github mathigon / textbooks / content / chaos / components / simulation.ts View on Github external
draw($canvas: CanvasView, res = 2) {
    const tail = this.points.map(t => new Point(t[0] * res, t[1] * res));
    for (let i = 1; i < tail.length - 2; ++i) {
      const line = new Segment(tail[i], tail[i + 1]);
      const opacity = 0.5 * (1 - i / tail.length);
      $canvas.draw(line,
          {stroke: this.color, strokeWidth: this.width, opacity});
    }
  }
github mathigon / textbooks / content / polyhedra / functions.ts View on Github external
$geo1.on('add:path', function (p) {
    const match = checkPathMatches(p, [
      new Segment(model.b, model.d),
      new Segment(model.a, model.c)
    ]);

    if (match >= 0) {
      p.$el.setAttr('target', 'diagonal');
      if (match === 1) model.set('o', true);
      $step.score('diagonal');
      $geo1.setActiveTool('move');
    } else {
      $step.addHint('not-a-diagonal-1');
    }
  });
}
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
function addEdge(u: number, v: number) {
      if (u === v) return;
      let edge = new Segment(points[u], points[v]);
      for (let i = 0; i < edges.length; ++i) {
        const e2 = new Segment(points[edges[i][0]], points[edges[i][1]]);
        if (edge.equals(e2) || Segment.intersect(edge, e2)) return;
      }

      edges.push([u, v]);
    }