简体   繁体   中英

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.

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM