# Rotate object based on oriented bounding box

## Recommended Posts

I put a slightly oblique scanned object into an oriented bounding box and picked two points that are supposed to be straight. Now I am struggling to counter-rotate my mesh according to the bounding box´s orientation.

```vector scan_orient = normalize( point(0, "P", 0) - point(0, "P", 3) );
vector straight = {0, 0, 1};

matrix3 rot = dihedral(scan_orient, straight);
rot = invert(rot);
@P *= rot;```

What am I missing?

Edited by konstantin magnus
##### Share on other sites

That given orientation is not the optimal to align two vectors. Consider you aligning a geo to same geo rotated by 180 degrees around Y axis using edge looking straight UP. There wouldn't be any transform (vectors already pretty aligned), but orientations are vastly different. dihedral won't help there. I would build a proper basis using at least 3 points here.

##### Share on other sites

@f1480187 Okay, then let´s assume I took two or three vectors along the edges of my oriented bounding box like this:

```vector scan_x = normalize( point(0, "P", 0) - point(0, "P", 3) );
vector scan_y = normalize( point(0, "P", 0) - point(0, "P", 1) );
vector scan_z = normalize( point(0, "P", 0) - point(0, "P", 4) );```

Whats the most direct way to turn this into a matrix that actually rotates my object back in place?

Edited by konstantin magnus
##### Share on other sites

`@P *= set(scan_x, scan_y, scan_z);`

The scan_* axes in the snippet above are negative though, I would swap operands. If axes are incorrect, try different combinations of 3-1-4. E.g.: 1-4-3.

##### Share on other sites

• 2 years later...

It's in a way related to my question there

Edited by vinyvince
##### Share on other sites

is there no way to automate the permutations and pick the right one?

Edited by vinyvince

## 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.

×   Pasted as rich text.   Paste as plain text instead

Only 75 emoji are allowed.

×   Your previous content has been restored.   Clear editor

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

×
×