Find the intersection of a line with a plane: Difference between revisions
Content deleted Content added
m →{{header|zkl}}: format |
Added Sidef |
||
Line 71:
{{out}}
<pre>intersection at [ 0 -5 5]</pre>
=={{header|Sidef}}==
{{trans|Perl 6}}
<lang ruby>struct Line {
P0, # point
u⃗, # ray
}
struct Plane {
V0, # point
n⃗, # normal
}
func dot_prod(a, b) { a »*« b -> sum }
func line_plane_intersection(𝑳, 𝑷) {
var cos = dot_prod(𝑷.n⃗, 𝑳.u⃗) ->
|| return 'Vectors are orthogonal'
var 𝑊 = (𝑳.P0 »-« 𝑷.V0)
var S𝐼 = -(dot_prod(𝑷.n⃗, 𝑊) / cos)
𝑊 »+« (𝑳.u⃗ »*» S𝐼) »+« 𝑷.V0
}
say ('Intersection at point: ', line_plane_intersection(
Line(P0: [0,0,10], u⃗: [0,-1,-1]),
Plane(V0: [0,0, 5], n⃗: [0, 0, 1]),
))</lang>
{{out}}
<pre>
Intersection at point: [0, -5, 5]
</pre>
=={{header|zkl}}==
|