#!/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]),
))