Find the intersection of a line with a plane: Difference between revisions

m
Line 23:
=={{header|APL}}==
<lang APL>⍝ Find Intersection of a line with a plane
⍝ The intersection I belongs to a line defined by point DL and vector V, means that t exists, so that I = DL + tV
⍝ I belongs to the plan defined by point P and normal vector N. This means that the vector IP is normal to vector N
⍝ This translates to their scalar product being zero.
⍝ (P - I).N = 0 <=> (P - DL - tV).N = 0
⍝ Using distributivity, then associativity, the following equations are established:
⍝ (P - DL - tV).N = (P - DL).N - (tV).N = (P - DL).N - t(V.N) = 0
⍝ so that: t = ((P - DL).N) ÷ (V.N)
⍝ In APL, A.B is coded +/A x B
V ← 0 ¯1 ¯1
DL ← 0 0 10
N ← 0 0 1
P ← 0 0 5
dot ← {+/⍺×⍵}
t ← ((P - DL) dot N) ÷ V dot N
I ← DL + t × V
</lang>
{{out}}
Anonymous user