#include <iostream>
#include <cmath>
class S {
double px, py;
double x_intercept, y_intercept;
public:
S(double x, double y) : px(x), py(y) {}
void getXIntercept(double &x) { x = x_intercept; }
void setYIntercept(double y) {
y_intercept = y;
/* px : x = (y - py) : y -> x(y - py) = px.y*/
x_intercept = px * y / (y - py);
}
};
double len(double x, double y) { /* len P(0, x) - P(y, 0) */
return std::sqrt(x * x + y * y);
}
double const ALPHA = 2.0;
double const delta = 1.0e-4;
int main() {
bool exhausted = false;
double x, y, l;
S s(1.0, 1.0);
y = 1.0 + delta;
for(;;) {
s.setYIntercept(y);
s.getXIntercept(x);
if (x < y) {
exhausted = true;
break;
}
if (std::fabs((l = len(x, y)) - 4.0) < ALPHA * delta)
break;
std::cout << (y += delta) << ':' << l << std::endl;
}
if (exhausted)
std::cout << "not found." << std::endl;
else
std::cout << "y = " << y << ", x = " << x << ", S = " << x * y << std::endl;
return 0;
}
/* end */