c++:已知N个顶点,每两个顶点之间拟合直线,插值出直线上等距离的点

/*
* @brief  输入几个顶点坐标 插值出更多点点云
* param[in] vec_points:输入7个顶点坐标   cloud 
*/
void getMorePoints(const vector<Point2d> & vec_points, pcXYZI &cloud)
{
	vector<Point2d> vec_more_points;
	for (int i = 0; i < vec_points.size(); i++)
	{
		double m = 0;
		//计算分子
		m = vec_points[i].x - vec_points[(i + 1) % vec_points.size()].x;
		double len_y = vec_points[i].y - vec_points[(i + 1) % vec_points.size()].y;
		//如果为y轴直线的时候
		if (m == 0)
		{
			double temp_len_y = 0.0;
			while (temp_len_y < abs(len_y))
			{
				Point2d p1;
				p1.x = vec_points[i].x;
				p1.y = min(vec_points[i].y, vec_points[(i + 1) % vec_points.size()].y) + temp_len_y;
				vec_more_points.push_back(p1);
				temp_len_y += 0.01;
			}
		}
		// y = kx + b
		else
		{
			double k = len_y / m;
			double b = vec_points[i].y - k * vec_points[i].x;
			double temp_len_x = 0.0;
			while (temp_len_x < abs(m))
			{
				Point2d p1;
				p1.x = min(vec_points[i].x, vec_points[(i + 1) % vec_points.size()].x) + temp_len_x;
				p1.y = k * p1.x + b;
				vec_more_points.push_back(p1);
				temp_len_x += 0.01 * cos(atan(k));
			}
		}
	}
	//生成点云
	for (int i = 0; i < vec_more_points.size(); i++)
	{
		pcl::PointXYZI point;
		point.intensity = 1000;
		point.x = vec_more_points[i].x;
		point.y = vec_more_points[i].y;
		point.z = 0;
		cloud.points.push_back(point);
	}
	cloud.height = 1;
	cloud.width = cloud.points.size();		
}

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

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

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值