使用PCL绘制空间圆

3 篇文章 0 订阅

参考算法公式:http://blog.csdn.net/menjiawan/article/details/43021507

代码:

void DisplayMessage::createTheoryCircle(Point3d planeNormal, Point3d centerPoint, double R)
{
	double nx = planeNormal.x, ny = planeNormal.y, nz = planeNormal.z;
	double cx = centerPoint.x, cy = centerPoint.y, cz = centerPoint.z;
	double r = R;

	double ux = ny, uy = -nx, uz = 0;
	double vx = nx*nz,
		vy = ny*nz,
		vz = -nx*nx - ny*ny;

	double sqrtU = sqrt(ux*ux + uy*uy + uz*uz);
	double sqrtV = sqrt(vx*vx + vy*vy + vz*vz);

	double ux_ = (1 / sqrtU)*ux;
	double uy_ = (1 / sqrtU)*uy;
	double uz_ = (1 / sqrtU)*uz;

	double vx_ = (1 / sqrtV)*vx;
	double vy_ = (1 / sqrtV)*vy;
	double vz_ = (1 / sqrtV)*vz;

	double xi, yi, zi;
	double t = 0;
	double angle = (t / 180.0)*Pi;
	vector<double> x, y, z;

	while (t < 360.0)
	{
		xi = cx + r*(ux_*cos(angle) + vx_*sin(angle));
		yi = cy + r*(uy_*cos(angle) + vy_*sin(angle));
		zi = cz + r*(uz_*cos(angle) + vz_*sin(angle));
		x.push_back(xi);
		y.push_back(yi);
		z.push_back(zi);

		t = t + 1;
		angle = (t / 180.0)*Pi;
	}
	pcl::PointCloud<pcl::PointXYZ>::Ptr theroyCirclePoints(new pcl::PointCloud<pcl::PointXYZ>);

	//定义cloudPoints大小,无序点云
	theroyCirclePoints->resize(x.size());
	for (int i = 0; i < x.size(); i++){
		//将三维坐标赋值给PCL点云坐标
		(*theroyCirclePoints)[i].x = x[i];
		(*theroyCirclePoints)[i].y = y[i];
		(*theroyCirclePoints)[i].z = z[i];
	}
	
	//圆心点云设置
	//设置点云颜色
	viewer->removePointCloud("theroyCircleCloud");
	pcl::visualization::PointCloudColorHandlerCustom<pcl::PointXYZ> theroyCircleCloud_color(theroyCirclePoints, 255, 0, 0);
	//点云颜色渲染	
	viewer->addPointCloud(theroyCirclePoints, theroyCircleCloud_color, "theroyCircleCloud");
	//设置点云大小
	viewer->setPointCloudRenderingProperties(pcl::visualization::PCL_VISUALIZER_POINT_SIZE, 2, "theroyCircleCloud");
	viewer->resetCamera();
	ui.widget->update();
	
}

本类用于QT显示PCL点云,可参考本栏博客QT显示PCL点云

评论 1
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值