#include #include #include #include #include using namespace std; vector > cross_candidates(double x1, double y1, double x2, double y2, double px, double py, double cx, double cy){ vector > result; double a = y2 - y1; double b = x1 - x2; double c = x2*y1 - x1*y2; double r2 = (px-cx)*(px-cx) + (py-cy)*(py-cy); double x_from = min(x1,x2); double x_to = max(x1,x2); double y_from = min(y1,y2); double y_to = max(y1,y2); if (b == 0){ double x = x1; double Dy = r2 - (x-cx)*(x-cx); if (Dy < 0) return result; else if (Dy == 0){ if ((y_from <= cy) && (cy <= y_to)) result.push_back(pair(x,cy)); return result; }else { double y_1 = cy+sqrt(Dy); double y_2 = cy-sqrt(Dy); if ((y_from <= y_1) && (y_1 <= y_to)) result.push_back(pair(x,y_1)); if ((y_from <= y_2) && (y_2 <= y_to)) result.push_back(pair(x,y_2)); return result; } }else{ double D = -2*b*b*(a*c*cx+a*b*cx*cy+b*c*cy) + a*a*b*b*(r2-cx*cx)+ b*b*b*b*(r2-cy*cy) - b*b*c*c; if (D < 0){ return result; }else if (D == 0){ double x = (-a*(c+cy*b)+b*b*cx)/(a*a+b*b); double y = -a/b*x - c/b; if ((x_from <= x) && (x <= x_to)) result.push_back(pair(x,y)); return result; }else{ double x_com = (-a*(c+cy*b)+b*b*cx); double x_1 = (x_com + sqrt(D))/(a*a+b*b); double x_2 = (x_com - sqrt(D))/(a*a+b*b); double y_1 = -a/b*x_1 - c/b; double y_2 = -a/b*x_2 - c/b; if ((x_from <= x_1) && (x_1 <= x_to)) result.push_back(pair(x_1,y_1)); if ((x_from <= x_2) && (x_2 <= x_to)) result.push_back(pair(x_2,y_2)); return result; } } } double angle_between(double sx, double sy, double tx, double ty, double cx, double cy){ double args = atan2(sy-cy,sx-cx); double argt = atan2(ty-cy,tx-cx); if (args < 0) args = M_PI+args + M_PI; if (argt < 0) argt = M_PI+argt + M_PI; if (argt > args) return (argt - args); else return (argt - args + 2.0 * M_PI); } int main(){ int N, M; while(cin >> N >> M){ if ((N == 0) && (M == 0)) break; vector > O; vector > I; double cx, cy; for (int i = 0; i < N; i++){ double tempx, tempy; cin >> tempx >> tempy; O.push_back(pair(tempx, tempy)); } O.push_back(O[0]); for (int i = 0; i < M; i++){ double tempx, tempy; cin >> tempx >> tempy; I.push_back(pair(tempx, tempy)); } I.push_back(I[0]); cin >> cx >> cy; vector angles; angles.push_back(2*M_PI); for (int i = 0; i < N; i++){ for (int j = 0; j < M; j++){ vector > candidates = cross_candidates(O[i].first, O[i].second, O[i+1].first, O[i+1].second, I[j].first, I[j].second, cx, cy); for (int k = 0; k < (int)candidates.size(); k++){ double angle = angle_between(I[j].first, I[j].second, candidates[k].first, candidates[k].second, cx, cy); angles.push_back(angle); } } } for (int i = 0; i < M; i++){ for (int j = 0; j < N; j++){ vector > candidates = cross_candidates(I[i].first, I[i].second, I[i+1].first, I[i+1].second, O[j].first, O[j].second, cx, cy); for (int k = 0; k < (int)candidates.size(); k++){ double angle = angle_between(candidates[k].first, candidates[k].second, O[j].first, O[j].second, cx, cy); angles.push_back(angle); } } } double angle = *min_element(angles.begin(), angles.end()); if (angle == (2*M_PI)) printf("360\n"); else printf("%.7llf\n", angle * 360 / (2*M_PI)); } return 0; }