#include <iostream>
#include <pcl/common/common.h>
#include <pcl/common/geometry.h>
#include <pcl/visualization/pcl_visualizer.h>
int main() {
// 定义两个平面的法向量
Eigen::Vector3f normal_plane1(1.0f, 0.0f, 0.0f); // 第一个平面的法向量
Eigen::Vector3f normal_plane2(0.0f, 1.0f, 0.0f); // 第二个平面的法向量
// 计算平面之间的交线
Eigen::Vector3f line_direction = normal_plane1.cross(normal_plane2); // 交线的方向向量
std::cout << "Direction of intersection line: " << line_direction.transpose() << std::endl;
// 选择一个平面作为基准点和另一个平面的法向量
Eigen::Vector3f point_on_plane1(0.0f, 0.0f, 0.0f); // 第一个平面上的一个点(可以是任意一个)
float t = 100.0f; // 参数化方程中的参数 t,可以根据具体需求进行调整
// 计算交线上的一个点
Eigen::Vector3f point_on_intersection_line = point_on_plane1 + t * line_direction;
std::cout << "Point on intersection line: " << point_on_intersection_line.transpose() << std::endl;
// 可视化部分
pcl::visualization::PCLVisualizer viewer("Intersection Line Viewer");
// 添加第一个平面
pcl::ModelCoefficients plane1_coeff;
plane1_coeff.values.push_back(normal_plane1.x());
plane1_coeff.values.push_back(normal_plane1.y());
plane1_coeff.values.push_back(normal_plane1.z());
plane1_coeff.values.push_back(0.0); // 偏移量设为0,表示过原点
viewer.addPlane(plane1_coeff, "plane1");
viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 1.0, 0.0, 0.0, "plane1");
// 添加第二个平面
pcl::ModelCoefficients plane2_coeff;
plane2_coeff.values.push_back(normal_plane2.x());
plane2_coeff.values.push_back(normal_plane2.y());
plane2_coeff.values.push_back(normal_plane2.z());
plane2_coeff.values.push_back(0.0); // 偏移量设为0,表示过原点
viewer.addPlane(plane2_coeff, "plane2");
viewer.setShapeRenderingProperties(pcl::visualization::PCL_VISUALIZER_COLOR, 0.0, 1.0, 0.0, "plane2");
// 添加交线
pcl::PointXYZ line_start(point_on_plane1.x(), point_on_plane1.y(), point_on_plane1.z());
pcl::PointXYZ line_end(point_on_intersection_line.x(), point_on_intersection_line.y(), point_on_intersection_line.z());
viewer.addLine(line_start, line_end, 1.0, 1.0, 1.0, "intersection_line");
// 设置视角和渲染
viewer.addCoordinateSystem(1.0);
viewer.setBackgroundColor(0.1, 0.1, 0.1);
viewer.initCameraParameters();
// 显示窗口
while (!viewer.wasStopped()) {
viewer.spinOnce();
}
return 0;
}
08-07
395
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
08-02
1159
![](https://csdnimg.cn/release/blogv2/dist/pc/img/readCountWhite.png)
09-27