以下是计算ply点云文件在y轴上最小点到最大点距离的C++代码:

#include #include #include #include #include #include

struct Point { double x; double y; double z; };

double distance(Point p1, Point p2) { return std::sqrt((p1.x - p2.x) * (p1.x - p2.x) + (p1.y - p2.y) * (p1.y - p2.y) + (p1.z - p2.z) * (p1.z - p2.z)); }

int main(int argc, char *argv[]) { if (argc < 2) { std::cerr << "Usage: " << argv[0] << " " << std::endl; return -1; } std::ifstream file(argv[1]); if (!file) { std::cerr << "Failed to open file: " << argv[1] << std::endl; return -1; } std::string line; std::vector points; while (std::getline(file, line)) { if (line.find("element vertex") != std::string::npos) { int count = std::stoi(line.substr(15)); for (int i = 0; i < count; i++) { std::getline(file, line); std::istringstream iss(line); Point p; iss >> p.x >> p.y >> p.z; points.push_back(p); } } } if (points.empty()) { std::cerr << "No points found in file: " << argv[1] << std::endl; return -1; } double minY = points[0].y; double maxY = points[0].y; for (int i = 1; i < points.size(); i++) { if (points[i].y < minY) { minY = points[i].y; } if (points[i].y > maxY) { maxY = points[i].y; } } std::cout << "Minimum y: " << minY << std::endl; std::cout << "Maximum y: " << maxY << std::endl; std::cout << "Distance: " << maxY - minY << std::endl; return 0;

写一段计算ply点云文件在y轴上最小点到最大点距离的C++代码

原文地址: https://www.cveoy.top/t/topic/f24A 著作权归作者所有。请勿转载和采集!

免费AI点我,无需注册和登录