ATD
ATD

Reputation: 894

How to find y at given point (x,z) on 3D triangle?

In a coordinate system where y is up/down, z is forward/backwards, x is left/right (as in Unity3D).


(Here's a bad drawing of what I mean)

y
|
|____x
\
z

(z would be going into/out of your monitor I guess)


Given coordinate (x,z) that is guaranteed to be on this triangle, how would I get y? Assume that you know the (x,y,z) coordinates of all three triangle points, as well as the normal of the face. The triangle may be slanted on any axis.

Upvotes: 2

Views: 1538

Answers (1)

Steven Hansen
Steven Hansen

Reputation: 3239

Well, given any Vector v inside your triangle, and your normal n, we know that the dot product of n and v equals 0 (true for all points on the triangle). So:

nx * vx + ny * vy + nz * vz = 0

Little algebra to solve for vy and we have:

vy = -((nz * vz) + (nx * vx)) / ny

One thing though. v must be in the plane of your triangle, so you will need to put that vector in the plane of your triangle, by subtracting one of your vertices (say t1) from v.

So:

vx = t1x - x, vz = t1z - z, and vy = t1y - y

And therefore, your final y coordinate is: y = t1y - vy where vy is defined above.

Upvotes: 4

Related Questions