以特定角度给出时,在多边形周围画一个矩形 [英] Draw a rectangle arround a polygon when given in certain angle

查看:132
本文介绍了以特定角度给出时,在多边形周围画一个矩形的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

使用Google Maps V3 API



如何在多边形周围绘制一个矩形(它不再是一个Google地图矩形,而是一个矩形多边形)。但重要的是矩形已经围绕某个给定的角度旋转。我并不是要先计算多边形坐标的最小值和最大值,然后再绘制矩形并旋转它;


这个图像可能是我想要完成的更好的描述。



我试图完成的是以一个角度获得多边形的边界矩形。

解决方案

这与找到不旋转的边框非常相似。



如果您的旋转角度为alpha,单位矢量沿Ox和Oy旋转,并通过这个角度α旋转它们以获得单位矢量X和Y.
现在您正在寻找与X,Y有关的边界框。

对于集合中的每个点(用向量表示)P,可以通过获得点积来得到面向投影:Px = PX和Py = PY

如果

  Mx i s是最大Px,mx是最小Px。 

我是最大Py,我是最小Py。

然后这是您的边界矩形。



我不确定你需要什么表示,但说它的顶点是:

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


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.

解决方案

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

这篇关于以特定角度给出时,在多边形周围画一个矩形的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆