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.


|