필터 지우기
필터 지우기

Calculate perimeter of a shape using x,y coordinates input to an array

조회 수: 31 (최근 30일)
LR
LR 2021년 5월 9일
편집: LR 2021년 5월 11일
How can I find the perimeter of a shape using x,y coordinates input to an array. The code below adds up the number of sides of the shape instead of the length of the sides which is what I need. The equation for calculating the distance between each pair of x,y points is: sqrt((dataX(i)+1)-dataX(i))^2+((dataY(i)+1)-dataY(i))^2
Many thanks
numberOfCoordinates=input('Please input the number of coordinates:');
for i=1:1:numberOfCoordinates
dataX(i)=input('Please enter the X co-ordinate:')
dataY(i)=input('Please enter the Y co-ordinate:')
end
end
perimeter=0;
for i=1:1:numberOfCoordinates
x=((dataX(i)+1)-dataX(i))^2
y=((dataY(i)+1)-dataY(i))^2
answer=sqrt(sum(x,y))
perimeter=perimeter+answer
end

답변 (1개)

Matt J
Matt J 2021년 5월 9일
pgon=polyshape(dataX,dataY);
perimeter(pgon)
  댓글 수: 5
Matt J
Matt J 2021년 5월 10일
You could just do
dataX(end+1)=dataX(1)
and similarly for dataY.
LR
LR 2021년 5월 11일
편집: LR 2021년 5월 11일
How would I add that to my current code?
Thanks

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

카테고리

Help CenterFile Exchange에서 Elementary Polygons에 대해 자세히 알아보기

태그

Community Treasure Hunt

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

Start Hunting!

Translated by