I have an arbitrary polygon as shown in Pic with co-planar Vertices's A,B,C,D,E,F,G,H in 3 D coordinate System. This Polygon is about to arbitrary axis.
1.Rotate this arbitrary polygon in X-Y Axis.
How to rotate Polygon from arbitrary Axis to X-Y Axis.
Compute normal of given Polygon. lets Assume normal of Polygon is Vector Nsrc.
Normal for any plane in X-Y axis will Z-direction so normal for X-Y Plane Vector Ndst (0,0,1).
By using Nsrc (source normal) and Ndst(destination Normal) compute rotation matrix and rotate plane in X-Y Axis.
2. Compute Min-Max for Rotated Polygon. i. e minXYZ[] and maxXYZ[] and generate Bounding rectangle by using min max.
bottomleftCorner = new Vector3(minXYZ[0], minXYZ[1], pointarr[0].z);
bottomRightCorner = new Vector3(maxXYZ[0], minXYZ[1], pointarr[0].z);
topLeftCorner = new Vector3(minXYZ[0], maxXYZ[1], pointarr[0].z);
topRightCorner = new Vector3(maxXYZ[0], maxXYZ[1], pointarr[0].z);
Note:- set Z-value of Bounding Rectangle Equal to Rotated Polygon Z Value for Perfect Align. Instead of Min Z and Max Z.
3. rotate Bounding rectangle back to Original polygon direction by using reverse of Rotation matrix.
|
Bounding Rectangle |