坐标系转换,将3d投影到2d平面 [英] Coordinate system transformation, 3d projection to 2d plane

查看:520
本文介绍了坐标系转换,将3d投影到2d平面的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个全局坐标系(X,Y,Z)和一个带点(A,B,C和中心)的三角形.我知道这些点的所有坐标.

I have a global coordinates system (X, Y, Z), and a triangle with points (A, B, C and Center). I know all coordinates of those points.

  1. 我需要将全局坐标系从(0; 0; 0)移至三角形中心,以便所有点:A,B,C和Center都将具有新的坐标,其中Z =0.之后,我需要知道与新坐标系的关系中这些点的新坐标.新坐标系的方向并不重要.
  2. 此外,如果有可能将3D点(三角形点)转换为2D平面而不会丢失其几何形状(大小).它不应该是2D平面的投影.

>> A=[10.63307; -7.72528; 21.26636];
B=[4.06139; -12.49988; 21.26636];
C=[-6.57172; -20.22529; 13.14344];
Centr=[-4.38113; -13.48349; 18.55872];

>> V1=(B-A)/(norm(B-A))

V1 =

   -0.8090
   -0.5878
         0

>> V2=((C-A)-(dot((C-A),V1)*V1))/(norm((C-A)-(dot((C-A),V1)*V1)))

V2 =

    0.0000
   -0.0000
   -1.0000

>> V3=cross(V1,V2)

V3 =

    0.5878
   -0.8090
    0.0000

>> M=[V1,V2,V3]

M =

   -0.8090    0.0000    0.5878
   -0.5878   -0.0000   -0.8090
         0   -1.0000    0.0000

>> Anew=inv(M)*(A-Centr)

Anew =

  -15.5313
   -2.7076
    4.1666

>> Bnew=inv(M)*(B-Centr)

Bnew =

   -7.4083
   -2.7076
    4.1666

>> Cnew=inv(M)*(C-Centr)

Cnew =

    5.7350
    5.4153
    4.1666

这就是我得到的: 从此

对此

推荐答案

问题可以表示为找到3×3矩阵M,以便可以在旧的点之间转换点P的坐标.坐标系(P_old,三行)和新坐标系(P_new,三行).这是一个仿射变换:

The problem can be expressed as finding the 3-by-3 matrix M such that the coordinates of a point P can be converted between the old coordinate system (P_old, 3 rows) and the new coordinate system (P_new, 3 rows). This is an affine transformation:

P_old = Center + M * P_new     (1)

M的(矩阵向量)相乘将其定向回旧系统,并添加Center的坐标将其转换回旧的原点.

The (matrix-vector) multiplication with M orientates it back to the old system, and adding Center's coordinates translates it back to the old origin.

等式(1)然后可以变成:

The equation (1) can then be turned into:

P_new = M^{-1} * (P_old - Center)     (2)

其中M^{-1}M的倒数,用于根据旧坐标计算新坐标(如果该点属于三角形的平面,则第三行的坐标为0).

where M^{-1} is the inverse of M, to compute the new coordinates from the old ones (the third row will have a 0 if the point belongs to the plane of the triangle).

矩阵M由旧系统中新基准的坐标组成,每列中都有一个基准向量.现在必须找到这样的基础.

The matrix M is made of the coordinates of the new basis in the old system, one basis vector in each column. One must now find such a basis.

此依据可取自(这都是伪代码):

This basis can be taken from (this is all pseudo-code):

  1. 重新规范化AB

       AB
V1 = ______
    || AB ||

  • AB在这里是指向量AB(顶部带有箭头):

    • AB here is meant as the vector AB (with an arrow on top):

      |b_x - a_x|
      |b_y - a_y|
      |b_z - a_z|
      

    • || . ||是欧几里得范数(^2表示平方,而不是 xor ):

    • || . || is the Euclidian norm (^2 means the square, not xor):

      || V || = sqrt(V_x^2 + V_y^2 + V_z^2)
      

    • AC(也是一个向量,定义与AB相似),但是减去在V1上的投影以使其与V1正交,然后重新归一化(如果除以零,则失败)三角形不是真正的三角形):

      AC (also a vector, defined like AB), but minus its projection on V1 to make it orthogonal to V1, and renormalized (this will fail with a division by zero if the triangle is not really a triangle):

              AC - (AC.V_1) V1
      V2 = _______________________
           || AC - (AC.V_1) V1 ||
      

      • M.N是标量积:

        • M.N is the scalar product:

          M.N = M_x * N_x + M_y * N_y + M_z * N_z
          

        • (AC.V_1) V1只是标量(AC.V_1)与矢量V1

        • (AC.V_1) V1 is simply the product of a scalar, (AC.V_1), with a vector, V1

          第三个向量,可以将其用作获得笛卡尔坐标系的叉积:

          A third vector that can be taken as the cross product to get a Cartesian coordinate system:

          V3 = V1 x V2
          

          • 叉积定义为:

            • The cross product is defined as:

                        |V1_y*V2_z - V1_z*V2_y|
              V1 x V2 = |V1_z*V2_x - V1_x*V2_z|
                        |V1_x*V2_y - V1_y*V2_x|
              

            • 那么M可以取为|V1 V2 V3|(每个Vx在3行上),然后将其逆值计算为使用公式(2).

              Then M can be taken as |V1 V2 V3| (each Vx is on 3 rows) and, then its inverse computed to use formula (2).

              此变换(带有倒M)都应为三角形平面上在第三轴上具有0的点(使其在该平面上为2D坐标)生成新的坐标,并保留大小欧几里得准则.

              This transformation (with the inverted M) should both generate new coordinates for the points on the plane of the triangle that have 0 on the third axis (which makes it 2D-coordinates on that plane), and preserve the size in terms of Euclidian norm.

              这篇关于坐标系转换,将3d投影到2d平面的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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