0

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!

gorkem
  • 731
  • 1
  • 10
  • 17
Math_Enthusiast
  • 155
  • 1
  • 14
  • What have you tried? I mean it reads to me like you wanna ignore the z axis and just take the xy and return it as a point.. so.. whats stopping you from writing something to do that – BugFinder Jan 11 '18 at 08:52
  • sorry,just edited it! Its like,one of the vertex should be transformed to origin and other two 3D Points will be like: (a,b) and (c,d) – Math_Enthusiast Jan 11 '18 at 08:54
  • You should read all about linear algebra – Passer By Jan 11 '18 at 09:03
  • you need `1:1` mapping instead `N:1` projection because once you project your 3D points onto plane you can not go back to the original 3D coordinates. However mapping will most likely not enable using 2D interpolations or what ever you want to do as `1:1` mappings from 3D to and from 2D is usually not continuous and breaks any geometric features applied in the other dimensionality. Your best bet would be to change your 2D stuff you want to apply to 3D. Without knowing what it is we can not decide if possible or not (even if you claim is not possible that does not mean it really isn't). – Spektre Jan 11 '18 at 09:41
  • If you want just 3D planar points after transformation back than that is easy just use basis vectors and origin point of the plane to convert between 2D and 3D. It is simpler than it sounds see [C++ plane interpolation from a set of points](https://stackoverflow.com/a/45431861/2521214) and [Calculate Y of 3D point on 3D QUAD PLANE based on X,Z in that point](https://stackoverflow.com/a/27166057/2521214) – Spektre Jan 11 '18 at 09:56

1 Answers1

1

Edit: Full rewriting

You can find affine matrix that transform 3D points in (0,0,0); (c,0,0); (e,f,0) form (note y=0 for the second point).

At first, shift all points by (-x1,-y1,-z1), so we have the first point in coordinate origin. New coordinates of two other vertices are Bx,By,Bz,Cx,Cy,Cz where Bx=x2-x1 and so on (vectors B and C).

Then follows rotation that must:

1) Transform B point into point on OX axis, where Lb is Length of vector B.

 Bx,By,Bz => Lb,0,0 

2) Transform normal of triangle into vector collinear to OZ axis.

 N = B x C  //cross product
 Ln = Length(N)
 Nx,Ny,Nz => 0,0,Ln

3) It was unclear for me for some time:)
Transform the third vector of source orthonormal basis into vector collinear to OY axis

P = B x N  
Lp = Length(P)
Px,Py,Pz => 0,Lp,0

Collecting all together:

             [Bx  Nx  Px]    [Lb  0  0]
 RotMatrix * [By  Ny  Py] =  [0   0  Lp]
             [Bz  Nz  Pz]    [0  Ln  0]

or shorter

RotMatrix * BNP = L

so we can find

 RotMatrix  = L * Inverse(BNP)

and finally

AffineMatrix = ShiftMatrix * RotMatrix

But why do you need such transformations?

Perhaps it is enough to sample triangle points in initial position like this (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)
MBo
  • 77,366
  • 5
  • 53
  • 86
  • Sampling is not my main thing...I have some different sampling algorithms,which work only on 2D And not in 3D. Cant we find affine matrix that transforms 3D Points to (0,0) ; (a,b) and (c,d)? – Math_Enthusiast Jan 11 '18 at 09:08
  • And I gave you example of 3D sampling – MBo Jan 11 '18 at 09:16
  • @MB0: you are right! can you please write the algorithm for transforming the 3D Vertices to (0,0) ; (c,0) and (e,f)?? – Math_Enthusiast Jan 11 '18 at 09:26
  • I think,its [[x2',y2',z2'],[x3',y3'z3']] * Mrot = [[Length12,0,0][someX,someY,0]] right?? bcoz, M = M = Mshift * Mrot. – Math_Enthusiast Jan 11 '18 at 10:49
  • It (solving of equation system for unknowns angles) is right in general, but we already know some angles. that is why I removed such approach (point pairs) – MBo Jan 11 '18 at 11:01
  • its really confusing now :( :(..Question1: r u providing points in the form of (0,0,0);( a,0,0),(d,e,0) (OR) (0,0,0);( a,b,0),(d,e,0) ?? Question2: Can you please expalin,which procedure i need to use now? How do I determine Alpha in Case 1?? How did u find Beta angle,since we dont know "length12"?? – Math_Enthusiast Jan 11 '18 at 11:07
  • Basically,In terms of CSharp,I need functions like this: Transform3DTo2D(List> 3D Vertices, List> 2D Vertices) and also InverseTransform2DTo3D(List> 2D Points, List> 3D Points)..Note that, the function Transform3DTo2D takes only 3D Vertices as inputs and gives 2D Vertices as output..But the function InverseTransform2DTo3D Takes 2D Points as input and gives 3D Points as output..would be really glad,if u can provide this. – Math_Enthusiast Jan 11 '18 at 11:23
  • In the algorithm u posted, what does "-atan2" exactly mean? is it the same function as of, -arcTan?? can you plz explain in detail – Math_Enthusiast Jan 12 '18 at 00:42
  • I realized how to apply "pair points" method here. See edit. – MBo Jan 12 '18 at 10:36
  • I now have 2 queries in your new edit.So,now,we dont have to find alpha,beta and gamma angles again right? As,we are getting the Product of rotation matrices(Rz*Ry*Rx) diectly?? Also, finally, how do the coordinates look like? in form of (0,0,0); (a,0,0) and (d,e,0) (Or) some other form? Also, are you sure about formula, AffineMatrix = ShiftMatrix * RotMatrix?? I think,it should be AffineMatrix = ShiftMatrix + RotMatrix. Is n't it? Suppose,now if we retrieve the points in the form of (0,0,0);(a,0,0) and (e,f,0), if i find some internal point in triangle,how do I apply inverse transformation? – Math_Enthusiast Jan 13 '18 at 02:21
  • Yes, we don't need angles, and RotMatrix is essentially product of all rotations. AffineMatrix is product, not sum. Form (0,0,0);(a,0,0) and (e,f,0) is for vertices, other points are (x,y,0). To get inverse transform, calculate inverse of AffineMatrix. – MBo Jan 13 '18 at 04:01