Example #1
0
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
// of the edge.
let centerOffset = 2*triBase[0].x - triWidth/2;