博客
关于我
强烈建议你试试无所不能的chatGPT,快点击我
Calculate the distance between two lines in 3D space
阅读量:4920 次
发布时间:2019-06-11

本文共 1750 字,大约阅读时间需要 5 分钟。

I just did some math work on the distance between two lines in 3D space. After some boring calculation, I found the result itself is much more decent and help us to revisit the issue in an elegant way.

Line 1: p = p1 + t * v1
Line 2: p = p2 + t * v2
(t is a scalar argument, while v1 and v2 are normalized vectors)
Before considering the special cases, we can consider the general case and usually the special cases can be analyzed from some items in the general result.
SO the general case is that the two lines are not coplanar. We can first construct a plane from these two lines by translating Line 2 to pass through p1 and calculating the distance from p2 to the constructed plane.
The normal vector of the plane is:
n = cross( v1, v2 )
Thus the plane is:
dot( n, p ) = dot( n, p1 )
The closest point in the plane to p2 is constrained by the above equation and the following one as well.
p = p2 + t * n
t in the above equation is therefore the distance we want to calculated.
By combining these two equations, we can get this one:
dot( n, p2 + t * n ) = dot( n, p1 )
i.e.
t = abs( dot( n, p1 - p2 ) ) = abs( dot( cross( v1, v2 ), p1 - p2 ) )
After this result comes out, I said to myself, "aah, how stupid I am..., I don't actually need to do so much calculation!"
It is actually a decent result if you consider this question in another way. You can pick any two points respectively from these two lines, let's say, p1 and p2 is OK. Then after projecting the vector p1 - p2 onto the normal n is the distance we want.
For the special cases, we can see from cross( v1, v2 ) that the equation is incorrect when the two lines are parallel. It will be easy to analyze it.

转载于:https://www.cnblogs.com/danod/archive/2012/08/16/DistanceBetweenLines.html

你可能感兴趣的文章
实验二
查看>>
c++ c# java 调用 c++ 写的dll
查看>>
css经典布局—stick footer布局
查看>>
div学习之div中dl-dt-dd的详解
查看>>
当在hive中show table …
查看>>
随机森林(Random Forest)
查看>>
[转载]/etc/security/limits.conf解释及应用
查看>>
Python的math模块
查看>>
Linux下gcc相关
查看>>
iphone真机(越狱)通讯录导入进模拟器
查看>>
剑指offer-删除链表中重复的结点
查看>>
mybatis自动生成mapper,dao映射文件
查看>>
IntelliJ IDEA 注册码
查看>>
C 调用数学函数pow时遇到 undefined reference [已解决]
查看>>
IDEA01 创建java项目、创建web项目
查看>>
Springboot21 整合redis、利用redis实现消息队列
查看>>
AJAX 总结
查看>>
[转]WPF中对Excel文件的导入导出操作详解
查看>>
导出模块化使用手册
查看>>
rabbitmq在storm中使用
查看>>