# Algo for finding nearest coordinates of arbitrary point along complex 3D line?

12 ビュー (過去 30 日間)
Joshua Melander 2016 年 2 月 16 日

I am looking for an algorithm that will take inputs of xyz coordinates of a series of points, and xyz coordinates of an associated line plot and will output the closest point along the line plot to each of the points.
The most basic example I can give is the following:
lineX = [0:10];
lineY = lineX;
lineZ = lineY;
point1 = [5 5 5];
point2 = [5 5 10];
point2 = [2 2 2];
I would hope the algo would give me the nearest coordinates along the line segment of each point (point1_nearest = 5 5 5, point2_nearest = 5 5 5, point3_nearest = 2 2 2] Any help would be most appreciated!
The problem is in practice the line coordinates will be more complicated ([0 0 0; 0.4 10 6; 0.5 15 7]) and it gets tedious to iterate through each coordinate and find the minimum distance.

サインインしてコメントする。

### 回答 (2 件)

Kevin Claytor 2016 年 2 月 16 日
Find the minimum squared distance between the point and the line:
pointX = point(1);
pointY = point(2);
pointZ = point(3);
[~, index] = find(min( (lineX - pointX).^2 + (lineY - pointY).^2 + (lineZ - pointZ).^2 ));
lineX(index), etc. gives you the closest line value for x, etc..
##### 0 件のコメント-2 件の古いコメントを表示-2 件の古いコメントを非表示

サインインしてコメントする。

Kelly Kearney 2016 年 2 月 16 日
I recommend distance2curve.m.

サインインしてコメントする。

### カテゴリ

Help Center および File ExchangeWatermarking についてさらに検索

### Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by