How to use the @mathigon/fermat.Segment.intersect 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
$step.onScore('points', () => {
    if (points.length < 4) points = [
      $geopad.drawMovablePoint(new Point(50, 40)),
      $geopad.drawMovablePoint(new Point(70, 250)),
      $geopad.drawMovablePoint(new Point(220, 240)),
      $geopad.drawMovablePoint(new Point(260, 90))
    ];

    $geopad.setActiveTool('move');

    const [a, b, c, d] = points.map(p => p.val);
    if (Segment.intersect(new Segment(a!, b!), new Segment(c!, d!))) {
      points = [points[0], points[2], points[1], points[3]];
    } else if (Segment.intersect(new Segment(a!, d!), new Segment(b!, c!))) {
      points = [points[0], points[1], points[3], points[2]];
    }

    const pointStr = points.map(p => p.name).join(',');
    $geopad.drawPath(`polygon(${pointStr})`, {name: 'quad', animated: 1000});
  });
github mathigon / textbooks / content / graph-theory / functions.ts View on Github external
function intersect(edges: Edge[]) {
    let count = 0;

    edges.forEach((e) => {
      e.intersect = e.vertices[0].intersect = e.vertices[1].intersect = false;
    });

    for (let i = 0; i < edges.length; ++i) {
      let e1 = edgeToSegment(edges[i]);
      for (let j = i + 1; j < edges.length; ++j) {
        let e2 = edgeToSegment(edges[j]);
        if (Segment.intersect(e1, e2)) {
          edges[i].intersect =
              edges[j].intersect = edges[i].vertices[0].intersect =
                  edges[i].vertices[1].intersect =
                      edges[j].vertices[0].intersect =
                          edges[j].vertices[1].intersect = true;
          count += 1;
        }
      }
    }

    return count;
  }
github mathigon / textbooks / content / graph-theory / functions.js View on Github external
function addEdge(u, v) {
      if (u === v) return;
      let edge = { p1: points[u], p2: points[v] };
      for (let i=0; i
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 / functions.js View on Github external
function intersect(edges) {
    let count = 0;

    edges.forEach(function(e) {
      e.intersect = e.vertices[0].intersect = e.vertices[1].intersect = false;
    });

    for (let i=0; i
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]);
    }