查找一个三维点的距离到线段 [英] Find the Distance from a 3d Point to a Line Segment
问题描述
我有一个三维点P和由A和B所限定的线段(A是线段的起点,乙结束)。
I have a 3d point P and a line segment defined by A and B (A is the start point of the line segment, B the end).
欲计算P和直线AB之间的最短距离。
I want to calculate the shortest distance between P and the line AB.
计算一个点的距离无限线很容易,我已经实现了,但我需要做这行有限长度的。
Calculating the distance of a point to an infinite line was easy as their was a solution on Wolfram Mathworld, and I have implemented that, but I need to do this for a line of finite length.
我还没有设法找到了很多环顾四周后,这个可靠的解决方案,在3D。
I have not managed to find a reliable solution for this in 3d after a lot of looking around.
我已用C语言实现的算法来计算点积,叉积,大小等++与包含浮筒的x,y和z的结构体。
I have implemented algorithms to calculate the dot product, cross product, magnitude and so on in C++ with a struct that contains floats x, y and z.
伪code,链接,或code $ p中$ ptty的多为这个任何语言将是巨大的。
Pseudo code, links, or code in pretty much any language for this would be great.
在此先感谢
推荐答案
softSurfer 有一个很好的教程显示如何< A HREF =http://www.softsurfer.com/Archive/algorithm_0102/algorithm_0102.htm>计算从点到线的距离,光线,或段在2D和3D 。
softSurfer has a nice tutorial showing how to compute the distance from a point to a line, ray, or segment in 2D and 3D.
这篇关于查找一个三维点的距离到线段的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!