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

Content added Content deleted
Line 19: Line 19:
<pre>
<pre>
The ray intersects the plane at (0, -5, 5)
The ray intersects the plane at (0, -5, 5)
</pre>

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