#include #include #include using namespace std; class point{ public: double x; double y; }; double R2D(double r){ return r*180/M_PI; } double D2R(double d){ return d*M_PI/180; } int main(){ int w,l; cin >> w >> l; double r; cin >> r; point ball1; cin >> ball1.x >> ball1.y; point ball2; cin >> ball2.x >> ball2.y; point ball3; cin >> ball3.x >> ball3.y; double h; cin >> h; bool possible = true; // find conditions that can't happen if(ball1.x < ball2.x) possible = false; if(ball1.y > ball2.y) possible = false; if(ball1.x > ball3.x) possible = false; if(ball1.y > ball3.y) possible = false; double ball2_theta = M_PI - atan((l - ball2.y)/ball2.x); // cout << "ball 2 needs to be at angle " << R2D(ball2_theta) << endl; double cue2_impact_angle = M_PI-ball2_theta; // cout << "angle from left edge: " << R2D(cue2_impact_angle) << endl; point cue2_impact; cue2_impact.x = ball2.x+2*r*cos(cue2_impact_angle); cue2_impact.y = ball2.y-2*r*sin(cue2_impact_angle); // cout << "Cue hits ball 2 at (" << cue2_impact.x << "," << cue2_impact.y << ")" << endl; double ball3_theta = atan((l-ball3.y)/(w-ball3.x)); // cout << "Ball 3 needs to be going at angle " << R2D(ball3_theta) << endl; point ball1_impact; ball1_impact.x = ball3.x - 2*r*cos(ball3_theta); ball1_impact.y = ball3.y - 2*r*sin(ball3_theta); // cout << "Ball 1 hits ball 3 at (" << ball1_impact.x << "," << // ball1_impact.y << ")" << endl; double ball1_theta = atan((ball1_impact.y-ball1.y)/(ball1_impact.x-ball1.x)); // cout << "Ball 1 hits ball 3 at angle " << R2D(ball1_theta) << endl; point cue1_impact; cue1_impact.x = ball1.x-2*r*cos(ball1_theta); cue1_impact.y = ball1.y-2*r*sin(ball1_theta); // cout << "Cue hits ball 1 at (" << cue1_impact.x << "," << cue1_impact.y << ")" << endl; double cue_dx = cue1_impact.x - cue2_impact.x; double cue_dy = cue2_impact.y-cue1_impact.y; // cout << "Cue travels (" << cue_dx << ", " << cue_dy << ") between balls 1 and 2 " << endl; double cue_1_2_impact_angle = M_PI-atan(cue_dy/cue_dx); // cout << "Cue comes off of ball 1 at angle " << R2D(cue_1_2_impact_angle) << endl; double normal_angle = ball1_theta+M_PI/2; double part1 = cue_1_2_impact_angle- normal_angle; double part2 = M_PI-normal_angle; double theta = M_PI-part1-part2; // cout << "Cue comes into ball 1 at angle " << R2D(theta) << endl; double table_x = (cue1_impact.y-h)/ tan(M_PI-theta); table_x = table_x + cue1_impact.x; if(table_x < r || table_x > w-r) possible = false; if(possible){ theta = theta * 180 / M_PI; cout << fixed << setprecision(2) << table_x << " " << theta << endl; } else cout << "impossible" << endl; return 0; }