从旋转矩形,图片里面计算边框坐标 [英] Calculate Bounding box coordinates from a rotated rectangle, Picture inside

查看:770
本文介绍了从旋转矩形,图片里面计算边框坐标的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个矩形的左上角点的坐标以及其宽度,高度和旋转从0到180和-0到-180

I have the coordinates of the top left Point of a rectangle as well as its width, height and rotation from 0 to 180 and -0 to -180.

我想获得矩形围绕着实际中的边界坐标。 这是计算的边界框的坐标的一个简单的方法 - 最小Y,最大Y,最小X,最大X

I am trying to get the bounding coordinates of the actual box around the rectangle. What is a simple way of calculating the coordinates of the bounding box - min y, max y, min x, max x ?

的甲点不总是在最小Y点束缚,但可以在任何地方。 我可以利用矩阵变换工具在AS3中,如果需要的。

The A point is not always on the min y bound, it can be anywhere. I can use matrix the transform toolkit in as3 if needed.

推荐答案

  • 变换的四角的坐标
  • 找到最小的所有四个X的如 min_x
  • 找到最大的四个X和称之为 max_x
  • 同上与y的
  • 您的边框(min_x,min_y),(min_x,max_y),(max_x,max_y),(max_x,min_y)

  • Transform the coordinates of all four corners
  • Find the smallest of all four x's as min_x
  • Find the largest of all four x's and call it max_x
  • Ditto with the y's
  • Your bounding box is (min_x,min_y), (min_x,max_y), (max_x,max_y), (max_x,min_y)
  • AFAIK,没有任何捷径可走,这将让你有更快。

    AFAIK, there isn't any royal road that will get you there much faster.

    如果你想知道如何变换坐标,请尝试:

    If you are wondering how to transform the coordinates, try:

    x2 = x0+(x-x0)*cos(theta)+(y-y0)*sin(theta)
    y2 = y0-(x-x0)*sin(theta)+(y-y0)*cos(theta)
    

    其中,(X0,Y0)为中心在其周围您正在旋转。您可能需要鼓捣这取决于你的三角函数(做,他们期望度或弧度)的坐标系的感觉/符号与你如何指定角度,等等。

    where (x0,y0) is the center around which you are rotating. You may need to tinker with this depending on your trig functions (do they expect degrees or radians) the sense / sign of your coordinate system vs. how you are specifying angles, etc.

    这篇关于从旋转矩形,图片里面计算边框坐标的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

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