在本教程中,我们将讨论一个程序来查找圆形线段的区域。
在给定的球体中制作和弦会将其分为两个部分-大和小。给定小半径圆弧的半径和半径,我们需要找到两个圆弧的面积。
#include <bits/stdc++.h> using namespace std; float pi = 3.14159; //查找段的区域 float area_of_segment(float radius, float angle){ float area_of_sector = pi * (radius * radius)*(angle / 360); float area_of_triangle = (float)1 / 2 *(radius * radius) * sin((angle * pi) / 180); return area_of_sector - area_of_triangle; } int main() { float radius = 10.0, angle = 90.0; cout << "Area of minor segment = " << area_of_segment(radius, angle) << endl; cout << "Area of major segment = " << area_of_segment(radius, (360 - angle)); return 0; }
输出结果
Area of minor segment = 28.5397 Area of major segment = 285.619