I have three vertices of a triangle : (x1,y1,z1); (x2,y2,z2); (x3,y3,z3). Basically, I want to transform these 3 vertices onto an XY plane such that vertices look like (0,0); (c,d); (e,f).
Once, I get the points on XY Plane, I would generate some sampling points using 2D Sampling algorithms.Then, I apply the inverse transform to these sampling points, call it as :(l,m,0) and transform it back to 3D(something, like (q,w,t)).
I would be really glad if Some can help me with functions like: Transform(), which takes 3D Vertices as inputs and converts it into 2D(XY PLane) points.
InverseTransform(), which takes 2D points as inputs and converts it into 3D(XYZ PLane) points.
Thanks in Advance!
答案 0 :(得分:1)
修改:完全重写
您可以找到以(0,0,0); (c,0,0); (e,f,0)
形式转换3D点的仿射矩阵(注意y=0
为第二点)。
首先,将所有点移动(-x1,-y1,-z1)
,因此我们得到坐标原点的第一个点。其他两个顶点的新坐标为Bx,By,Bz,Cx,Cy,Cz
,其中Bx=x2-x1
等等(向量 B 和 C )。
然后跟随必须的旋转:
1)将B点转换为OX
轴上的点,Lb
为向量长度 B 。
Bx,By,Bz => Lb,0,0
2)将三角形的法线变换为与OZ轴共线的矢量。
N = B x C //cross product
Ln = Length(N)
Nx,Ny,Nz => 0,0,Ln
3)一段时间我不清楚:)
将源标准正交基的第三矢量转换为与OY轴共线的矢量
P = B x N
Lp = Length(P)
Px,Py,Pz => 0,Lp,0
全部收集:
[Bx Nx Px] [Lb 0 0]
RotMatrix * [By Ny Py] = [0 0 Lp]
[Bz Nz Pz] [0 Ln 0]
或更短
RotMatrix * BNP = L
所以我们可以找到
RotMatrix = L * Inverse(BNP)
最后
AffineMatrix = ShiftMatrix * RotMatrix
但你为什么需要这样的转变呢?
也许只需在初始位置对三角形点进行采样就像这样(trilinear coordinates):
for u = 0 to N //sampling level
for v = 0 to N - u
w = N - u - v
p = GetPoint(Vertices, u/N, v/N, w/N)