Function poly2cw not working?
Mostrar comentarios más antiguos
Hi all,
Matlab says:
[x2, y2] = poly2cw(x1, y1) arranges the vertices in the polygonal contour (x1, y1) in clockwise order, returning the result in x2 and y2.
However, if I have the (x1, y1) coordinates as:
x1 =
-1 -1 0 0
y1 =
-1 0 -1 0
obviously the poly2cw result should be:
>> x2
x2 =
-1 -1 0 0
>> y2
y2 =
-1 0 0 -1
However, if I run
>> [x2 y2] = poly2cw(x1, y1)
x2 =
-1 -1 0 0
y2 =
-1 0 -1 0
The result is not clockwise? Why?
Or
>> [x3 y3] = poly2ccw(x1, y1)
x3 =
0 0 -1 -1
y3 =
0 -1 0 -1
It's not counterclockwise either.
Respuestas (1)
Veda Upadhye
el 15 de Nov. de 2017
Hi,
This is actually the expected behavior of the "poly2cw" function. This function expects its input to be a counter clockwise ordered polygon and simply reorders the vertices bottom to top to change the ordering to clockwise.
If you wish to plot points in the clockwise direction, I would suggest using the "convhull" function before the "poly2cw" function. The "convhull" function converts the unordered set of points to counter-clockwise ordered points. You may then use the "poly2cw" to convert them to clockwise order. Here is an example demonstrating this:
K = convhull(x1,y1);
ccx = x1(K);
ccy = y1(K);
[cx,cy] = poly2cw(ccx,ccy);
Documentation for the "convhull" function can be found here:
Hope this helps!
-Veda
Categorías
Más información sobre Call Python from MATLAB en Centro de ayuda y File Exchange.
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!