当前位置:网站首页>The calculation proof of the intersection of the space line and the plane and its source code
The calculation proof of the intersection of the space line and the plane and its source code
2022-07-30 07:49:00 【sunset stained ramp】
目的:最近写C++代码,Come across some basic algorithms.The intersection of the space line and the plane is required.
Vector representation of straight lines: L : r → = P 0 → + t N 0 → L:\overrightarrow{r}=\overrightarrow{P_0}+t\overrightarrow{N_0} L:r=P0+tN0;其中 P 0 → = ( x 0 y 0 z 0 ) \overrightarrow{P_0}=\begin{pmatrix} x_0 \\ y_0 \\ z_0 \end{pmatrix} P0=⎝⎛x0y0z0⎠⎞, N 0 → = ( n x 0 n y 0 n z 0 ) \overrightarrow{N_0}=\begin{pmatrix} n_x^0 \\ n_y^0 \\ n_z^0 \end{pmatrix} N0=⎝⎛nx0ny0nz0⎠⎞
Flat vector representation: π : N 1 → T ⋅ X + d 1 = 0 \pi: \overrightarrow{N_1}^T \cdot X+d_1=0 π:N1T⋅X+d1=0;其中 N 1 → = ( n x 1 n y 1 n z 1 ) \overrightarrow{N_1}=\begin{pmatrix} n_x^1 \\ n_y^1 \\ n_z^1 \end{pmatrix} N1=⎝⎛nx1ny1nz1⎠⎞, d d d为标量.
For the intersection of the line and the plane, it is divided into three cases:
1)在平面上
2)parallel plane
3)intersects with the plane
图示如下:
It can be seen in the left and middle images,It has no intersection with the plane.Therefore, it is necessary to judge whether the line intersects the plane.in a traditional space,planes and straight planes,The hair vectors of lines and planes are perpendicular.因此可以通过计算 N 0 → \overrightarrow{N_0} N0和 N 1 → \overrightarrow{N_1} N1之间的夹角.If it is perpendicular to the surface the straight line and the plane are parallel.
c o s ( θ ) − > N 0 → T ⋅ N 1 → cos(\theta)->\overrightarrow{N_0}^T \cdot \overrightarrow{N_1} cos(θ)−>N0T⋅N1
if it's close to0means it is parallel.
The case of intersection is described below
If the plane and the line intersect,对于直线来说,只需要计算 t t t即可.
L : r → = P 0 → + t N 0 → L:\overrightarrow{r}=\overrightarrow{P_0}+t\overrightarrow{N_0} L:r=P0+tN0带入公式 π : N 1 → T ⋅ X + d 1 = 0 \pi: \overrightarrow{N_1}^T \cdot X+d_1=0 π:N1T⋅X+d1=0得到如下:
N 1 → T ⋅ ( P 0 → + t N 0 → ) + d 1 = 0 = > N 1 → T ⋅ P 0 → + t N 1 → T ⋅ N 0 → + d 1 = 0 t = ( − d 1 − N 1 → T ⋅ P 0 → ) / N 1 → T ⋅ N 0 → \overrightarrow{N_1}^T \cdot (\overrightarrow{P_0}+t\overrightarrow{N_0})+d_1=0 \\ =>\overrightarrow{N_1}^T \cdot \overrightarrow{P_0}+t \overrightarrow{N_1}^T \cdot \overrightarrow{N_0}+d_1=0 \\ t=(-d_1 - \overrightarrow{N_1}^T \cdot \overrightarrow{P_0})/\overrightarrow{N_1}^T \cdot \overrightarrow{N_0} N1T⋅(P0+tN0)+d1=0=>N1T⋅P0+tN1T⋅N0+d1=0t=(−d1−N1T⋅P0)/N1T⋅N0
因为向量 P 0 → \overrightarrow{P_0} P0, N 0 → \overrightarrow{N_0} N0, N 1 → \overrightarrow{N_1} N1都是已知,So it can be requested t = t n t=t_n t=tn.
带入得到
r n → = P 0 → + t n N 0 → \overrightarrow{r_n}=\overrightarrow{P_0}+t_n\overrightarrow{N_0} rn=P0+tnN0
Based on the above formula,源码如下:
bool LineRayToPlanePnt(Eigen::Vector3f& o_orign, Eigen::Vector3f& o_dir, Eigen::Vector4f& fn, Eigen::Vector3f& inter_pnt)
{
Eigen::Vector3f N = Eigen::Vector3f(fn[0], fn[1], fn[2]);
float D = fn[3];
if (std::abs(o_dir.dot(N)) < 1e-8)
{
return false;
}
float t = -(o_orign.dot(N) + D) / (o_dir.dot(N));
inter_pnt = o_orign + t*o_dir;
}
边栏推荐
- Graph analysis like NetworkX with GraphScope
- 05-Theos
- 大厂年薪50w+招聘具有测试平台开发能力的测试工程师
- Selenium02
- libgrape-lite: 提供 GraphScope 的图分析能力
- Advanced multi-threading (lock strategy, spin+CAS, Synchronized, JUC, semaphore)
- idea内置翻译插件
- GadgetInspector principle analysis
- Software Testing Terminology - Scenario Testing
- Test Development Engineer Growth Diary 010 - CI/CD/CT in Jenkins (Continuous Integration Build/Continuous Delivery/Continuous Testing)
猜你喜欢

(GGG)JWT

How to save modelsim simulation data as a file

05-Theos

测试开发工程师成长日记009 - 环境排排站:开发环境、测试环境、生产环境、UAT环境、仿真环境

GNNLab: A Novel GNN System Based on Spatial Sharing Ideas

用 GraphScope 像 NetworkX 一样做图分析

Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps

基于 JupyterLab 插件在 GraphScope 中交互式构图

多线程基础(多线程内存,安全,通信,线程池和阻塞队列)

Redis下载与安装
随机推荐
Test Development Engineer Growth Diary 008 - Talking About Some Bugs/Use Case Management Platform/Collaboration Platform
图计算在网络安全分析中的应用
测试开发工程师成长日记016 - 关于提测的那些事
STL源码剖析:迭代器的概念理解,以及代码测试。
多线程进阶(锁策略,自旋+CAS,Synchronized,JUC,信号量)
Redis下载与安装
The Force Plan Microservices | Centralized Configuration Center Config Asymmetric Encryption and Security Management
Selenium01
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
网络协议03 - 路由和NAT
How to import matlab data into modelsim simulation
用 GraphScope 像 NetworkX 一样做图分析
Test development engineer diary 002 - starting from 0 interface automation
(GGG)JWT
Required request body is missing 问题解决
基于 JupyterLab 插件在 GraphScope 中交互式构图
DNS域名解析服务
MySQL主从复制配置搭建,一步到位
空间顶点到平面的距离计算的证明及其源码
mysql常用命令以及mysqldump备份