Use this skill to turn game picking, collision, containment, and distance
questions into small geometric systems with explicit constraints and failure
cases.
Primary source: Geometry for Programmers by Oleksandr Kaleniuk
(
https://www.manning.com/books/geometry-for-programmers), transformed and
paraphrased, especially chapters 3, 4, and 9. Additional source: "Fast,
Minimum Storage Ray-Triangle Intersection" by Tomas Moller and Ben Trumbore
(
https://dl.acm.org/doi/10.1145/1198555.1198746).
Model the ray as
with
. Model triangle points as
with
,
, and
.
Decide whether points on edges count as inside. Tests must cover both the chosen
edge policy and reversed triangle winding.
Build a plane normal from two nonparallel edges. Dot the normalized normal with
the vector from any plane point to the query point. Keep the sign when side
matters; take absolute value only for unsigned distance.
Project onto the segment direction, clamp the parameter to
, then measure
distance to the clamped point. Reject or special-case zero-length segments before
normalization.