-
-
Notifications
You must be signed in to change notification settings - Fork 151
Commit
This commit does not belong to any branch on this repository, and may belong to a fork outside of the repository.
feat(geom-isec): add ray-plane, plane-plane fns, update readme
- Loading branch information
1 parent
74dbcb0
commit 40a8bff
Showing
5 changed files
with
86 additions
and
14 deletions.
There are no files selected for viewing
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,32 @@ | ||
import { IntersectionType } from "@thi.ng/geom-api"; | ||
import { eqDelta, eqDeltaFixed } from "@thi.ng/math"; | ||
import { | ||
add3, | ||
cross3, | ||
dot3, | ||
mulN3, | ||
ReadonlyVec | ||
} from "@thi.ng/vectors"; | ||
import { NONE } from "./api"; | ||
|
||
export const intersectPlanePlane = ( | ||
na: ReadonlyVec, | ||
wa: number, | ||
nb: ReadonlyVec, | ||
wb: number | ||
) => { | ||
const dn = dot3(na, nb); | ||
if (eqDeltaFixed(dn, 1)) { | ||
return eqDelta(wa, wb) ? { type: IntersectionType.COINCIDENT } : NONE; | ||
} | ||
const det = 1 / (1 - dn * dn); | ||
const da = (wa - wb * dn) * det; | ||
const db = (wb - wa * dn) * det; | ||
return { | ||
type: IntersectionType.INTERSECT, | ||
isec: [ | ||
add3(null, mulN3([], na, da), mulN3([], nb, db)), | ||
cross3([], na, nb) | ||
] | ||
}; | ||
}; |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Original file line number | Diff line number | Diff line change |
---|---|---|
@@ -0,0 +1,37 @@ | ||
import { IntersectionType } from "@thi.ng/geom-api"; | ||
import { EPS, sign } from "@thi.ng/math"; | ||
import { | ||
copy, | ||
dot, | ||
maddN, | ||
mulN, | ||
ReadonlyVec, | ||
sub | ||
} from "@thi.ng/vectors"; | ||
import { NONE } from "./api"; | ||
|
||
export const intersectRayPlane = ( | ||
rpos: ReadonlyVec, | ||
dir: ReadonlyVec, | ||
normal: ReadonlyVec, | ||
w: number, | ||
eps = EPS | ||
) => { | ||
const d = dot(normal, dir); | ||
const cp = sign(dot(normal, rpos) - w, eps); | ||
if ((d > eps && cp < 0) || (d < -eps && cp > 0)) { | ||
const isec = sub(null, mulN([], normal, w), rpos); | ||
const alpha = dot(normal, isec) / d; | ||
return { | ||
type: IntersectionType.INTERSECT, | ||
isec: maddN(isec, rpos, dir, alpha), | ||
alpha | ||
}; | ||
} | ||
return cp === 0 | ||
? { | ||
type: IntersectionType.COINCIDENT, | ||
isec: copy(rpos) | ||
} | ||
: NONE; | ||
}; |