How to use the @mathigon/fermat.Line 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 / transformations / components / wallpaper.ts View on Github external
import {Point, Line} from '@mathigon/fermat';
import {CanvasView, CustomElementView, register, slide} from '@mathigon/boost';
import {Select} from '../../shared/types';


// -------------------------------------------------------------------------
// Symmetry Functions

const width = 1920;
const height = 1280;

const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0, 320), new Point(480, 320));
const lineY1 = new Line(new Point(480, 0), new Point(480, 320));
const lineY2 = new Line(new Point(640, 0), new Point(640, 320));

const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));

function grid(points: Point[], x: number, y: number) {
  return flatten(tabulate2D((i, j) =>
      points.map((p: Point) => p.shift(i * x, j * y)), width / x, height / y));
}

function applyTransforms(point: Point, [x, y]: [number, number],
                         transforms: ((p: Point) => Point)[]) {
  let points = [point.mod(x, y)];

  for (let t of transforms) {
    for (let p of points.map(p => t(p))) {
github mathigon / textbooks / transformations-and-symmetry / components / wallpaper.js View on Github external
import { tabulate, flatten } from '@mathigon/core';
import { Point, Line } from '@mathigon/fermat';
import { CustomElement, registerElement, slide } from '@mathigon/boost';


// -------------------------------------------------------------------------
// Symmetry Functions

const width = 1920;
const height = 1280;

const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0,320), new Point(480,320));
const lineY1 = new Line(new Point(480,0), new Point(480,320));
const lineY2 = new Line(new Point(640,0), new Point(640, 320));

const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));

function grid(points, x, y) {
  return flatten(tabulate((i, j) => points.map(p => p.shift(i * x, j * y)),
    width/x, height/y));
}

function applyTransforms(point, [x, y], transforms) {
  let points = [point.mod(x, y)];

  for (let t of transforms) {
    for (let p of points.map(p => t(p))) {
github mathigon / textbooks / content / transformations / components / wallpaper.js View on Github external
// -------------------------------------------------------------------------
// Symmetry Functions

const width = 1920;
const height = 1280;

const pointX1M = new Point(240, 320);
const pointX1Y1 = new Point(480, 320);
const lineX1 = new Line(new Point(0,320), new Point(480,320));
const lineY1 = new Line(new Point(480,0), new Point(480,320));
const lineY2 = new Line(new Point(640,0), new Point(640, 320));

const pointS = new Point(360, 360);
const lineS = new Line(new Point(0, 0), new Point(360, 360));
const lineSI = new Line(new Point(0, 720), new Point(720, 0));

function grid(points, x, y) {
  return flatten(tabulate((i, j) => points.map(p => p.shift(i * x, j * y)),
    width/x, height/y));
}

function applyTransforms(point, [x, y], transforms) {
  let points = [point.mod(x, y)];

  for (let t of transforms) {
    for (let p of points.map(p => t(p))) {
      if (!points.some(q => q.equals(p))) points.push(p);
    }
  }
github mathigon / textbooks / content / transformations / components / wallpaper.js View on Github external
function lineX(y) { return new Line(new Point(0, y), new Point(1, y)); }
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
github mathigon / textbooks / transformations-and-symmetry / components / wallpaper.js View on Github external
function lineX(y) { return new Line(new Point(0, y), new Point(1, y)); }
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
github mathigon / textbooks / transformations-and-symmetry / components / wallpaper.js View on Github external
function line(a1, a2, b1, b2) { return new Line(new Point(a1, a2), new Point(b1, b2)); }
github mathigon / boost.js / src / sketch.js View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points;
    let line1 = new Line(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;
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Line(points2[j], points2[j + 1]);
        let t = Line.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', { point: t, paths: [path1, path2] });
          return;
        }
      }
    }
  }
github mathigon / textbooks / content / chaos / components / pool-table.ts View on Github external
drawPath(start: Point) {
    const ellipse = new Ellipse(new Point(380, 220), 360, 200);

    const points = [start];
    let line = new Line(start, start.shift(1, -1));

    for (let i = 0; i < 100; ++i) {
      const p = ellipse.intersect(line)[0];
      points.push(p);
      const q = line.p1.reflect(ellipse.normalAt(p));
      line = new Line(p, q);
    }

    this.$path.points = points;
    this.$end.setCenter(last(points));
  }
}
github mathigon / boost.js / src / sketch.js View on Github external
checkForIntersects() {
    if (!this.options.intersect || this.paths.length <= 1) return;

    let path1 = last(this.paths);
    let points1 = path1.points;
    let line1 = new Line(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;
      for (let j = 1; j < points2.length - 2; ++j) {
        let line2 = new Line(points2[j], points2[j + 1]);
        let t = Line.intersect(line1, line2);
        if (t) {
          this.trigger('intersect', { point: t, paths: [path1, path2] });
          return;
        }
      }
    }
  }
github mathigon / textbooks / transformations-and-symmetry / components / wallpaper.js View on Github external
function lineY(x) { return new Line(new Point(x, 0), new Point(x, 1)); }
function line(a1, a2, b1, b2) { return new Line(new Point(a1, a2), new Point(b1, b2)); }