이 문제에서는 다각형의 좌표가 제공됩니다. 우리의 임무는 주어진 폴리곤이 같은지 여부를 확인하는 프로그램을 만드는 것입니다.
동일한 모양 둘레가 도형의 면적과 같은 도형입니다.
문제를 이해하기 위해 예를 들어 보겠습니다.
입력: 다각형[][] ={{0, 0}, {5, 7}, {2, 0}}
출력: 동등하지 않음
설명:
둘레 =18.21
면적 =7
해결 방법:
문제의 해결책은 모양의 면적과 둘레를 찾은 다음 두 값을 비교하여 주어진 모양이 동일한 모양인지 아닌지 날씨를 확인하는 것입니다.
좌표를 사용하여 둘레를 찾는 것은 간단합니다. 좌표를 사용하여 길이를 찾고 둘레를 찾기만 하면 됩니다.
둘레 =측면1 + 측면2 + 측면3
좌표를 사용하여 영역을 찾으려면 공식을 사용하여 수행됩니다.
면적 =1/2 {(x_1 y_2+ x_2 y_3 + ....x_(n-1) y_n + x_n y_1 ) - (x_2 y_1 + x_3 y_2 + ....+ x_n y_(n-1) + x_1 n )}
우리 솔루션의 작동을 설명하는 프로그램,
예시
#include <bits/stdc++.h>
using namespace std;
double findShapeArea(double cord[][2], int n)
{
double area = 0.0;
int j = n - 1;
for (int i = 0; i < n; i++) {
area += (float)(cord[j][0] + cord[i][0]) * (cord[j][1] - cord[i][1]);
j = i;
}
return abs(area / 2.0);
}
double findShapeperimeter(double cord[][2], int n) {
double perimeter = 0.0;
int j = n - 1;
for (int i = 0; i < n; i++) {
perimeter += sqrt((cord[j][0] - cord[i][0]) * (cord[j][0] - cord[i][0]) + (cord[j][1] - cord[i][1]) * (cord[j][1] - cord[i][1]));
j = i;
}
return perimeter;
}
int isEquableShape(double cord[][2], int n)
{
int area = findShapeArea(cord, n);
int peri = findShapeperimeter(cord, n);
cout<<"The area of the given shape is "<<area<<endl;
cout<<"The perimeter of the given shape is "<<peri<<endl;
if (area == peri)
return 1;
else
return 0;
}
int main() {
int n = 3;
double cord[n][2] = {{0, 0} , {5, 7}, {2, 0}};
if (isEquableShape(cord, n))
cout<<"The given shape is an equable shape";
else
cout<<"The given shape is not an equable shape";
return 0;
} 출력 -
The area of the given shape is 7 The perimeter of the given shape is 18 The given shape is not an equable shape