Jump to content

orient grids to origin by edge


Recommended Posts

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
 

Link to comment
Share on other sites

Hi,

One way would be like this:

jaEDkag.png

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 );

 

  • Like 1
Link to comment
Share on other sites

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

 

Link to comment
Share on other sites

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.

Guest
Reply to this topic...

×   Pasted as rich text.   Paste as plain text instead

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...