poly2cw doesn't work for this simple rectangle. I have an example here. Could you please check this code?
1 view (last 30 days)
Show older comments
Kaveh Gharibi
on 9 Aug 2016
Commented: Kaveh Gharibi
on 9 Aug 2016
Xs{1}=[
0
1
1
1
0
1]
Ys{1}=[1.0000
1.0000
0.0101
0
0
0.5000]
[xr,yr]=poly2cw( Xs{1} , Ys{1} )
for i=1:length(xr)
plot(xr(i),yr(i),'or')
hold on
drawnow
pause
end
0 Comments
Accepted Answer
Sean de Wolski
on 9 Aug 2016
Edited: Sean de Wolski
on 9 Aug 2016
EDIT with more info from comments
It sounds like what you really want is the convex hull of your points since your points, ordered like they are now, do not create a rectangle.
dt = delaunayTriangulation(xr,yr);
hullidx = convexHull(dt);
xa = xr(hullidx);
ya = yr(hullidx);
[xa,ya] = poly2cw(xa,ya);
comet(xa,ya)
If you don't want the convex hull but do want to encourage your shape to be close to convex, then look at alphaShape which will also do a triangulation for you but will allow concavities below a certain size based on alpha.
Original
It starts in the upper left hand corner at (0,1) and moves to (1,1) and then down to (1,0) before completing the triangle. This is indeed clockwise
comet(xr,yr)
3 Comments
More Answers (1)
KSSV
on 9 Aug 2016
Xs=[ 0
1
1
1
0
1] ;
Ys=[1.0000
1.0000
0.0101
0
0
0.5000] ;
[xr,yr]=poly2cw( Xs,Ys) ;
plot(xr,yr)
2 Comments
See Also
Categories
Find more on Bounding Regions in Help Center and File Exchange
Products
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!