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 11:55, 5 December 2023
, 6 months ago→{{header|Wren}}: Added libheader.
(→{{header|D}}: add evaldraw solution for intersect line plane) |
m (→{{header|Wren}}: Added libheader.) |
||
(4 intermediate revisions by 4 users not shown) | |||
Line 591:
{{out}}
<pre>The ray intersects the plane at (0.000000,-5.000000,5.000000)</pre>
=={{header|EasyLang}}==
{{trans|Lua}}
proc minus . l[] r[] res[] .
len res[] 3
for i to 3
res[i] = l[i] - r[i]
.
func dot l[] r[] .
for i to 3
.
return res
.
proc scale f . l[] .
for i to 3
.
.
proc inter_point rv[] rp[] pn[] pp[] . res[] .
minus rp[] pp[] dif[]
prd1 = dot dif[] pn[]
prd2 = dot rv[] pn[]
scale (prd1 / prd2) rv[]
minus rp[] rv[] res[]
.
rv[] = [ 0.0 -1.0 -1.0 ]
rp[] = [ 0.0 0.0 10.0 ]
pn[] = [ 0.0 0.0 1.0 ]
pp[] = [ 0.0 0.0 5.0 ]
inter_point rv[] rp[] pn[] pp[] res[]
print res[]
</syntaxhighlight>
=={{header|Evaldraw}}==
Line 596 ⟶ 631:
Makes use of the intersectionPoint function to intersect 9 lines with 1 moving plane in a realtime demo.
[[File:Evaldraw line vs plane.png|thumb|alt=Grid of 3x3 3d points intersecting a 3D plane|Shows 3x3 grid of lines intersecting a plane. Gridlines drawn between intersection points. Intersection "time" value projected from 3d intersection point to 2d screen rendering.]]
<syntaxhighlight lang="c">
struct vec{x,y,z;};
Line 1,789 ⟶ 1,824:
Line definition: x=3*t ; y=2+2*t ; z=4+t
Intersection: P(0.6,2.4,4.2)</pre>
=={{header|RPL}}==
≪ → rd rp pn pp
≪ rd rp pp - pn DOT * rd pn DOT /
≫ ≫ '<span style="color:blue">INTLP</span>' STO
[ 0 -1 -1 ] [ 0 0 0 ] [ 0 0 1 ] [ 0 0 5 ] <span style="color:blue">INTLP</span>
{{out}}
<pre>
1: [ 0 -5 -5 ]
</pre>
=={{header|Ruby}}==
Line 2,042 ⟶ 2,088:
=={{header|Wren}}==
{{trans|Kotlin}}
{{libheader|Wren-vector}}
▲<syntaxhighlight lang="ecmascript">class Vector3D {
<syntaxhighlight lang="wren">import "./vector" for Vector3
▲ _x = x
▲ _y = y
▲ }
var intersectPoint = Fn.new { |rayVector, rayPoint, planeNormal, planePoint|
Line 2,072 ⟶ 2,099:
}
var rv =
var rp =
var pn =
var pp =
var ip = intersectPoint.call(rv, rp, pn, pp)
System.print("The ray intersects the plane at %(ip).")</syntaxhighlight>
|