gadirections.ts 631 B

1234567891011121314151617181920212223242526
  1. import * as GA from "./ga";
  2. import { Line, Direction, Point } from "./ga";
  3. /**
  4. * A direction is stored as an array `[0, 0, 0, 0, y, x, 0, 0]` representing
  5. * vector `(x, y)`.
  6. */
  7. export const from = (point: Point): Point => [
  8. 0,
  9. 0,
  10. 0,
  11. 0,
  12. point[4],
  13. point[5],
  14. 0,
  15. 0,
  16. ];
  17. export const fromTo = (from: Point, to: Point): Direction =>
  18. GA.inormalized([0, 0, 0, 0, to[4] - from[4], to[5] - from[5], 0, 0]);
  19. export const orthogonal = (direction: Direction): Direction =>
  20. GA.inormalized([0, 0, 0, 0, -direction[5], direction[4], 0, 0]);
  21. export const orthogonalToLine = (line: Line): Direction => GA.mul(line, GA.I);