In article <ofqrg21jj3mgg5og49ctk6vuffudniatt2@[EMAIL PROTECTED]
>,
Tom Plunket <gamedev@[EMAIL PROTECTED]
> wrote:
> 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.
Ah yes, I was just pondering over that little bug in my code...
> 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.
That sounds right. My triangle is "mostly XZ" (that is, it is NOT
vertical), and I have a point within the XZ bounds of the triangle, I
want to know the Y of that particular XZ point on the triangle -- it's
"altitude", in my game terms.
> E.g. assume that you have three points defining a triangle, where Y is
> up:
>
> { 0, 0, 0 }, { 1, 1, 0 }, { 0, 2, 1 }
Ok, looks good. Im****tantly, the XZ of this triangle is
{0,0},{1,0},{0,1}, with the 3 points at 0, 1 & 2 "Y" values.
> and a point at { 0.5, 10, 0.2 }, which is "contained" in your terms by
> the triangle defined above.
Sure. Or, more im****tantly, I know that I'm at location XZ={0.5, 0.2}
and I'm "on the triangle" (i.e., on the ground, as this tri is part of
my terrain), and want to know my "Y".
> 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 }.
Aha! See, THAT'S what I meant in my original by "a sort of averaging"
of the points.
> I think that's correct. ;)
Me, too, but I wasn't sure, and my 1st attempt wasn't working out the
way I thought it should -- so I was hoping for some sample code.
> 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...
It appears as if the dot-product solution gives me the distance from my
point PERPENDICULAR to the tri -- so it's always the shortest distance,
but not the "drop" distance, in terms of "same XZ, what's the Y?"
And I haven't gotten the averaging ("interpolation") thing to work quite
the way I want it to, either, although I'm pretty sure that's the
correct solution.
--
Please take off your pants or I won't read your e-mail.
I will not, no matter how "good" the deal, patronise any business which
sends
unsolicited commercial e-mail or that advertises in discussion newsgroups.


|