Draw a rectangle arround a polygon when given in c

2020-08-09 06:57发布

问题:

Using Google Maps V3 API

How can I draw a rectangle (It wouldn't exactly be a google map rectangle anymore but a rectangular polygon) around a polygon. Important however is that the rectangle has be rotated around a certain given angle. I do not mean to calculate the min and max of the coord of the polygon first to draw a rectangle and rotate it afterwards;

This image may be a better description from what I am trying to accomplish.

What I am trying to accomplish is to get the bounding rectangle of the polygon at an angle.

回答1:

This is very similar to finding a bounding box, which is not rotated.

If your angle of rotation is alpha, then take the unit vectors along Ox and Oy and rotate them by this angle alpha to get unit vectors X and Y. Now you are looking for the bounding box with respect to X,Y.

For each point (represented by a vector) P in your set you can get the oriented projection by taking the dot product: Px = P.X and Py = P.Y

If

Mx is the max Px, mx is the min Px.

My is the max Py, my is the min Py.

then this is your bounding rectangle.

I am not sure what representation of it you need, but say its vertices would be:

mx * X + my * Y
mx * X + My * Y
Mx * X + my * Y
Mx * X + My * Y