how to find the sharp turn in a 2d-line (curve)?

조회 수: 25 (최근 30일)
tafteh
tafteh 2012년 12월 21일
댓글: Image Analyst 2019년 5월 31일
Hi all,
I am trying to find the sharp turn in a 2d-line (curve). Line is constructed with two vectors, X and Y. In following link you can find a sample line with realized point at which there is sharp turn (red solid point).
I appreciate if you could help me out with this.
Thanks, Payam

채택된 답변

Roger Stafford
Roger Stafford 2012년 12월 22일
One measure of a "sharp turn" is the amount of curvature between three adjacent points on your curve. Let (x1,y1), (x2,y2), and (x3,y3) be three such adjacent points. By a well-known formula, the curvature of a circle drawn through them is simply four times the area of the triangle formed by the three points divided by the product of its three sides. Using the coordinates of the points this is given by:
K = 2*abs((x2-x1).*(y3-y1)-(x3-x1).*(y2-y1)) ./ ...
sqrt(((x2-x1).^2+(y2-y1).^2)*((x3-x1).^2+(y3-y1).^2)*((x3-x2).^2+(y3-y2).^2));
Roger Stafford
  댓글 수: 3
Maradona Rodrigues
Maradona Rodrigues 2019년 5월 31일
Hi I tried using the above code and resulted in some erronous results
my 2d line is list = [0 0; 4 0.5; 8 6; 6 25; 3 7; 1 1] , with the biggest curvature being at the point [6,25]. However i didnt get the second lowest at that point?
Image Analyst
Image Analyst 2019년 5월 31일
Maybe there are not enough points to make a determination. If you have a recent version of MATLAB you might also try findchangepts().

댓글을 달려면 로그인하십시오.

추가 답변 (3개)

Jan
Jan 2012년 12월 22일
"Sharp" is relative. There is always a zoom level, which let a curve look smooth.
If you do not have a curve defined by a function, but a piecewise defined line, you are looking for neighboring elements with and included angle above a certain limit. But when such a piece has a length of 1e-200, while the others have a length of 1.0, can this have a "sharp turn"?!
But let's imagine, that you can control this fundamental problem by inventing some meaningful thresholds. Then this determines the angle between two lines:
angle = atan2(norm(cross(N1, N2)), dot(N1, N2))

Image Analyst
Image Analyst 2012년 12월 21일
Well for that example, just do
yAtTurn = min(y);
xAtTurn = find(y == yAtTurn);
If you need something more general, flexible, and robust, then you need to say how other curves might look different than the one example you supplied.
  댓글 수: 6
Alessandro
Alessandro 2014년 5월 30일
Hi Image Analyst... your code works fine for me but i have a bw image instead of a set of (x,y) points... so that, i've not an ordered set of (x,y)... how can i figure out? (my purpose is still find inflection points)
Image Analyst
Image Analyst 2014년 5월 30일
You can use bwboundaries() to get a list of (x,y) points.

댓글을 달려면 로그인하십시오.


tafteh
tafteh 2012년 12월 21일
Hi again, I have updated the image to make it more clearer regarding my problem explained in the first post. Please find the link below:
Thanks,

카테고리

Help CenterFile Exchange에서 2-D and 3-D Plots에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by