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.

• 1