Jump to content

Find the intersection of a line with a plane: Difference between revisions

→‎{{header|Wren}}: Now uses vector module.
(Added Easylang)
(→‎{{header|Wren}}: Now uses vector module.)
Line 2,088:
=={{header|Wren}}==
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascriptwren">classimport Vector3D"./vector" for {Vector3
construct new(x, y, z) {
_x = x
_y = y
_z = z
}
 
x { _x }
y { _y }
z { _z }
 
+(v) { Vector3D.new(_x + v.x, _y + v.y, _z + v.z) }
 
-(v) { Vector3D.new(_x - v.x, _y - v.y, _z - v.z) }
 
*(s) { Vector3D.new(s * _x, s * _y, s * _z) }
 
dot(v) { _x * v.x + _y * v.y + _z * v.z }
 
toString { "(%(_x), %(_y), %(_z))" }
}
 
var intersectPoint = Fn.new { |rayVector, rayPoint, planeNormal, planePoint|
Line 2,118 ⟶ 2,098:
}
 
var rv = Vector3DVector3.new(0, -1, -1)
var rp = Vector3DVector3.new(0, 0, 10)
var pn = Vector3DVector3.new(0, 0, 1)
var pp = Vector3DVector3.new(0, 0, 5)
var ip = intersectPoint.call(rv, rp, pn, pp)
System.print("The ray intersects the plane at %(ip).")</syntaxhighlight>
9,482

edits

Cookies help us deliver our services. By using our services, you agree to our use of cookies.