Skip to content

Commit c44d8da

Browse files
feat(geom): add planeFromRay()
1 parent 31fef3f commit c44d8da

File tree

1 file changed

+13
-0
lines changed

1 file changed

+13
-0
lines changed

packages/geom/src/plane.ts

Lines changed: 13 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -3,7 +3,9 @@ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
33
import { dot3 } from "@thi.ng/vectors/dot";
44
import { normalize3 } from "@thi.ng/vectors/normalize";
55
import { orthoNormal3 } from "@thi.ng/vectors/ortho-normal";
6+
import { set3 } from "@thi.ng/vectors/set";
67
import { Plane } from "./api/plane.js";
8+
import type { Ray3 } from "./api/ray3.js";
79

810
export const plane = (normal: Vec, w: number, attribs?: Attribs) =>
911
new Plane(normalize3(null, normal), w, attribs);
@@ -17,6 +19,17 @@ export const planeWithPoint = (
1719
return new Plane(normal, dot3(normal, p), attribs);
1820
};
1921

22+
/**
23+
* Creates a new plane from the given ray, using the ray's position as point on
24+
* the plane and the ray's direction as plane normal. If `attribs` are given,
25+
* they take precedence over the ray's attribs.
26+
*
27+
* @param ray
28+
* @param attribs
29+
*/
30+
export const planeFromRay = ({ pos, dir, attribs }: Ray3, $attribs?: Attribs) =>
31+
new Plane(set3([], dir), dot3(dir, pos), $attribs || attribs);
32+
2033
export const planeFrom3Points = (
2134
a: ReadonlyVec,
2235
b: ReadonlyVec,

0 commit comments

Comments
 (0)