Straight line through center of polygon

조회 수: 5 (최근 30일)
Sunetra Banerjee
Sunetra Banerjee 2021년 5월 24일
댓글: Sunetra Banerjee 2021년 5월 24일
Hi,
I have polygon ROI and I need to draw a straight line through the center of the polygon and through the middle of superior (S1 & S2) / inferior (I1 & I2) points of the ROI. In my case, the ROI polygons are of various sizes and shapes. I am attaching a picture of a sample ROI of my work. Please help me regarding this.

채택된 답변

KSSV
KSSV 2021년 5월 24일
편집: KSSV 2021년 5월 24일
If you have the vertices of the polygon, you can fit a striaght line and draw it.
Example:
P = [0 0 ; 1 0 ; 1 1 ; 0 1] ; % vertices of the polygon
p = polyfit(P(:,1),P(:,2),1) ; % fit a striaght line
xi = P(:,1) ;
yi = polyval(p,xi) ;
patch(P(:,1),P(:,2),'r')
hold on
plot(xi,yi,'b')
  댓글 수: 2
Sunetra Banerjee
Sunetra Banerjee 2021년 5월 24일
Hi KSVV,
Thanks for your answer. I don't have the exact vertices of the polygon. How to get that?
Sunetra Banerjee
Sunetra Banerjee 2021년 5월 24일
If I be more specific, I need the vertices of the polygon.

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

추가 답변 (0개)

Community Treasure Hunt

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

Start Hunting!

Translated by