• 微信公众号：美女很有趣。 工作之余，放松一下，关注即送10G+美女照片！

# SZTUOJ 1121 – The Area of a Sector

5天前 7次浏览

## SZTUOJ 1013 – The Area of a Sec++tor

### Desc++ription

Given a circle and two points on it, calculate the area of the sector with its central angle no more than 180 degrees.

### Input

There are multiple test cases.
Each line contains 6 float numbers denote the center of the circle xc, yc, the two points on the circle x1, y1 and x2, y2.
1 <= xc, yc, x1, y1, x2, y2 <= 10000.

### Output

The area of the sector. The result should be accurated to three decimal places.

### Sample Input

``````0 0 1 1 -1 1
2.5 2.5 3.25 3.5 3.5 3.25
``````

### Sample Output

``````1.571
0.222
``````

### Hint

With math.h, you could define pi (3.1415926…) as const double pi = acos(-1.0);
Inverse trigonometric function could be obtained by acos, atan, asin, etc..
Be careful that angles like pi in C/C++ are in 3.1415926… type rather than 180.
You’d better use double instead of float. Load double with “%lf” but output it with “%f”.

### Sourc++e

2021 SZTU AI Class Qualifying.

## 思路分析

[S_theta=frac{theta}{2}r^2 (0<thetaleq2pi)
]

[r=sqrt{(x_0-x_1)^2+(y_0-y_1)^2}\
l=sqrt{(x_2-x_1)^2+(y_2-y_1)^2}
]

(triangle OP_1P_2)的中垂线，根据几何性质，有：

[sin{frac{1}{2}angle O}=sin{frac{theta}{2}}=frac{l}{2r}
]

[theta=2arcsin{frac{l}{2r}}
]

## 代码实现

``````// Language: C
#include<stdio.h>
#include<math.h>

typedef struct Point{
double x;
double y;
}point;

int main() {
point o, p1, p2;
double ox, oy, x1, y1, x2, y2;
while (scanf("%lf%lf%lf%lf%lf%lf", &o.x, &o.y, &p1.x, &p1.y, &p2.x, &p2.y) != EOF) {
double r = hypot(p1.x - o.x, p1.y - o.y);
double l = hypot(p1.x - p2.x, p1.y - p2.y);
double theta = 2 * asin(0.5 * l / r);
printf("%.3fn", r * r * theta / 2);
}
return 0;
}
``````