当前位置:网站首页>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;
}
边栏推荐
猜你喜欢
随机推荐
From installation to compilation: 10 minutes to teach you to use and develop GraphScope locally
Linx常见目录&文件管理命令&VI编辑器使用 介绍
空间直线到平面上的交点的计算证明及其源码
Network Protocol 03 - Routing and NAT
debian problem
瀑布流(自定义布局实现)
空间顶点到直线的距离计算及其源码
04-packing and unpacking
prometheus监控nacos
Rodrigues:旋转矩阵的向量表达
OP tokens and non-transferable NFTs work to build a new digital democracy
libgrape-lite: 提供 GraphScope 的图分析能力
测试开发工程师成长日记001 - 敏捷测试、CI/CD/CT、DecOps的一些介绍
02-Cycript的使用
debian 问题
黑盒测试的概念及测试方法
DNS域名解析服务
Test Development Engineer Growth Diary 007 - Bug Priority Definition and Filling Specifications
多线程基础(多线程内存,安全,通信,线程池和阻塞队列)
Test Development Engineer Growth Diary 001 - Some Introduction to Agile Testing, CI/CD/CT, DecOps