How to use the @mathigon/fermat.isBetween 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 / chaos / functions.ts View on Github external
function step() {
    for (let i = 0; i < balls.length; ++i) {
      const b = balls[i];
      if (!isBetween(b.p.x, bounds[0], bounds[2])) {
        b.v = b.v.scale(-1, 1);
        playCollision();
      }

      if (!isBetween(b.p.y, bounds[1], bounds[3])) {
        b.v = b.v.scale(1, -1);
        playCollision();
      }

      for (let j = i + 1; j < balls.length; ++j) {
        const b1 = balls[j];
        if (Point.distance(b.p, b1.p) < 2 * RADIUS) {
          // https://en.wikipedia.org/wiki/Elastic_collision#Two-dimensional_collision_with_two_moving_objects
          const d = b.p.subtract(b1.p);
          const dv = Point.dot(b.v.subtract(b1.v), d) / d.length ** 2;
          b.v = b.v.subtract(d.scale(dv));
github mathigon / textbooks / content / chaos / functions.ts View on Github external
function step() {
    for (let i = 0; i < balls.length; ++i) {
      const b = balls[i];
      if (!isBetween(b.p.x, bounds[0], bounds[2])) {
        b.v = b.v.scale(-1, 1);
        playCollision();
      }

      if (!isBetween(b.p.y, bounds[1], bounds[3])) {
        b.v = b.v.scale(1, -1);
        playCollision();
      }

      for (let j = i + 1; j < balls.length; ++j) {
        const b1 = balls[j];
        if (Point.distance(b.p, b1.p) < 2 * RADIUS) {
          // https://en.wikipedia.org/wiki/Elastic_collision#Two-dimensional_collision_with_two_moving_objects
          const d = b.p.subtract(b1.p);
          const dv = Point.dot(b.v.subtract(b1.v), d) / d.length ** 2;
          b.v = b.v.subtract(d.scale(dv));
          b1.v = b1.v.add(d.scale(dv));
          playCollision();
        }
      }
    }
github mathigon / boost.js / src / elements.js View on Github external
get isInViewport() {
    if (this.height === 0) return false;
    const bounds = this.bounds;
    return isBetween(bounds.top, -bounds.height, Browser.height);
  }
github mathigon / textbooks / content / chaos / components / water-ripples.ts View on Github external
touchWater(p: Point, pressure: number) {
    const x = Math.round(p.x);
    const y = Math.round(p.y);

    for (let i = 0; i < 2 * this.touchSize; ++i) {
      for (let j = 0; j < 2 * this.touchSize; ++j) {
        const cx = x - this.touchSize + i;
        const cy = y - this.touchSize + j;
        if (isBetween(cx, -1, this.sx) && isBetween(cy, -1, this.sy)) {
          this.depthMap1[cx][cy] -= this.touchPattern[i][j] * pressure;
        }
      }
    }

    this.startAnimation();
  }
github mathigon / textbooks / content / graph-theory / components / sketch.ts View on Github external
move: p => {
        if (!this.drawing) return;

        const box = $svg.viewBox;
        if (!isBetween(p.x, 0, box.width) || !isBetween(p.y, 0, box.height))
          return this.stop();

        this.addPoint(p);
      },
      end: () => this.stop()