@@ -3,7 +3,9 @@ import type { ReadonlyVec, Vec } from "@thi.ng/vectors";
3
3
import { dot3 } from "@thi.ng/vectors/dot" ;
4
4
import { normalize3 } from "@thi.ng/vectors/normalize" ;
5
5
import { orthoNormal3 } from "@thi.ng/vectors/ortho-normal" ;
6
+ import { set3 } from "@thi.ng/vectors/set" ;
6
7
import { Plane } from "./api/plane.js" ;
8
+ import type { Ray3 } from "./api/ray3.js" ;
7
9
8
10
export const plane = ( normal : Vec , w : number , attribs ?: Attribs ) =>
9
11
new Plane ( normalize3 ( null , normal ) , w , attribs ) ;
@@ -17,6 +19,17 @@ export const planeWithPoint = (
17
19
return new Plane ( normal , dot3 ( normal , p ) , attribs ) ;
18
20
} ;
19
21
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
+
20
33
export const planeFrom3Points = (
21
34
a : ReadonlyVec ,
22
35
b : ReadonlyVec ,
0 commit comments