Example #1
0
  constructor(container: HTMLElement, viewSize: [number, number]) {
    // Internal UI state
    this._viewSize = viewSize;
    this._container = container;
    this._canvasSize = [viewSize[0] / 2, viewSize[1]];
    this._canvasBounds = new Rect(
      Coords2d.fromXY(0, this._canvasSize[1]),
      OffsetCoords2d.fromDxDy(this._canvasSize[0], -this._canvasSize[1])
    );

    this._needsRedraw = false;

    this.gluingBounds = Rect.fromDimensions(2, 2);
    this.editMode = 'triangle';

    // Internal array to store the embedded 3-d triangles.
    this._distance = 3;
    this._triangle = Triangle2d.fromCoords(
      Coords2d.origin(),
      Coords2d.fromXY(1, 0),
      Coords2d.fromXY(0.5, Math.sqrt(3)/4)
    );
    this._rotation = Quaternion.fromReal(1);
    this._gluing = TriangleTetraGluing.fromEdgeIndexAndGluePoint(0, 0);
    this._refreshEmbedding();
  }
Example #2
0
export function TriangleForApex(apex: Coords2d): Triangle2d {
  return Triangle2d.fromCoords(
    Coords2d.origin(),
    Coords2d.fromXY(1, 0),
    apex
  );
}
Example #3
0
export function ApexForBaseAngles(a0: number, a1: number): Coords2d {
  let leftTangent =
    OffsetCoords2d.fromPolar(1, a0).rootedAtCoords(Coords2d.origin());
  let rightTangent = OffsetCoords2d.fromPolar(1, Math.PI - a1)
    .rootedAtCoords(Coords2d.fromXY(1, 0));
  return leftTangent.intersectionWith(rightTangent);
}
Example #4
0
export function PathMargin (
    triangle: Triangle2d, edgeSequence: Array<number>): number {
  let tri = triangle.copy();
  let leftBoundary = [];
  let rightBoundary = [];
  let prevEdge = 0;
  for (let i = 0; i < edgeSequence.length; i++) {
    let edgeDelta = (edgeSequence[i] - (prevEdge + 1) + 3) % 3; // always 0 or 1
    if (edgeDelta == i % 2) {
      // Right
      leftBoundary.push(tri.vertex(edgeSequence[i] + 1 - (i % 2)));
    } else {
      // Left
      rightBoundary.push(tri.vertex(edgeSequence[i] + (i % 2)));
    }
    tri.reflectThroughEdge(edgeSequence[i]);
    prevEdge = edgeSequence[i];
  }
  let offset = tri.vertexCoords[0]
    .asOffsetFrom(triangle.vertexCoords[0]);
  let lineCoeff = OffsetCoords2d.fromDxDy(-offset.dy, offset.dx).normalized();
  let o = Coords2d.origin();
  let minLeft = lineCoeff.dot(triangle.vertexCoords[0].asOffsetFrom(o));
  for (let i = 0; i < leftBoundary.length; i++) {
    let coeff = lineCoeff.dot(leftBoundary[i].asOffsetFrom(o));
    if (coeff < minLeft) {
      minLeft = coeff;
    }
  }
  let maxRight = lineCoeff.dot(triangle.vertexCoords[1].asOffsetFrom(o));
  for (let i = 0; i < rightBoundary.length; i++) {
    let coeff = lineCoeff.dot(rightBoundary[i].asOffsetFrom(o));
    if (coeff > maxRight) {
      maxRight = coeff;
    }
  }
  //window.console.log(`${minLeft}, ${maxRight}`);
  return minLeft - maxRight;
}
Example #5
0
 constructor (target: RenderTarget) {
   this.target = target;
   this.modelBounds = AxisRect.fromCenterAndDimensions(
     Coords2d.origin(), 2, 2);
   this.backgroundColor = "white";
 }
Example #6
0
 static fromDimensions (width: number, height: number): Rect {
   return Rect.fromCenterAndDimensions(Coords2d.origin(), width, height);
 }
Example #7
0
// @flow

import { ElementsModel } from 'faec/elements_model';
import { Coords2d, OffsetCoords2d } from 'faec/geometry';
import { AxisRect } from 'faec/polygon';

import { Line, Renderable } from 'faec/element_render';

let squareRoot = Math.sqrt(3);
let fourthRoot = Math.sqrt(squareRoot);
// (w, h) are the dimensions of the unit-area equilateral triangle
// with its base aligned with the x axis.
let triWidth = 2 / fourthRoot;
let triHeight = fourthRoot;
let triVerts = [
  Coords2d.origin(),
  Coords2d.fromXY(triWidth, 0),
  Coords2d.fromXY(triWidth / 2, triHeight)];
let triLeft = Coords2d.midpoint(triVerts[0], triVerts[2]);
let triRight = Coords2d.midpoint(triVerts[1], triVerts[2]);

// The horizontal width of the long diagonal, which goes from
// triRight to the base and has length 1.
let diagonalWidth = Math.sqrt(1.0 - triRight.y * triRight.y);
let diagonal = OffsetCoords2d.fromDxDy(diagonalWidth, triRight.y);
let triBase = [
  Coords2d.fromXY(triRight.x - diagonalWidth, 0),
  Coords2d.fromXY((triRight.x - diagonalWidth) * 2, 0),
  Coords2d.fromXY((triRight.x - diagonalWidth) + triWidth/2, 0)];

// The offset of the center base point from the geometric center
Example #8
0
 // Triangle: the triangle in which we're looking at billiards.
 get triangle (): Triangle2d {
   return Triangle2d.fromCoords(
     Coords2d.origin(),
     Coords2d.fromXY(1, 0),
     this._apex);
 }