How to minimize a midpoint of a 3D line to a 3D data set?

1 回表示 (過去 30 日間)
John Hunt
John Hunt 2017 年 10 月 25 日
編集済み: Matt J 2017 年 10 月 25 日
I have two points pt1 = (36.77, 11.63, -38.82) pt2 = (31.77, 14.61, -31.09). I also have a set of data points that I need to use to "connect" these two points.
a = [44.16 17.609 -28.523;
43.491 15.957 -30.258;
45.491 16.502 -31.569;
45.337 17.206 -33.948;
44.864 14.849 -33.304]
I wanted to connect the points by first making a line between them. I can use the two points to make a vector that would connect them, then I can divide that in half and then find the midpoint between these points. Once I have the mid point I want to "move" it so that it resides "in" the data. To move it in I was going to find the smallest distance from the midpoint of the line and a data point then move the midpoint there. I want to iterate this until I have enough lines that fit the data well. I wanted to do this with fmincon, but I am having a hard time with the parameters. Any suggestions?

回答 (1 件)

Matt J
Matt J 2017 年 10 月 25 日
編集済み: Matt J 2017 年 10 月 25 日
You don't need fmincon for something so simple as finding separation distances of points. It can all be done algebraically,
mindpoint=(pt1+pt2)/2;
[minDistance,minloc]=min(sum( (a-midpoint).^2 ,2) ), %R2016b or higher

カテゴリ

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

タグ

Community Treasure Hunt

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

Start Hunting!

Translated by