Draw a rectangle arround a polygon when given in certain angle

懵懂的女人 提交于 2019-12-06 15:58:01

问题


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


来源:https://stackoverflow.com/questions/12464754/draw-a-rectangle-arround-a-polygon-when-given-in-certain-angle

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!