Filter löschen
Filter löschen

Passing a line in middle of random lines

1 Ansicht (letzte 30 Tage)
Muhammad Umar
Muhammad Umar am 23 Okt. 2018
Bearbeitet: John D'Errico am 23 Okt. 2018
I have a list of coordinates of lines with coordinates. Line 1 = (a,b) , (c,d) Line 2 = (a1,b1), (c1,d1)
I have around more than ten lines. I want to construct a line which passes in the middle of these coordinates. Is there any function available in Matlab to do it? where I can pass x vector and y coordinate vector and it returns me coordinates of a line

Antworten (1)

John D'Errico
John D'Errico am 23 Okt. 2018
Bearbeitet: John D'Errico am 23 Okt. 2018
You have a long list of line segments. Not lines, unless you mean the extension of those lines to infinity in each direction. But the distinction is of course crucial.
Next, what do you mean by "in the middle"? Note that it is trivial to create a set of line segments such that it is impossible for any single line to pass in a way that the line intersects ALL line segments between their end points. The simple counter-example is to choose 5 points, at the corners of a regular pentagon. There is no line that can intersect more than 4 of the line segments, even if the line passes through 2 of the vertices. Thus, choose these line segments:
t = linspace(0,2*pi,6);
px = cos(t);
py = sin(t);
plot(px,py,'o-')
No line can intersect all 5 line segments, so case closed.
If you have a set of lines such that a common intersecting line does exist, then it is not that difficult to find. For example, given the following set of line segments, are you asking to find a line that intersects all of them?
x = rand(2,10) + [0;2];
y = rand(2,10);
plot(x,y,'o-')
Of course, as I constructed it, the simple solution is just the line defined by
x = 1.5
If you actually want a programmatic solution, I would ask that you confirm what you are trying to do. Note that almost always, even if a solution does exist, that it will not be unique.

Community Treasure Hunt

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

Start Hunting!

Translated by