[英]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). 在y为上/下,z为前/后,x为左/右的坐标系中(与Unity3D相同)。
(Here's a bad drawing of what I mean) (这是我意思的不好描述)
y ÿ
| |
| | _ __ _x _ __ _x
\\ \\
z ž
(z would be going into/out of your monitor I guess) (我想z会进入/离开您的显示器)
Given coordinate (x,z) that is guaranteed to be on this triangle, how would I get y? 给定坐标(x,z)保证在这个三角形上,我将如何获得y? Assume that you know the (x,y,z) coordinates of all three triangle points, as well as the normal of the face. 假设您知道所有三个三角形点的(x,y,z)坐标以及人脸的法线。 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). 好吧,给定三角形内的任何向量v
以及法线n
,我们知道n
和v
的点积等于0(对于三角形上的所有点均为true)。 So: 所以:
nx * vx + ny * vy + nz * vz = 0
Little algebra to solve for vy
and we have: 解决vy
小代数,我们有:
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
. v
必须在三角形的平面内,因此您需要通过从v
减去一个顶点(例如t1
),将矢量放入三角形的平面内。
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. 因此,最终的y坐标为: y = t1y - vy
其中vy
在上面定义。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.