#include <bits/stdc++.h>
using namespace std;
const double PI = acos(-1.0);
const double EPS = 1e-10;
struct Vector {
double x, y, z;
Vector(double a=0, double b=0, double c=0) : x(a), y(b), z(c) {}
Vector operator+(const Vector& o) const {
return Vector(x+o.x, y+o.y, z+o.z);
}
Vector operator-(const Vector& o) const {
return Vector(x-o.x, y-o.y, z-o.z);
}
Vector operator*(double s) const {
return Vector(x*s, y*s, z*s);
}
double dot(const Vector& o) const {
return x*o.x + y*o.y + z*o.z;
}
Vector cross(const Vector& o) const {
return Vector(y*o.z - z*o.y,
z*o.x - x*o.z,
x*o.y - y*o.x);
}
double norm() const {
return sqrt(x*x + y*y + z*z);
}
Vector normalized() const {
double n = norm();
if(n < EPS) return Vector(0,0,0);
return Vector(x/n, y/n, z/n);
}
};
int main(){
ios::sync_with_stdio(false);
cin.tie(0);
int T;
cin >> T;
for(int tc=1; tc<=T; tc++){
int N;
double R;
cin >> N >> R;
vector<pair<double, double>> planets(N);
for(auto &p: planets) cin >> p.first >> p.second;
double total_area =0.0;
for(int i=0; i<N; i++){
// Compute normals
vector<Vector> normals;
for(int j=0; j<N; j++) if(j !=i){
double dx = planets[j].first - planets[i].first;
double dy = planets[j].second - planets[i].second;
double dz = 0.0;
Vector u(dx, dy, dz);
double n_norm = u.norm();
if(n_norm < EPS){
// Same position, but problem states planets do not intersect
continue;
}
u = u.normalized();
Vector ni = u * (-1.0);
normals.push_back(ni);
}
if(normals.empty()){
// Only one planet, entire sphere is blind spot
total_area += 4.0 * PI * R * R;
continue;
}
// Find intersection of hemispheres
// Collect all intersection points
vector<Vector> candidates;
int K = normals.size();
for(int a=0; a<K; a++) {
for(int b=a+1; b<K; b++){
Vector cross_prod = normals[a].cross(normals[b]);
double cp_norm = cross_prod.norm();
if(cp_norm < EPS) continue; // Parallel or antiparallel
Vector p1 = cross_prod.normalized();
Vector p2 = p1 * (-1.0);
// Check if p1 and p2 satisfy all p • ni >=0
auto check = [&](const Vector& p) -> bool {
for(auto &ni : normals){
if(p.dot(ni) < -EPS) return false;
}
return true;
};
if(check(p1)) candidates.push_back(p1);
if(check(p2)) candidates.push_back(p2);
}
}
// Also, the points where n_i are themselves could be part of the polygon if they satisfy all
for(auto &ni : normals){
// Hemisphere boundary point can be part of intersection
// But usually already covered by intersection points
// To be safe, you can skip
}
// Remove duplicates
vector<Vector> unique_candidates;
for(auto &p : candidates){
bool unique = true;
for(auto &q : unique_candidates){
double dp = p.dot(q);
if(dp > 1.0 - 1e-8){
unique = false;
break;
}
}
if(unique) unique_candidates.push_back(p);
}
// If no candidates, check if all normals have a common intersection
// It could be the entire hemisphere if all normals are same
// But in practice, with at least one hemisphere, candidates should exist
// If no candidates, possible the blind spot is empty or full hemisphere
if(unique_candidates.empty()){
// Check if all normals are same
// The intersection is the hemisphere defined by one normal
// Area is 2 pi R^2
// Check if all normals are same direction
bool same = true;
for(int a=1; a<K; a++) {
double dp = normals[0].dot(normals[a]);
if(dp < 1.0 - 1e-8){
same = false;
break;
}
}
if(same){
// Entire hemisphere
total_area += 2.0 * PI * R * R;
}
else{
// No intersection
// But this should not happen as for N>=2, at least one candidate should exist
// To be safe, set area to 0
}
continue;
}
// Now sort the unique_candidates in cyclic order
// Compute centroid
Vector centroid(0,0,0);
for(auto &p : unique_candidates) centroid = centroid + p;
double c_norm = centroid.norm();
if(c_norm < EPS){
// Points are uniform, the entire sphere is intersection
total_area += 4.0 * PI * R * R;
continue;
}
centroid = centroid * (1.0 / c_norm);
// Find orthonormal basis u, v
Vector arbitrary;
if(abs(centroid.x) < 1.0 - 1e-8 || abs(centroid.y) > 1e-8){
arbitrary = Vector(0,0,1);
}
else{
arbitrary = Vector(1,0,0);
}
Vector u = centroid.cross(arbitrary).normalized();
Vector v = centroid.cross(u);
// Compute angles
vector<pair<double, Vector>> angles;
for(auto &p : unique_candidates){
double angle = atan2(p.dot(v), p.dot(u));
if(angle < 0) angle += 2.0 * PI;
angles.emplace_back(angle, p);
}
sort(angles.begin(), angles.end());
// Extract sorted points
vector<Vector> sorted_p;
for(auto &[angle, p] : angles) sorted_p.push_back(p);
// Compute internal angles
int V = sorted_p.size();
if(V <3){
// Not a polygon, area is 0 or hemisphere
// Check if V==2 and they are antipodal
if(V==2){
// Two points, defines a great circle, intersection is a lune
// Area of lune where p1 and p2 are boundary
// But p1 and p2 satisfy all p • ni >=0, likely the entire sphere
total_area += 4.0 * PI * R * R;
}
else{
// Single point, area is 0
}
continue;
}
// Compute spherical excess
double sum_angles =0.0;
for(int i=0; i<V; i++){
Vector A = sorted_p[i];
Vector B = sorted_p[(i+1)%V];
Vector C = sorted_p[(i+2)%V];
// Compute angle at B between BA and BC
// Project A and C onto tangent plane at B
Vector BA = A - B * (A.dot(B));
Vector BC = C - B * (C.dot(B));
double BA_norm = BA.norm();
double BC_norm = BC.norm();
if(BA_norm < EPS || BC_norm < EPS){
continue;
}
BA = BA * (1.0 / BA_norm);
BC = BC * (1.0 / BC_norm);
double dot_prod = BA.dot(BC);
// Clamp due to numerical errors
if(dot_prod > 1.0) dot_prod =1.0;
if(dot_prod < -1.0) dot_prod = -1.0;
double angle = acos(dot_prod);
sum_angles += angle;
}
double spherical_excess = sum_angles - (V -2)*PI;
// Area is spherical_excess * R^2
double area = spherical_excess * R * R;
total_area += area;
}
// Output
cout << fixed << setprecision(3);
cout << "Case #" << tc << ": " << fixed << setprecision(3) << total_area << "\n";
}
}