MathGem:Height of a Point in a Triangle
From GPWiki
The wiki is now hosted by GameDev.NET at wiki.gamedev.net. All gpwiki.org content has been moved to the new server. However, the GPWiki forums are still active! Come say hello.
[edit] Height of a Point in a TriangleThis shows how to find the value of one component of a point in a triangle given the other two components. In this article, we find Z given X and Y, but this applies could apply to any component simply by swapping axis names. [edit] ProcedureGiven three vertices of a triangle, P, Q, and R, and x and y of the point,
Note: If Nz is 0, then the triangle is parallel to the Z axis and there is no unique z. [edit] Applications[edit] The Height of the TerrainOne instance where this is used is to find the height of the terrain at a particular location. Once the particular triangle at the location is found, the height of the object can be determined from the equation above.
It should be noted that if the vertices of the terrain are on an axis-aligned regular grid (such as a heightmap), the calculation of [edit] Color InterpolationAnother common application is interpolating the color of a point in a triangle in 2D given the colors at the vertices. In this case, the Z component is a color instead of a location. [edit] DerivationIf the point X:[x,y,z] is in the plane of the triangle, then the dot product of a vector, N perpendicular to the plane, and the vector (X - P) is 0. |
is simplified. Assuming that
is parallel to the X axis,
is parallel to the Y axis, and the distance between points in the grid is






