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: Altitude of...
Latest [ Topics | Posts ] Archive Post A New Topic Post a Reply
<< Topic < Post Post 3 of 17 Topic 581 of 680
Post > Topic >>

Re: Altitude of a point in a triangle

by Miss Elaine Eos <Misc@[EMAIL PROTECTED] > Sep 14, 2006 at 11:04 PM

In article <EtydnYWsIOD1J5TYnZ2dnUVZ_sidnZ2d@[EMAIL PROTECTED]
>,
 Erik Max Francis <max@[EMAIL PROTECTED]
> wrote:

> Miss Elaine Eos wrote:
> > I have a triangle that represents a bit of terrain mesh -- that is,
the 
> > triangle is NOT vertically aligned.  It's made of points A, B, C, each

> > point having an XYZ (so there's Ax, Ay, Az...)  I have a 4th point
(P), 
> > that I've already determined has X/Z coordinates inside the triangle
-- 
> > that is, if I set everything's Y to 0, T(ABC) contains P.  I can get
the 
> > distance2d between points, and I know that what I want to do to get
the 
> > Y coordinate of P is some sort of averaging, but I can't seem to quite

> > figure out what values to average, how.
> 
> It's not clear to me from your description what you're looking for. 
> _Altitude_ is probably not the right word based on your description, but

> your description isn't precise enough to know what you want.  Are you 
> just saying you want the y-coordinate of your fourth point P to be the 
> average of the y-coordinates of points A, B, and C?  If so, just average

> them:  p_y = (a_y + b_y + c_y)/3.
> 
> If you mean something else, you're going to have to define it more
clearly.

I thought that altitude would be clear from my description that it's a 
terrain mesh.  The implication is that my triangles are laid out on an 
XZ grid, with their corners at various "altitudes" (Ys).

The formula you give tells me the altitude at the point that's in the 
exact center of the triangle.  The thing I'm wrestling with is how to 
average the 4th point ANYWHERE within (XZ-wise, that is) the triangle.

What I came up with so far is below and, while it seems right on 
code-review, it's giving me "funny looking" results (they seem too high).

The general idea of this code is to:

* Find the triangle that encloses xx/zz
* Get the altitudes of that triangle's 3 corners
* Find the distance from xx/zz to each of the corners
* Do a sort of weighted averaging, counting a corner's alt more, the 
closer xx/zz is to it.

   public   double   getAltitude (double xx, double zz)
   {
      double         u***     = xx + gridOffset;                     // 
move XZ to grid coordinates
      double         useZ     = zz + gridOffset;
      BinaryTriangle innerTri = findInnerTriangle (bTri1, u***, useZ);
      if (innerTri == null)
         innerTri          = findInnerTriangle (bTri2, u***, useZ);

      if (innerTri == null)                                       // XZ 
is not within our grid
         return (0);

      // Now we have the triangle which contains my XZ point
      // gather the distance to each corner & total
      double         totalDist   = 0;
      double []      dists    = new double [3];
      for (int ii = 0 ; ii < 3 ; ++ii)
      {
         dists [ii]  = ToglUtils.calcDistance (xx - 
innerTri.corners[ii][0], zz - innerTri.corners[ii][1]);
         totalDist   += dists [ii];
      }

      // average this point from those
      double   theAlt   = 0;
      for (int ii = 0 ; ii < 3 ; ++ii)
      {
         double   thisAlt  = altitudes [innerTri.corners[ii][0]] 
[innerTri.corners[ii][1]];     // alt at corner
         double   nearPct  = 1.0 - (dists[ii] / totalDist);             
// "nearPct" = 1 - distancePct.
         theAlt   += thisAlt * nearPct;
      }

      return (theAlt / 1000.0);                                   // div 
1000 to give result in mm
   }

-- 
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.
 




 17 Posts in Topic:
Altitude of a point in a triangle
Miss Elaine Eos <Misc@  2006-09-14 17:10:54 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-14 13:24:04 
Re: Altitude of a point in a triangle
Miss Elaine Eos <Misc@  2006-09-14 23:04:33 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-14 17:01:36 
Re: Altitude of a point in a triangle
"Alfie [UK]" &l  2006-09-15 02:04:43 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-15 13:49:39 
Re: Altitude of a point in a triangle
Miss Elaine Eos <Misc@  2006-09-15 01:12:41 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-15 13:49:09 
Re: Altitude of a point in a triangle
Tom Plunket <gamedev@[  2006-09-21 16:26:51 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-22 15:22:10 
Re: Altitude of a point in a triangle
Tom Plunket <gamedev@[  2006-09-23 19:12:17 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-23 19:22:19 
Re: Altitude of a point in a triangle
Tom Plunket <gamedev@[  2006-09-24 12:54:02 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-24 21:33:53 
Re: Altitude of a point in a triangle
Tom Plunket <gamedev@[  2006-09-25 14:28:47 
Re: Altitude of a point in a triangle
Erik Max Francis <max@  2006-09-25 15:58:10 
Re: Altitude of a point in a triangle
Miss Elaine Eos <Misc@  2006-09-15 01:04:18 

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:34:50 CDT 2008.