根据该点的 X、Z 计算 3D QUAD PLANE 上 3D 点的 Y [英] Calculate Y of 3D point on 3D QUAD PLANE based on X,Z in that point

查看:29
本文介绍了根据该点的 X、Z 计算 3D QUAD PLANE 上 3D 点的 Y的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

假设我有一个平面 3D Quad(a、b、c、d 3D 顶点)并且我知道 3D 点 e:e.x 和 e.z 在该 Quad 的范围内,我将如何计算 e.y ?我已经尝试了几种可能的解决方案,但无法让它发挥作用.

Assuming I have a planar 3D Quad (a,b,c,d 3D vertices) and I know 3D point e: e.x and e.z are within the bound of that Quad, how would i compute e.y ? I've tried several possible solutions but just can't get it to work.

感谢您的帮助.

推荐答案

平面方程

(a*x)+(b*y)+(c*z)=d;

其中 n=(a,b,c) 是平面的法向量,因此要构建平面方程,您需要 a,b,c,d 常量:

Where n=(a,b,c) is normal vector to plane so to construct your plane equation you need a,b,c,d constants:

  1. 得到正常的n

两个非平行向量的叉积的结果是垂直于每个向量的向量.因此,将四边形的两条边作为向量.进行叉积并将其归一化为单位向量.这为您提供了法线向量 n.所以如果你的四边形是由顶点定义的 p0,p1,p2,p3 那么

result of cross product of two non parallel vectors is vector perpendicular to each one. So take two edges of your quad as vectors. Make the cross product and normalize it to unit vector. That gives you normal vector n. So if your Quad is defined by vertexes p0,p1,p2,p3 then

n=cross(p1-p0,p2-p1);
n=n/|n|;

希望你知道向量的叉积和绝对值的方程,如果没有,那么谷歌.现在 3D 矢量 n 的坐标保存了你的 a,b,c 常量

hope you know the equations for cross product and absolute value for vectors if not then google. Now the coordinates of 3D vector n holds your a,b,c constants

获取d常量

get the d constant

简单地得到平面上的任何点并导出d,例如:

simply get any point on plane and derive d for example:

d=(n.x*p0.x)+(n.y*p0.y)+(n.z*p0.z);

也可以写成:

d=dot(n,p0);

  • 现在如何从 e.x,e.z 计算 e.y ?

  • now how to compute e.y from e.x,e.z ?

    e.y=(d-(n.x*e.x)-(n.z*e.z))/n.y;
    

    仅当 n.y 为非零时才有效.如果确实为零,则必须使用基向量而不是平面方程

    this works only if n.y is non-zero . If it is indeed zero then you have to use basis vectors instead of plane equation

    基向量(n.y==0)

    所以计算基向量

    bu=p1-p0;
    bv=p3-p0;
    

    现在平面上的任何点都定义为:

    now any point on plane is defined as:

    p=p0+(bu*u)+(bv*v);
    

    其中 u,v 是标量(表示单个数字而不是向量)平面坐标,bu,bv 是基向量.现在您需要计算 x,z 坐标和 u,v 的依赖关系,我们现在:

    where u,v are scalar (means single number not vector) plane coordinates and bu,bv are the basis vectors. Now you need to compute the dependency of x,z coordinates and u,v we now that:

    • p0u=0,v=0
    • p1u=1,v=0
    • p3u=0,v=1
    • p0 is u=0,v=0
    • p1 is u=1,v=0
    • p3 is u=0,v=1

    我们需要这样的方程:

    u=u0+(ux*x)+(uz*z);
    v=v0+(vx*x)+(vz*z);
    

    所以我们需要计算常数:u0,ux,uy,v0,vx,vy 所以替换 3 个点,导致:

    so we need to compute constants: u0,ux,uy,v0,vx,vy so substitude the 3 points which leads to:

    0=u0+(ux*p0.x)+(uz*p0.z);
    0=v0+(vx*p0.x)+(vz*p0.z);
    1=u0+(ux*p1.x)+(uz*p1.z);
    0=v0+(vx*p1.x)+(vz*p1.z);
    0=u0+(ux*p3.x)+(uz*p3.z);
    1=v0+(vx*p3.x)+(vz*p3.z);
    

    解决该系统,这就是您所需要的.现在为点 e 计算 u,v 然后从 u,v

    solve that system and that is all you need. Now compute u,v for point e then compute e.y from u,v

    [注释]

    Bullet #4 适用于所有非平凡四边形,而不仅仅适用于 n.y==0 情况

    Bullet #4 works for all nontrivial quads not just for n.y==0 case

    这篇关于根据该点的 X、Z 计算 3D QUAD PLANE 上 3D 点的 Y的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

  • 查看全文
    登录 关闭
    扫码关注1秒登录
    发送“验证码”获取 | 15天全站免登陆