Exomondo 122 Report post Posted August 2, 2007 Hello, I have a series of points in 3D space (actually a planar graph), they share a common plane, however that plane is not parallel to any axis. How would i go about translating these points so that the plane that they share would be one of the axis? I figure i can at least determine the normal of that plane by using 3 of the points on the graph, but im not sure how i would translate the points to the axis plane. Any help would be great! Thanks! 0 Share this post Link to post Share on other sites
stevenmarky 369 Report post Posted August 2, 2007 I'm not great with math but one way is to build a matrix and then apply it to all the vertices.The x-axis of the matrix can be made from normalising the position of one point and ignoring it's y-component.The z-axis of the matrix can be made from getting the cross product of three of the points.The y-axis will be 0,1,0 because the transformation will not affect the y-component.If you multiply by this matrix it should translate your points into the correct position.You may need to make this matrix negative before you multiply..sorry I'll check and get back to you on this.A much easier way is just to set one of the components to 0, say the z component.You could then use the x location of the last point to scale the graphs width.Edit: I assumed the graph was parallel to at least one axis, otherwise it isn't possible to solve. i.e. I assumed the y component of the cartesian graph is 0 at the worlds y=0. 0 Share this post Link to post Share on other sites
Exomondo 122 Report post Posted August 2, 2007 Quote:Original post by stevenmarkyEdit: I assumed the graph was parallel to at least one axis, otherwise it isn't possible to solve. i.e. I assumed the y component of the cartesian graph is 0 at the worlds y=0.Ah...No, the graph is not parallel to any axis.Surely there is a way to create a matrix to transform the points to be parallel to an axis since i can get the normal of the coplane though?[Edited by - Exomondo on August 2, 2007 3:41:16 AM] 0 Share this post Link to post Share on other sites
erissian 727 Report post Posted August 2, 2007 You need to use the normal of the plane, which fortunately can be defined by those three points.Say you have the position vectors of the points, A, B, and C.(B-A) X (C-A) = Nnormal(N) is then your axis.The caveat is that if you don't choose the same ordering, you can end up with the inverse of the axis you had intended.Anyways, you can work out the rotation required to transform that normal to the axis you prefer, and apply that same rotation to all three points.Edit: I'm really not sure what your question was, so I'm guessing at what you want. Could you rephrase it more clearly?[Edited by - erissian on August 2, 2007 3:06:55 AM] 0 Share this post Link to post Share on other sites
ToohrVyk 1595 Report post Posted August 2, 2007 You cannot make the points coplanar in an axis plane by translating them, because translation keeps the destination plane parallel to the origin plane.The simplest way to transform the points so that they're in a plane which is parallel to an axis plane is to project them. The matrix for this (RHW 4x4 transform matrix) is:1 0 0 00 1 0 00 0 0 0 0 0 0 1This will place all points in the plane (x,y). 0 Share this post Link to post Share on other sites
D_Tr 362 Report post Posted August 2, 2007 Quote:How would i go about translating these points so that the plane that they share would be one of the axis?So you mean you want your points to lie on a plane which is defined by any two of the axes?If that's the case, you need to find an angle and axis of rotation for your points. I would try to do the following (I 'm not sure this is exactly right but it should be in the right direction):-Edit: ThoorVyk's solution of projecting is actually much easier and faster but does not maintain the distances between the points. If you don't care about maintaining the distances, better use ThoorVyk's solution.You have:a) the normal of the plane that is shared by your points andb) the normal of the plane you want them to lie to (if its the x-y plane then its normal is (0, 0, 1)).You take the dot product of these two normals and you have the cosine of the angle by which you need to rotate.Then you take the cross product of these two normals, normalize it and get the axis around you need to rotate.Then , having the angle angle and axis A, by which you need to rotate, you constrict a 3x3 rotation matrix from A and angle, using the following codeSqMat3 CMRotationMatrix3(const Vec3 &A, Float32 angle){ Float32 c = Cos(angle); Float32 s = Sin(angle); Float32 oneMinusC = 1 - c; Float32 AxAy = A.x * A.y; Float32 AxAz = A.x * A.z; Float32 AyAz = A.y * A.z; Float32 sAx = s * A.x; Float32 sAy = s * A.y; Float32 sAz = s * A.z; Float32 oneMinusCAxAy = oneMinusC * AxAy; Float32 oneMinusCAxAz = oneMinusC * AxAz; Float32 oneMinusCAyAz = oneMinusC * AyAz; return SqMat3(c + oneMinusC * A.x * A.x, oneMinusCAxAy - sAz, oneMinusCAxAz + sAy, oneMinusCAxAy + sAz, c + oneMinusC * A.y * A.y, oneMinusCAyAz - sAx, oneMinusCAxAz - sAy, oneMinusCAyAz + sAx, c + oneMinusC * A.z * A.z);};And finally you multiply all your points with this matrix.-EDIT: if for some reason you want to rotate around a point other than the origin (for example around the center of the points), you must subtract the point around which you want to rotate from your points, multiply with the matrix and then add it back. 0 Share this post Link to post Share on other sites
stevenmarky 369 Report post Posted August 2, 2007 Quote:Original post by ExomondoQuote:Original post by stevenmarkyEdit: I assumed the graph was parallel to at least one axis, otherwise it isn't possible to solve. i.e. I assumed the y component of the cartesian graph is 0 at the worlds y=0.Ah...No, the graph is not parallel to any axis.Surely there is a way to create a matrix to transform the points to be parallel to an axis since i can get the normal of the coplane though?Sorry I presumed you would want the data parallel to more than one axis (I didn't read your original post well enough) since how useful is a graph when you don't know what the rotation around the z-axis is? Imagine your cartesian graph is in world space as three points (0, 5, 0) (1, 6, 0) (2, 7, 0) - it looks like y=x+5. Looking at this it would be impossible to determine it was in fact the 2d cartesian graph y=5 with its axis rotated.ToohrVyk explained my second method, except much better than I. :-)Edit: points are in (x, y, z) form. 0 Share this post Link to post Share on other sites
Exomondo 122 Report post Posted August 3, 2007 Thanks for the help guys, ill look into those solutions. Exceptional explanations from all of you, very much appreciated.What i have is a planar graph (in 3D) and i have xyz coordinates for every point. The issue is that the coplane is not parallel to any axis, and unfortunately thats what i need.[Edited by - Exomondo on August 3, 2007 2:09:47 AM] 0 Share this post Link to post Share on other sites
Zipster 2359 Report post Posted August 3, 2007 It's worth noting that projecting the points onto one of the axial planes won't maintain the same distances between them. So if that's important you would need to actually rotate the points. 0 Share this post Link to post Share on other sites
Exomondo 122 Report post Posted August 3, 2007 Quote:Original post by ZipsterIt's worth noting that projecting the points onto one of the axial planes won't maintain the same distances between them. So if that's important you would need to actually rotate the points.Yes that was one of my concerns. 0 Share this post Link to post Share on other sites