is a curve clockwise or counterclockwise?

200 views
Skip to first unread message

Nick Trefethen

unread,
Aug 7, 2016, 10:43:49 AM8/7/16
to chebfun-users, gree...@uw.edu, gue...@gmail.com
Anne Greenbaum has asked if Chebfun has a simple way to check if a curve is oriented clockwise or counter-clockwise. Here's one idea, but perhaps others can improve on it?

At the example http://www.chebfun.org/examples/geom/Area.html by Stefan Guettel, one sees a way to compute the area enclosed by a curve.  One could say that if the area is positive, then the curve runs counterclockwise, like this:
```
>> t = chebfun('t'); z = exp(pi*1i*t);
>> f = exp(z); area_of_f = sum(real(f).*diff(imag(f)))
area_of_f = 4.997133057057813
```
If the area is negative, then the curve runs clockwise, like this:
```
g = exp(1./z); area_of_g = sum(real(g).*diff(imag(g)))
area_of_g = -4.997133057057813
```
Do people have any suggestions about these ideas?

Anthony Austin

unread,
Aug 8, 2016, 6:15:33 AM8/8/16
to Nick Trefethen, chebfun-users, gree...@uw.edu, gue...@gmail.com
This was exactly the sort of thing that popped into my mind when I saw
this question, though I probably would have phrased it as integrating
1/(z - c) over the curve, where c is some point that lies within the
curve, and seeing if the result comes out positive or negative.

The problem is how to choose c. For convex curves, you can take c to be
the centroid, which you can easily compute by doing another Chebfun
integral. This is probably good enough for Prof. Greenbaum's
application, since I'm guessing that her curves are boundaries of fields
of values of matrices, and those sets are always convex. For non-convex
curves, you'd have to choose some other point.

At any rate, the approach based on Dr. Güttel's method doesn't have this
problem, and it saves an integral, so you may as well use it instead.


Regards,

Anthony P. Austin
aus...@maths.ox.ac.uk
> --
> You received this message because you are subscribed to the Google Groups
> "chebfun-users" group.
> To unsubscribe from this group and stop receiving emails from it, send an
> email to chebfun-user...@googlegroups.com.
> To view this discussion on the web, visithttps://groups.google.com/d/msgid/chebfun-users/dd463372-03f3-4430-8e2c-9c77
> bed52277%40googlegroups.com.
> For more options, visit https://groups.google.com/d/optout.
>
>

Anne Greenbaum

unread,
Aug 8, 2016, 10:48:35 AM8/8/16
to Anthony Austin, Nick Trefethen, chebfun-users, gue...@gmail.com
Thanks!  I will give the Guettel idea a try.  The curves that I am looking at 
are convex, but I would like to write a code that works for general closed curves.

Anne

Jacob Rus

unread,
Aug 8, 2016, 5:42:09 PM8/8/16
to chebfun-users
For a complex curve, is there any obvious way to compute the contour
winding number relative to a point at infinity?

Jacob Rus

unread,
Aug 8, 2016, 5:51:38 PM8/8/16
to chebfun-users
> For a complex curve, is there any obvious way to compute the contour
> winding number relative to a point at infinity?

(For instance, perhaps you could invert the function and then find the
winding number about the origin.)

Jacob Rus

unread,
Aug 8, 2016, 6:02:40 PM8/8/16
to chebfun-users
Another possibility would be to integrate the signed curvature along
the whole curve.

Anne Greenbaum

unread,
Aug 9, 2016, 5:54:52 PM8/9/16
to Anthony Austin, Nick Trefethen, chebfun-users, Stefan Güttel
Another method that seems to work is the following:

dL_arg=angle(diff(L));

dL_arg=unwrap(dL_arg-dL_arg(0));

direction = sum(diff(dL_arg))


If the curve is counterclockwise, direction should be +2pi, and if clockwise, direction should be -2pi.
Then you can just check the sign of direction.

Anne

On Mon, Aug 8, 2016 at 3:15 AM, Anthony Austin <aus...@maths.ox.ac.uk> wrote:
Reply all
Reply to author
Forward
0 new messages