How to use the @mathigon/fermat.roundTo 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 / linear-functions / functions.ts View on Github external
function pfn(p: Point) {
    const q = $chart.plotToMathCoords(p);
    const x = clamp(roundTo(q.x, 0.5), -4, 4);
    return $chart.mathToPlotCoords(new Point(x, 3 / 4 * x + 2));
  }
github mathigon / boost.js / src / elements.js View on Github external
setTransform(posn, angle = 0, scale = 1) {
    let t = '';
    if (posn) t += `translate(${roundTo(posn.x, 0.1)}px,${roundTo(posn.y, 0.1)}px)`;
    if (angle) t += ` rotate(${angle}rad)`;
    if (scale) t += ` scale(${scale})`;
    this._el.style.transform = t;
  }
github mathigon / textbooks / content / polyhedra / components / tessellation.ts View on Github external
function getAngle(p1: Point, p2: Point) {
  return roundTo(Math.atan2(p1.y - p2.y, p1.x - p2.x) * 180 / Math.PI + 90, 6);
}
github mathigon / textbooks / content / statistics / functions.ts View on Github external
draw(angle, isMomentum, dt) {
      for (let $w of $wheels) $w.setTransform(undefined, angle);
      if (!isMomentum) return;

      ballSpeed *= 0.985;
      if (Math.abs(ballSpeed) > 0.00032) {
        ballAngle = (ballAngle + dt * ballSpeed) % (2 * Math.PI);
      } else {
        if (!ballOffset) ballOffset =
            roundTo(ballAngle - angle, 2 * Math.PI / 37);
        ballAngle = angle + ballOffset;
      }

      const ballRadius = Math.min(116 + 87500 * Math.abs(ballSpeed), 165);
      const x = ballRadius * Math.sin(ballAngle);
      const y = -ballRadius * Math.cos(ballAngle);
      $ball.translate(x, y);
    }
  });
github mathigon / textbooks / probability / functions.js View on Github external
animation = animate((t, dt) => {
      wheelSpeed *= 0.995;
      wheelAngle = (wheelAngle + dt * wheelSpeed) % (2 * Math.PI);

      ballSpeed *= 0.985;
      if (Math.abs(ballSpeed) > 0.00032) {
        ballAngle = (ballAngle + dt * ballSpeed) % (2 * Math.PI);
      } else {
        if (!ballOffset) ballOffset = roundTo(ballAngle - wheelAngle, 2 * Math.PI/ 37);
        ballAngle = wheelAngle + ballOffset;
      }

      let ballRadius = Math.min(116 + 87500 * Math.abs(ballSpeed), 165);
      draw(wheelAngle, ballAngle, ballRadius);
      return wheelSpeed;
    });
  }
github mathigon / textbooks / content / linear-functions / functions.ts View on Github external
function pfn(p: Point) {
    const q = $chart.plotToMathCoords(p);
    const x = clamp(roundTo(q.x, 0.5), -4, 4);
    return $chart.mathToPlotCoords(new Point(x, 1.5 * x));
  }
github mathigon / textbooks / content / circles / functions.ts View on Github external
move(p) {
        let r = roundTo(p.subtract(drag.position).length, 20);
        $outline.setAttr('r', r);
        $outlineHalo.setAttr('r', r);
        rReady = (r === 60);
        if (rReady && cReady) complete(c[3], $handle, $outline, $outlineHalo);
      }
    });