# [Solved] - Getting the height of a coordinate inside triangle.

This topic is 4236 days old which is more than the 365 day threshold we allow for new replies. Please post a new topic.

## Recommended Posts

I'm using a triangle list wich defines a walkpath for a character, currentlly it works fine for a flat surface path (checks if the character XZ-pos is inside a triangle). But I can't find out how I could get the height of this position that's inside the 3 points of the triangle. How would I be able to find the Y (height) coordinate when given XZ coordinates that is inside a triangle? [Edited by - R3D on December 12, 2006 12:41:54 PM]

##### Share on other sites
Hey,

p = One Point of triangle
normal = triangleNormal
dir = Vector.Set(0,1,0); //upvector
pos = Vector.Set(x,0,z);

//Get IntersectionPoint between plane and dirvector
float top = pos-p;
top = DotProduct(top, normal)
float bottom = DotProduct(dir, normal);

return (top/bottom);

Depending on direction of the triangle normal you might need to multiply the result with -1;

##### Share on other sites
Using the plane equation Ax + By + Cz = D, just solve for 'y'. D will be the distance along your plane normal from the origin to your triangle:

N = normal
V = a triangle vertex
P = point to check

y = (Dot(N,V) - (N.x*P.x) - (N.z*P.z)) / N.y;

Note that when N.y is 0, this process fails, but that's also the case when your triangle is completely vertical!

##### Share on other sites

Zipster, thanks alot, that seems to be working perfect on the moment for me.

Yeah, I was a bit expecting a possible problem when a triangle should be vertical, though for this case I don't think I will let the character walk vertical onto a wall. :)

1. 1
2. 2
Rutin
23
3. 3
JoeJ
20
4. 4
5. 5
gaxio
13

• 24
• 40
• 23
• 13
• 13
• ### Forum Statistics

• Total Topics
631734
• Total Posts
3001933
×