Re: 3d math
In a message dated 7/17/99 5:02:41 AM Central Daylight Time,
molasses at ALPHALINK.COM.AU writes:
<< Hi,
Does someone know how to calculate if a point exists on a 3d line?
e.g..
I have 2 points that make a line : {x1, y1, z1} and {x2, y2, z2}
and I want to see if the point {x3, y3, z3} exists on that line. >>
Using calculus, you can find the change in one as another element changes,
to see if the point falls on that slope. For example, say the given points
are A and B, and the point in consideration is C:
A = { 10, 4, 7}
B = { 6, 6, 3}
C = { 8, 5, 5}.
Make the first step be to find the change in y over the change in x for the
end points:
(y1 - y2/x1 - x2)
(4-6/10-6) = -1/2
Now, find the slope like above, but use only one of the endpoints and point
C.
(4-5)/10-8) = -1/2.
Since the slopes are equal, then so far this point does lies in the line.
Repeat the process above using change in z over change in x. If the slopes
are equal again, then the point lies in the line. Here is the function that
I just tested, so it works. A return of 1 means it's one the line, 0 means
false:
function CheckPoint(sequence pt1, sequence pt2, sequence point)
atom dydx, dzdx, answer
answer = ( pt1[2] - pt2[2] ) / ( pt1[1] - pt2[1] )
dydx = ( pt1[2] - point[2] ) / ( pt1[1] - point[1] )
if answer != dydx then
return 0
else
answer = ( pt1[3] - pt2[3] ) / ( pt1[1] - pt2[1])
dzdx = ( pt1[3] - point[3] ) / ( pt1[1] - point[1] )
if answer != dzdx then
return 0
else
return 1
end if
end if
end function
Derek Brown
|
Not Categorized, Please Help
|
|