Automatically continue a line

5 views (last 30 days)
Josep Llobet
Josep Llobet on 6 Sep 2021
Commented: Josep Llobet on 8 Sep 2021
Hi there
Is there any way for automatically continue a drawed line?
For example, we have a curved line, and we want to extend it.
In example the black one, to below
Thank you!
Ravi Narasimhan
Ravi Narasimhan on 7 Sep 2021
My recommendation does not make sense if you are looking for a way to extend general curves especially if they are based on real data.
I use extrapolation only for small regions outside my data and then only if I have some underlying model for the data points; e.g. linear or exponential decay, growth, and so forth that are consistent with Matlab's inter/extrapolation algorithms.
You can consider fitting a curve to your points and then extrapolating from there if justified to do so.
@Jan brings up very good reasons/examples as well.

Sign in to comment.

Answers (1)

Jan on 7 Sep 2021
Edited: Jan on 7 Sep 2021
This cannot work without further assumptions. Because the existing line is drawn with some noise, e.g. due to rounding effects, there is an infinite number of curves matching a finite section of the original curve. If you have a sufficiently small piece of the curve, there is no chance to indentify, if it is a circle, parabola, sine, tangent or a straight line.
Remember that e.g. the extrapolation of a curve by a polynomial is extremely instable for higher orders.
Imagine a straight line drawn with a pencil on paper. It looks trivial to identify this as a line and to continue it. But how do you decide in which magnitude and over which length you determine the slope? Looking with a mikroscope on the final micrometer you will see a huge colored block. So you have to take a magnification, in which the width of the line is "sufficiently" smaller than its length. Even then you can take the right and the left edge of the line such that the determination of the slope has an uncertainty.
This effect does not only appear for real lines drawn on paper, but for numerical data stored with limited precision in a computer also.
Of course, if you do know in advance, that the line is a sine, you can use the existing data points to determine the parameters. But in general you do not know the equation. Assume you get the coordinates of the curve at the red circles:
x = linspace(0, 9*pi, 100);
y = sin(x);
plot(x, y, 'ro'); hold('on');
Of course you could decide, that this is a sine wave, but this equation matchs the given points very good also:
xx = linspace(0, 10*pi, 1000);
yy = sin(xx) + exp(xx - 9.8*pi);
plot(xx, yy, 'b')
If you have the rightmost 4 points only, assuming that this is a straight line or a sine wave would be pure guessing. The more points you have, the more possible solutions can be excluded. But the problem remains that infinity minus a huge number is still infinity. Because an infinite number of possible curves matchs a set of given points recorded with a limited precision, you cannot guess reliably, how a section of a curve has to be extrapolated.
Is there any way for automatically continue a drawed line?
It depeneds. If you decide for a specific scale and take a specific number of "points" to obtain the parameters of a specified formula (e.g. a sine or a straight line), you can determine the parameters with a deviation, such that you can draw a "most likely" continuation together with a (in general exponentially) growing uncertainty interval.
The job seems to be very easy for human. Give a 5 year old child a pencil and it will solve this for you without noticing, that the problem is hard. But from a viewpoint of a scientist, it gets clear, that the child included a huge number of intelligent assumptions based on common sense like "healthy curves do not explode or drive around like crazy". Almost all real curves does.
  1 Comment
Josep Llobet
Josep Llobet on 8 Sep 2021
Thank you for your response @Jan. I think in a absolutely way it is as you say, which would be impossible to continue a line unless by it would be possible to obtain an regression like linear, sinusoidal, and as, you said, instable, in the case of polinomial.
For my present question the continuity of the line does not demand an high accuracy because I just want to draw a short space line bewteen the end point of the line (which come from an skeletonization) and the near surface of the continuity. In my example I just wanted to join this endpoint of the black line with the red surface.
By this panorama, I think the best option could be the simply regresion in a simpler way as try regresion line or sinusoidal one and take this with a best regression coefficient, as an example.
I appreciate your further explanation whic have bring us to this conclusion.

Sign in to comment.

Community Treasure Hunt

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

Start Hunting!

Translated by