Find the intersection of a line with a plane: Difference between revisions
Find the intersection of a line with a plane (view source)
Revision as of 19:12, 7 May 2023
, 1 year agoAdded XPL0 example.
m (→With a geometric algebra library: precision in comment) |
(Added XPL0 example.) |
||
Line 1,967:
<pre>
The ray intersects the plane at (0, -5, 5).
</pre>
=={{header|XPL0}}==
{{trans|Wren}}
<syntaxhighlight lang "XPL0">include xpllib;
func real IntersectPoint; real RayVector, RayPoint, PlaneNormal, PlanePoint;
real Diff(3), Prod1, Prod2, Prod3, Prod(3);
[VSub(Diff, RayPoint, PlanePoint);
Prod1:= VDot(Diff, PlaneNormal);
Prod2:= VDot(RayVector, PlaneNormal);
Prod3:= Prod1 / Prod2;
return VSub(Diff, RayPoint, VMul(Prod, RayVector, Prod3));
];
real RV, RP, PN, PP, IP;
[RV:= [0., -1., -1.];
RP:= [0., 0., 10.];
PN:= [0., 0., 1.];
PP:= [0., 0., 5.];
IP:= IntersectPoint(RV, RP, PN, PP);
Print("The ray intersects the plane at %1.1f, %1.1f, %1.1f\n", IP(0), IP(1), IP(2));
]</syntaxhighlight>
{{out}}
<pre>
The ray intersects the plane at 0.0, -5.0, 5.0
</pre>
|