getting the height
ok here it goes
i want to find out the y value at a point (x, z) in a triangle
knowing the three vertices
i tried using a deteriminant but i get division by 0
| x - x0 y - y0 z - z0|
|x1 - x0 y1 - y0 z1 - z0| = 0
|x2 - x1 y2 - y1 z2 - z1|
also i dont know how to find the d value for the plane eq
/*ilici*/
The plane equation is easy. Calculate the triangle normal, (N.x, N.y, N.z), using the cross product of two edges. The plane equation is the following:
N.x*x + N.y*y + N.z*z + d = 0
Now that you know (Nx, Ny, Nz), you can calculate d by just plugging in one of the vertices of the triangle, say vertex v0 = (v0.x, v0.y, v0.z). So,
d = -N.x*v0.x - N.y*v0.y - N.z*v0.z
Now you know everything in the plan equation. If you want to then calculate the value of y at a given (x, z), just solve the plane equation for y:
y = -(N.x*x + N.z*z + d)/N.y
Just plug in x and z, along with (N.x, N.y, N.z) and d that you already calculated. As long as the triangle is not perpendicular to the y axis, this will work fine. If the triangle *is* perpendicular to the y axis, then there is not a single value of y that works (many of values work, but only if your (x, z) line up with the triangle in the (x, z) plane.
Of course, before you can find the value of y in the triangle, you need to be sure that (x, z) actually do lie within the triangle. Please refer to the forum FAQ for this. There is a web link that discusses point-in-polygon tests.
Forum FAQ
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
N.x*x + N.y*y + N.z*z + d = 0
Now that you know (Nx, Ny, Nz), you can calculate d by just plugging in one of the vertices of the triangle, say vertex v0 = (v0.x, v0.y, v0.z). So,
d = -N.x*v0.x - N.y*v0.y - N.z*v0.z
Now you know everything in the plan equation. If you want to then calculate the value of y at a given (x, z), just solve the plane equation for y:
y = -(N.x*x + N.z*z + d)/N.y
Just plug in x and z, along with (N.x, N.y, N.z) and d that you already calculated. As long as the triangle is not perpendicular to the y axis, this will work fine. If the triangle *is* perpendicular to the y axis, then there is not a single value of y that works (many of values work, but only if your (x, z) line up with the triangle in the (x, z) plane.
Of course, before you can find the value of y in the triangle, you need to be sure that (x, z) actually do lie within the triangle. Please refer to the forum FAQ for this. There is a web link that discusses point-in-polygon tests.
Forum FAQ
Graham Rhodes
Senior Scientist
Applied Research Associates, Inc.
Graham Rhodes Moderator, Math & Physics forum @ gamedev.net
This topic is closed to new replies.
Advertisement
Popular Topics
Advertisement
Recommended Tutorials
Advertisement