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

Content added Content deleted
(Added Easylang)
(→‎{{header|Wren}}: Now uses vector module.)
Line 2,088: Line 2,088:
=={{header|Wren}}==
=={{header|Wren}}==
{{trans|Kotlin}}
{{trans|Kotlin}}
<syntaxhighlight lang="ecmascript">class Vector3D {
<syntaxhighlight lang="wren">import "./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|
var intersectPoint = Fn.new { |rayVector, rayPoint, planeNormal, planePoint|
Line 2,118: Line 2,098:
}
}


var rv = Vector3D.new(0, -1, -1)
var rv = Vector3.new(0, -1, -1)
var rp = Vector3D.new(0, 0, 10)
var rp = Vector3.new(0, 0, 10)
var pn = Vector3D.new(0, 0, 1)
var pn = Vector3.new(0, 0, 1)
var pp = Vector3D.new(0, 0, 5)
var pp = Vector3.new(0, 0, 5)
var ip = intersectPoint.call(rv, rp, pn, pp)
var ip = intersectPoint.call(rv, rp, pn, pp)
System.print("The ray intersects the plane at %(ip).")</syntaxhighlight>
System.print("The ray intersects the plane at %(ip).")</syntaxhighlight>