Talk About Network

Google


Register and Login
Nick
Password
Register create new account Sign up is FREE and you can post replies, new topics, bookmark posts and more!
Recover lost password


Gaming > Development Programming Algorithms > Re: How to tell...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 6 of 8 Topic 579 of 680
Post > Topic >>

Re: How to tell if a 4th pt is coplanar with the other 3.

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Sep 18, 2006 at 05:22 AM

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.
 




 8 Posts in Topic:
How to tell if a 4th pt is coplanar with the other 3.
Miss Elaine Eos <Misc@  2006-09-12 02:02:45 
Re: How to tell if a 4th pt is coplanar with the other 3.
Erik Max Francis <max@  2006-09-11 19:49:21 
Re: How to tell if a 4th pt is coplanar with the other 3.
Miss Elaine Eos <Misc@  2006-09-14 02:39:45 
Re: How to tell if a 4th pt is coplanar with the other 3.
Erik Max Francis <max@  2006-09-13 19:53:00 
Re: How to tell if a 4th pt is coplanar with the other 3.
Tom Plunket <gamedev@[  2006-09-17 17:58:10 
Re: How to tell if a 4th pt is coplanar with the other 3.
Miss Elaine Eos <Misc@  2006-09-18 05:22:24 
Re: How to tell if a 4th pt is coplanar with the other 3.
Tom Plunket <gamedev@[  2006-09-21 15:56:32 
Re: How to tell if a 4th pt is coplanar with the other 3.
Miss Elaine Eos <Misc@  2006-09-22 01:59:40 

Post A Reply:
  Go here to Signup

AddThis Feed Button


About - Advertising - Contact - Frequently Asked Questions - Privacy Policy - Terms of Use - Signup

Contact
tan12V112 Fri Jul 25 19:22:57 CDT 2008.