필터 지우기
필터 지우기

poly2cw doesn't work for this simple rectangle. I have an example here. Could you please check this code?

조회 수: 2 (최근 30일)
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

채택된 답변

Sean de Wolski
Sean de Wolski 2016년 8월 9일
편집: Sean de Wolski 2016년 8월 9일
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
Kaveh Gharibi
Kaveh Gharibi 2016년 8월 9일
Thank you! That actually works great! Since the geometry is changing in my code in each time step, the geometry is not convex always and I think can use alphashape as you said or boundry.

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

추가 답변 (1개)

KSSV
KSSV 2016년 8월 9일
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
Kaveh Gharibi
Kaveh Gharibi 2016년 8월 9일
편집: Kaveh Gharibi 2016년 8월 9일
Thank you for response. But, maybe I was not clear. If you look at the results in the loop, you will see that the polygone is not clockwise. If you run the code you shared here, it will give you this plot below. This is not a clockwise polygon

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

카테고리

Help CenterFile Exchange에서 Bounding Regions에 대해 자세히 알아보기

Community Treasure Hunt

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

Start Hunting!

Translated by