[Dir3d-l] Line-Plane intersect
ullala
ullala at ullala.org
Mon Mar 17 08:06:04 EST 2003
At 11:15 Uhr +0000 17.3.2003, Phillip Gan wrote:
>Does anybody know of a Lingo command that will find the point of
>intersection between a line and a plane? I want a model to appear on
>a plane at a position determined by a click. The
>spriteSpaceToWorldSpace command puts the model somewhere way off
>into the distance. I haven't been able to find a command that does
>what I want, but intersections are a pretty fundamental idea in 3D
>maths so I reckon I must be missing something obvious.
I wrote 2 handlers a few days ago for a generic, mathematical
ray-plane-interesection calculation...
Till now it looks like its working without mistakes ;-)
Well, if anybody knows a better way, please let me know.
First handler is the ray-plane-intersection, while the plane is
defined by its normal and the distance to (0,0,0) in the world
(Koordinatenursprung in engl.?)
If you dont know this distance but a point on the plane instead, you
can get the distance with the second handler.
Take care about line breaks...
-- *********************************** --
on RayPlaneIntersection RayPoint, RayVector, PlaneNormal, PlaneDistance
-- calculating intersection point of ray and plane
-- returns intersection point (vector) if it exists
-- returns void if ray is parallel to plane (within plane or not)
-- RayPoint ... point on ray
-- RayVector ... ray direction (normalized!)
-- PlaneNormal ... normal vector to plane (normalized!)
-- PlaneDistance ... distance from plane to Koordinatenursprung
-- angle between ray and normal
tAngle = RayVector.angleBetween(PlaneNormal)
if abs(tAngle) = 90 then RETURN -- ray parallel
-- shortest distance between rayPoint and plane
a = RayPoint.angleBetween(PlaneNormal)
deltaD = PlaneDistance - (cos(a*pi()/180.0) * RayPoint.magnitude)
-- distance from rayPoint to intersection
D = deltaD / cos(tAngle*pi()/180.0)
RETURN RayPoint + (D*RayVector)
end
-- *********************************** --
on GetPlaneDistance PlanePoint, PlaneNormal
-- calculating distance from plane to Koordinatenursprung
-- PlanePoint ... a point (vector) on the plane
-- PlaneNormal ... normal vector to plane (normalized!)
distP = PlanePoint.magnitude
if distP = 0 then RETURN 0
tAngle = PlanePoint.angleBetween(PlaneNormal)
if abs(tAngle) = 90 then RETURN 0
D = abs(distP * cos(tAngle*pi()/180.0))
SP = D * PlaneNormal
if (SP-PlanePoint).magnitude > (-SP-PlanePoint).magnitude then D = -D
RETURN D
end
-- *********************************** --
ullala :-)
----------------------------------
3DPI - the 3D Property Inspector for Director:
http://www.3dpi-director.com/
----------------------------------
--
More information about the Dir3d-l
mailing list