papsphilip Posted December 9, 2020 Share Posted December 9, 2020 I have some randomly rotated grids in 3d space that i'd like to orient to the origin on XZ plane (flat on the ground) and have the longest edge align with the Z axis. How can i figure out each grid's transform and orient and reset it. Controlling the way it gets oriented (longest edge) is important for UVing later Quote Link to comment Share on other sites More sharing options...
animatrix Posted December 9, 2020 Share Posted December 9, 2020 Hi, One way would be like this: vector p0 = point ( 1, "P", 0 ); vector p1 = point ( 1, "P", 1 ); vector p2 = point ( 1, "P", 2 ); vector dir0 = p1 - p0; vector dir1 = p2 - p0; vector dir = dir0; if ( length2 ( dir1 ) > length2 ( dir0 ) ) dir = dir1; @P -= p0; vector n = primuv ( 1, "N", 0, 0.5 ); matrix3 m = maketransform ( normalize ( dir ), normalize ( n ) ); @P *= invert ( m ); 1 Quote Link to comment Share on other sites More sharing options...
tamagochy Posted December 9, 2020 Share Posted December 9, 2020 You can use this wrangle in foreach // Build Matrix From Edge int pts[] = neighbours(0,@ptnum); float dists[]; vector dirs[]; foreach(int pt; pts){ vector pos = point(0,"P",pt); vector dir = pos-@P; float dist = length(dir); append(dists,dist); append(dirs,normalize(dir)); } dirs = reorder(dirs,argsort(dists)); vector z = dirs[-1]; vector y = dirs[0]; vector x = cross(z,y); matrix m = set(x, y, z); translate(m,@P); 4@m = m; And then choose point 0 take matrix and make invert multiplication for the grid Quote Link to comment Share on other sites More sharing options...
papsphilip Posted December 9, 2020 Author Share Posted December 9, 2020 (edited) thank you! i m not sure if i implemented your methods correctly but they are not working orient planes.hip Edited December 9, 2020 by papsphilip spelling Quote Link to comment Share on other sites More sharing options...
tamagochy Posted December 10, 2020 Share Posted December 10, 2020 You forget to multiply for inverted matrix. orient planes_fix.hipnc Quote Link to comment Share on other sites More sharing options...
papsphilip Posted December 10, 2020 Author Share Posted December 10, 2020 almost there, one problem i see is that the plane normals are not all facing the same way. Also if i transform them at the origin can place them back at their original positions? orient plane.hip Quote Link to comment Share on other sites More sharing options...
tamagochy Posted December 11, 2020 Share Posted December 11, 2020 Yes normals can be in different directions, if you need one direction you can use normal vector in building matrix. orient plane_fix.hipnc Quote Link to comment Share on other sites More sharing options...
papsphilip Posted December 11, 2020 Author Share Posted December 11, 2020 4 hours ago, tamagochy said: Yes normals can be in different directions, if you need one direction you can use normal vector in building matrix. orient plane_fix.hipnc thanks a lot for the help, this was really usefull! Quote Link to comment Share on other sites More sharing options...
Recommended Posts
Join the conversation
You can post now and register later. If you have an account, sign in now to post with your account.
Note: Your post will require moderator approval before it will be visible.