我从旋转的矩形中读取了计算边界框坐标,以了解如何从旋转的矩形中计算边界框坐标。但在特殊情况下,如下图:
如果获得了边界框大小、坐标和旋转度,如何获得旋转后的矩形大小?
我尝试用javascript编写代码
//assume w=123,h=98,deg=35 and get calculate box size
var deg = 35;
var bw = 156.9661922099485;
var bh = 150.82680201149986;
//calculate w and h
var xMax = bw / 2;
var yMax = bh / 2;
var radian = (deg / 180) * Math.PI;
var cosine = Math.cos(radian);
var sine = Math.sin(radian);
var cx = (xMax * cosine) + (yMax * sine) / (cosine * cosine + sine * sine);
var cy = -(-(xMax * sine) - (yMax * cosine) / (cosine * cosine + sine * sine));
var w = (cx * 2 - bw)*2;
var h = (cy * 2 - bh)*2;
但是......答案是不匹配 w 和 h