Skip to main content

Lines and Rays

  • Situation: Rejecting hits behind a ray or beyond a segment
  • Target: Parameter domain · Distance · Closest point
  • Convention: Right-handed orthonormal frame; column vectors; rightmost matrix first; angles in radians unless marked °; lengths in m · Overview

Core concepts​

  • Parameter domain: line t∈R, ray t≥0, segment A+t(B−A) with 0≤t≤1; equation and domain jointly defining the primitive
line ray segment parameter range
Figure 1. line ray segment parameter range
two points direction vector
Figure 2. two points direction vector
  • Distance: |t|‖d‖; dimensionless t for d in meters, distance parameter s in meters for dimensionless unit d̂

  • Closest point: projection onto direction, then domain clamp; ray max(0,t), segment clamp(t,0,1)

closest point projection
Figure 3. closest point projection
  • Degeneracy: d=0 or A=B as a single point; denominator test before projection
segment interpolation
Figure 4. segment interpolation
  • 2D forms: y=mx+b excluding vertical lines; n·P=c with n perpendicular to direction including vertical lines
parametric direction implicit normal
Figure 5. parametric direction implicit normal

Worked example​

Shared path: A=(1,1,0), d=(3,4,0) m; t=−1,0,0.5,1,2 → (−2,−3,0),(1,1,0),(2.5,3,0),(4,5,0),(7,9,0) m

P(t)=A+td,t∗=(Q−A)⋅dd⋅d,Pseg=A+clamp⁡(t∗,0,1)dP(t)=A+t\mathbf d,\qquad t_*=\frac{(Q-A)\cdot\mathbf d}{\mathbf d\cdot\mathbf d},\qquad P_{\mathrm{seg}}=A+\operatorname{clamp}(t_*,0,1)\mathbf d

Practice​

  • Preparation → prediction → calculation: Predict membership for five t values; calculate positions and line/ray/segment membership; midpoint with t=0.5 versus s=2.5 m; retain parameter domains for hit tests
  • Record: Assumed exercise inputs; predictions before calculation; calculated answers and optional viewer output in separate columns; no physical measurements
CasePredictionCalculated resultViewer output (optional)
P(0.25)P(0.25)
t=2: ∣t∣∥d∥t=2:\ \vert t\vert \Vert \mathbf d\Vert
Q=(5,1,0): A+0.48dQ=(5,1,0):\ A+0.48\mathbf d
  • Optional extension: Closest point to Q=(5,1,0) m: projection t=12/25=0.48, on both line and segment

Exercises​

  1. Problem: P(0.25)P(0.25)
  2. Problem: t=2: ∣t∣∥d∥t=2:\ |t|\|\mathbf d\|
  3. Problem: Q=(5,1,0): A+0.48dQ=(5,1,0):\ A+0.48\mathbf d
  4. Problem: Segment membership at t=−0.1
Answers and checks
  1. Answer: (1.75,2,0) m(1.75,2,0)\ \mathrm m
  2. Answer: 10 m10\ \mathrm m
  3. Answer: (2.44,2.92,0) m(2.44,2.92,0)\ \mathrm m
  4. Answer: Outside; closest clamped endpoint A

Connections​