Anonymous user
Find the intersection of a line with a plane: Difference between revisions
Find the intersection of a line with a plane (view source)
Revision as of 15:32, 4 December 2019
, 4 years agoadded R as a translation of MATLAB
Alextretyak (talk | contribs) (Added 11l) |
(added R as a translation of MATLAB) |
||
Line 853:
{{out}}
<pre>intersection at [ 0 -5 5]</pre>
=={{header|R}}==
{{trans|MATLAB}}
<lang R>intersect_point <- function(ray_vec, ray_point, plane_normal, plane_point) {
pdiff <- ray_point - plane_point
prod1 <- pdiff %*% plane_normal
prod2 <- ray_vec %*% plane_normal
prod3 <- prod1 / prod2
point <- ray_point - ray_vec * as.numeric(prod3)
return(point)
}</lang>
{{out}}
<lang R>>>intersect_point(c(0, -1, -1), c(0, 0, 10), c(0, 0, 1), c(0, 0, 5))
[1] 0 -5 5</lang>
=={{header|Racket}}==
|