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

1 view (last 30 days)
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?

Answers (1)

Matt J
Matt J on 25 Oct 2017
Edited: Matt J on 25 Oct 2017
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

Categories

Find more on Interpolation in Help Center and File Exchange

Community Treasure Hunt

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

Start Hunting!