Find the intersection of a line with a plane: Difference between revisions
Content added Content deleted
Thundergnat (talk | contribs) m (→{{header|F#|F sharp}}: Regularize header markup to recommended on category page) |
(→{{header|Picat}}: Adding Picat) |
||
Line 1,245: | Line 1,245: | ||
"no intersection" |
"no intersection" |
||
</pre> |
</pre> |
||
=={{header|Picat}}== |
|||
{{trans|Java}} |
|||
{{works with|Picat}} |
|||
<lang Picat> |
|||
plus(U, V) = {U[1] + V[1], U[2] + V[2], U[3] + V[3]}. |
|||
minus(U, V) = {U[1] - V[1], U[2] - V[2], U[3] - V[3]}. |
|||
times(U, S) = {U[1] * S, U[2] * S, U[3] * S}. |
|||
dot(U, V) = U[1] * V[1] + U[2] * V[2] + U[3] * V[3]. |
|||
intersect_point(RayVector, RayPoint, PlaneNormal, PlanePoint) = IntersectPoint => |
|||
Diff = minus(RayPoint, PlanePoint), |
|||
Prod1 = dot(Diff, PlaneNormal), |
|||
Prod2 = dot(RayVector, PlaneNormal), |
|||
Prod3 = Prod1 / Prod2, |
|||
IntersectPoint = minus(RayPoint, times(RayVector, Prod3)). |
|||
main => |
|||
RayVector = {0.0, -1.0, -1.0}, |
|||
RayPoint = {0.0, 0.0, 10.0}, |
|||
PlaneNormal = {0.0, 0.0, 1.0}, |
|||
PlanePoint = {0.0, 0.0, 5.0}, |
|||
IntersectPoint = intersect_point(RayVector, RayPoint, PlaneNormal, PlanePoint), |
|||
printf("The ray intersects the plane at (%f, %f, %f)\n", |
|||
IntersectPoint[1], |
|||
IntersectPoint[2], |
|||
IntersectPoint[3] |
|||
). |
|||
</lang> |
|||
{{out}} |
|||
<pre> |
|||
The ray intersects the plane at (0.000000, -5.000000, 5.000000) |
|||
</pre> |
|||
=={{header|Python}}== |
=={{header|Python}}== |