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

56 views (last 30 days)

Show older comments

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

##### 0 Comments

### Accepted Answer

Roger Stafford
on 22 Dec 2012

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 Comments

Image Analyst
on 31 May 2019

### More Answers (3)

Jan
on 22 Dec 2012

"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))

##### 0 Comments

Image Analyst
on 21 Dec 2012

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 Comments

Image Analyst
on 30 May 2014

You can use bwboundaries() to get a list of (x,y) points.

Roger's Answer is in the FAQ http://matlab.wikia.com/wiki/FAQ#How_do_I_find_.22kinks.22_in_a_curve.3F

### See Also

### Categories

### Community Treasure Hunt

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

Start Hunting!