#include <iostream>
#include <cmath>
#include <iomanip> // For std::fixed and std::setprecision
// Define M_PI if not already defined (common in some compilers)
#ifndef M_PI
#define M_PI 3.14159265358979323846
#endif
// Function to calculate the grazing area
double calculateGrazingArea(double R, double r) {
// This formula applies when the goat is tied to the edge of a circular field,
// and the rope length 'r' allows the goat to graze within the field.
// The problem often involves finding 'r' such that the grazing area is half the field area.
// If the rope is too short to reach the field's center, the grazing area is simply pi * r^2.
if (r <= R) {
return M_PI * r * r / 2.0; // Half circle if tied to edge
} else {
// More complex calculation for when the rope extends beyond the center
// This is a simplified representation, the actual formula is more involved
// and often requires solving a transcendental equation for the angle.
// For a more accurate solution, numerical methods are usually needed.
// This example assumes a scenario where the rope is long enough to cover a significant portion.
double alpha = 2 * acos(R / r); // Angle subtended by the field's radius at the goat's tether point
double area_segment = r * r * alpha - R * sqrt(r * r - R * R);
return M_PI * R * R - area_segment; // Placeholder, actual formula is more specific
}
}
int main() {
double fieldRadius, ropeLength;
std::cout << "Enter the radius of the circular field (R): ";
std::cin >> fieldRadius;
std::cout << "Enter the length of the goat's rope (r): ";
std::cin >> ropeLength;
// In this specific common variation, the third input (theta) is usually derived or part of a more complex scenario.
// For simplicity in this example, we are not directly taking 'theta' as an input for the core calculation,
// as it's often a result of the geometry of R and r.
// If a specific 'theta' is required for a different problem variation, it would be added here.
double grazingArea = calculateGrazingArea(fieldRadius, ropeLength);
std::cout << std::fixed << std::setprecision(4); // Format output to 4 decimal places
std::cout << "The grazing area is: " << grazingArea << std::endl;
return 0;
}