Calculate Y of 3D point on 3D QUAD PLANE based on X,Z in that point

前端 未结 1 595
天涯浪人
天涯浪人 2020-12-22 11:16

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 po

相关标签:
1条回答
  • 2020-12-22 11:48

    plane equation

    (a*x)+(b*y)+(c*z)=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. get the normal n

      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|;
      

      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

    2. get the d constant

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

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

      or the same can be written as:

      d=dot(n,p0);
      
    3. now how to compute e.y from e.x,e.z ?

      e.y=(d-(n.x*e.x)-(n.z*e.z))/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

    4. basis vectors (n.y==0)

      quad with n.y==0

      so compute basis vectors

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

      now any point on plane is defined as:

      p=p0+(bu*u)+(bv*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:

      • p0 is u=0,v=0
      • p1 is u=1,v=0
      • p3 is u=0,v=1

      we need equations like:

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

      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);
      

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

    [notes]

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

    0 讨论(0)
提交回复
热议问题