Find the intersection of a line with a plane: Difference between revisions
Content added Content deleted
(added R as a translation of MATLAB) |
|||
Line 1,056: | Line 1,056: | ||
Line definition: x=3*t ; y=2+2*t ; z=4+t |
Line definition: x=3*t ; y=2+2*t ; z=4+t |
||
Intersection: P(0.6,2.4,4.2)</pre> |
Intersection: P(0.6,2.4,4.2)</pre> |
||
=={{header|Ruby}}== |
|||
{{trans|C#}} |
|||
<lang ruby>require "matrix" |
|||
def intersectPoint(rayVector, rayPoint, planeNormal, planePoint) |
|||
diff = rayPoint - planePoint |
|||
prod1 = diff.dot planeNormal |
|||
prod2 = rayVector.dot planeNormal |
|||
prod3 = prod1 / prod2 |
|||
return rayPoint - rayVector * prod3 |
|||
end |
|||
def main |
|||
rv = Vector[0.0, -1.0, -1.0] |
|||
rp = Vector[0.0, 0.0, 10.0] |
|||
pn = Vector[0.0, 0.0, 1.0] |
|||
pp = Vector[0.0, 0.0, 5.0] |
|||
ip = intersectPoint(rv, rp, pn, pp) |
|||
puts "The ray intersects the plane at %s" % [ip] |
|||
end |
|||
main()</lang> |
|||
{{out}} |
|||
<pre>The ray intersects the plane at Vector[0.0, -5.0, 5.0]</pre> |
|||
=={{header|Rust}}== |
=={{header|Rust}}== |