Sign in to follow this  
R3D

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

Recommended Posts

R3D    122
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 this post


Link to post
Share on other sites
Exilberliner    122
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 this post


Link to post
Share on other sites
Zipster    2359
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 this post


Link to post
Share on other sites
R3D    122

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

Share this post


Link to post
Share on other sites

Create an account or sign in to comment

You need to be a member in order to leave a comment

Create an account

Sign up for a new account in our community. It's easy!

Register a new account

Sign in

Already have an account? Sign in here.

Sign In Now

Sign in to follow this