#!/usr/bin/ruby
#
## https://rosettacode.org/wiki/Find_the_intersection_of_a_line_with_a_plane
#
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]),
))