Skip to content

Commit

Permalink
fix(geom-poly-utils): fix equilateralTriangle2()
Browse files Browse the repository at this point in the history
  • Loading branch information
postspectacular committed Mar 11, 2022
1 parent 2385eb0 commit c37c27e
Showing 1 changed file with 11 additions and 7 deletions.
18 changes: 11 additions & 7 deletions packages/geom-poly-utils/src/equilateral.ts
Original file line number Diff line number Diff line change
@@ -1,6 +1,7 @@
import type { FnU2 } from "@thi.ng/api";
import { THIRD_PI } from "@thi.ng/math/api";
import { SQRT3_2 } from "@thi.ng/math/api";
import type { Vec } from "@thi.ng/vectors";
import { add2 } from "@thi.ng/vectors/add";
import { maddN2 } from "@thi.ng/vectors/maddn";
import { mag } from "@thi.ng/vectors/mag";
import { normalize } from "@thi.ng/vectors/normalize";
Expand All @@ -9,10 +10,13 @@ import { sub2 } from "@thi.ng/vectors/sub";

export const equilateralTriangle2: FnU2<Vec, Vec[]> = (a, b) => {
const dir = sub2([], b, a);
const c = normalize(
null,
perpendicularCCW([], dir),
mag(dir) * Math.sin(THIRD_PI)
);
return [a, b, maddN2(null, dir, 0.5, c)];
return [
a,
b,
add2(
null,
normalize(null, perpendicularCCW([], dir), mag(dir) * SQRT3_2),
maddN2(dir, dir, 0.5, a)
),
];
};

0 comments on commit c37c27e

Please sign in to comment.