码农知识堂 - 1000bd
  •   Python
  •   PHP
  •   JS/TS
  •   JAVA
  •   C/C++
  •   C#
  •   GO
  •   Kotlin
  •   Swift
  • python计算点到面的距离


    python计算点到面的距离

    已知M个点,记P∈R^(M*3),目的是求M个点到平面Z= aX + bY + c的距离
    
    解法1: 使用平面的法向量来求解                                    
    平面Z= aX + bY + c的法向量为[a,b,-1];
    
    解法2: 使用系数[a,b,c]来求解
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • code1
    # 加入normal就为法向量[a,b,-1]
    def point_plane_dist(normals,pcd):
    	max_dist = 0.4
        a1 = normals[0] # a
        a2 = normals[1] # b
        a3 = normals[2] # -1
        normals = normals.reshape(3,1)
        FM = np.sqrt(a1**2 + a2**2+a3**2)
        dists = abs(np.dot(normals,A)+a3)/FM
    
    	# 求点集中于平面距离小于阈值的点集的索引
        ground_idx = (dists <= max_dist).ravel()
        ground_points = pcd[ground_idx]
        pre_cloud = pcd[np.logical_not(ground_idx)]
        # 输出地面背景点和前景点
        return ground_points, pre_cloud
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • code2
    def point_plane_dist(normals,pcd):
        max_dist = 0.4
        a1 = normals[0]
        a2 = normals[1]
        a3 = normals[2]
        FM = np.sqrt(a1**2 + a2**2+1)
        A = np.array([a1,a2,-1]).reshape(3,1)
        dists = abs(np.dot(pcd,A)+a3)/FM
    
        ground_idx = (dists <= max_dist).ravel()
        ground_points = pcd[ground_idx]
        pre_cloud = pcd[np.logical_not(ground_idx)]
        return ground_points, pre_cloud
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • code2(c++版本代码)
    #include
    #include
    
    using namespace std;
    
    vector<float> mat(vector<vector<float>> P, vector<float> N)
    {
    	float c = N[2];
    	N[2] = -1;
    	float FM = sqrt(pow(N[0], 2.0) + pow(N[1], 2.0) + 1);
    	vector<float> res(P.size(), 0);
    	for (int i = 0; i < P.size(); i++)
    	{
    		for (int j = 0; j < N.size(); j++)
    			res[i] += P[i][j] * N[j];
    		res[i] += c;
    		res[i] = res[i] / FM;
    	}
    	return res;
    }
    
    int main()
    {
    	// 平面Z = aX + bY + c
    	vector<float> normals(3, 0);//法向量[a,b,c]
    	int N;
    	cin >> N;
    	vector<vector<float>> points(N, vector<float>(3, 0));
    	vector<float> dist = mat(points, normals);
    	return 0;
    
    }
    
    • 1
    • 2
    • 3
    • 4
    • 5
    • 6
    • 7
    • 8
    • 9
    • 10
    • 11
    • 12
    • 13
    • 14
    • 15
    • 16
    • 17
    • 18
    • 19
    • 20
    • 21
    • 22
    • 23
    • 24
    • 25
    • 26
    • 27
    • 28
    • 29
    • 30
    • 31
    • 32
  • 相关阅读:
    mysql进程信息出现大量Waiting for table level lock信息的原因,怎么处理?
    java计算机毕业设计校园失物招领管理系统源代码+系统+数据库+lw文档
    Unity JobSystem使用及技巧
    【0基础学算法】归并排序(超详细讲解+私人笔记+源码)
    jMetalPy: 用元启发法进行多目标优化的Python框架
    gitlab离线安装时缺少依赖库的解决思路
    Linux动静态库
    CF1846F交互题WA了求Debug!
    Python机器学习17——Xgboost和Lightgbm结合分位数回归(机器学习与传统统计学结合)
    根据类的属性自动生成该属性名对应的字符串常量值
  • 原文地址:https://blog.csdn.net/qhu1600417010/article/details/126368363
  • 最新文章
  • 沪漂五周年了:我越来越迷茫了
    Agentic Skill Routing 实战:别再把所有 Skill 塞进 AI Agent 上下文
    MySQL-Seconds_behind_master的精度误差
    [MAF预定义ChatClient中间件-03]CachingChatClient——利用缓存省钱省时间
    AI的至暗历史:从万众期待到被政府撤资,AI的两次死亡徘徊
    Agent OS :五种驯服不确定性的范式
    PortSwigger SQL注入LAB11
    数据库即时编译JIT
    [Begin]AI Learn Data Day 0
    深度学习进阶(二十七)现代 LLM 的核心架构设计其二:SwiGLU
  • 热门文章
  • 十款代码表白小特效 一个比一个浪漫 赶紧收藏起来吧!!!
    奉劝各位学弟学妹们,该打造你的技术影响力了!
    五年了,我在 CSDN 的两个一百万。
    Java俄罗斯方块,老程序员花了一个周末,连接中学年代!
    面试官都震惊,你这网络基础可以啊!
    你真的会用百度吗?我不信 — 那些不为人知的搜索引擎语法
    心情不好的时候,用 Python 画棵樱花树送给自己吧
    通宵一晚做出来的一款类似CS的第一人称射击游戏Demo!原来做游戏也不是很难,连憨憨学妹都学会了!
    13 万字 C 语言从入门到精通保姆级教程2021 年版
    10行代码集2000张美女图,Python爬虫120例,再上征途
小工具 小游戏
Copyright © 2022 侵权请联系2656653265@qq.com    京ICP备2022015340号-1

京公网安备 11010502049817号