Miss Elaine Eos wrote:
> Ok, The 4th point is anywhere -- I guess I was hallucinating. Ok, just
> so you don't think I'm entirely off the wall, my triangle is part of a
> "terrain" mesh, and the point in question is known to be "above" said
> triangle (within the same X/Z boundaries, but at an arbitrary Y)
> although, now that I think about it, none of that really matters -- my
> question really is "how do I tell the distance of a point from a
> triangle?"
This is different from what Erik gave earlier, in case that wasn't
clear. Erik gave you the distance from the point to the plane defined
by the triangle, which is not going to be the distance from the point to
some arbitrary point inside the triangle. Using the equation that Erik
gave you will yield distances that are shorter than you want,
pro****tional to the angle of the face, in fact.
What I think you want to do is compute the barycentric coordinates of
the point in the triangle in the horizontal plane. That is, strip out
the vertical component of all of the points and get your barycentric
coordinate. Then, plug that back into the original face vertices, and
you'll get the point on the face above which the point-in-air is (and
you can assert that the horizontal components are equal, to validate
your math). The difference in the vertical components, then, gives you
what you're looking for.
Oh actually, if you're on a regular grid you can fairly readily get the
"components" for the altitudes of the three triangle points which feed
into the ground point.
E.g. assume that you have three points defining a triangle, where Y is
up:
{ 0, 0, 0 }, { 1, 1, 0 }, { 0, 2, 1 }
and a point at { 0.5, 10, 0.2 }, which is "contained" in your terms by
the triangle defined above.
This point is .5 of the way from p0 to p1, and .2 of the way from p0 to
p2 (choosing p0 as the "root" since it's the right angle when projected
to the horizontal so the math is easier), and you end up with a point on
the triangle at { 0.5, (0.5 * 1) + (0.2 * 2), .2 }.
I think that's correct. ;)
Alternatively you could do a solution with dot products against the
vertical vector, which you may need to do if your grid isn't regular. It
would end up very similarly to the above, though. Hmm, it may in fact
be exactly that is how you compute the barycentric coordinates in the
first place...
-tom!
--


|