[Solved] - Getting the height of a coordinate inside triangle.
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]
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;
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;
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!
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!
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement