任意方位矩形相交面积计算(一次优化版800us->400us)

前面对于任意方位矩形相交面积的计算发过一篇博客,但是算法耗时比较大,需要800us,无法满足应用需求。于是对其进行了优化,耗时减了一半,只需400us。现在将优化的代码分享出来。算法计算原理还是跟原始的差不多,只是在具体的实现方式上对代码进行了优化。部分代码也是参考网上的代码,在此表示感谢!!!

1. 矩形框的头文件以及对矩形框类的定义

#include <algorithm>
#include <csignal>
#include <ctime>
#include <map>
#include <string>
#include <utility>
#include <vector>
#include <math.h>
#include <iostream>
#define Max(a,b) ((a>b)? a:b)
#define Min(a,b) ((a<b)? a:b)
#define Pi 3.1415926
class NormalizedBBox
{
public:
float x;
float y;
float w;
float h;
float theta;
NormalizedBBox(float x , float y , float w , float h , float theta ){

this->x = x;
this->y = y;
this->w = w;
this->h = h;
this->theta = theta;
       }

}

2. 坐标点类简单定义

class Point{
public:
float x;
float y;
Point(float x, float y)
{
this->x = x;
this->y = y;
}
Point()
{
this->x = 0;
this->y = 0;
}


}

3. 计算一个矩形的顶点坐标

void getRectanglVertexs(NormalizedBBox box, vector<Point>& vertexs){
Point temp(0,0);
float cos_theta = cos(box.theta);
float sin_theta = sin(box.theta);
temp.x &#

  • 3
    点赞
  • 13
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值