设为首页 加入收藏

TOP

UVA 12304 - 2D Geometry 110 in 1!(计算几何)(二)
2015-11-21 01:05:16 】 浏览:5296
Tags:UVA 12304 Geometry 110 计算 几何
ntCirclesWithRadius(Circle c1, Circle c2, double r, Point *sol){ double dis1 = c1.r + r + r + c2.r; double dis2= Length(c1.c - c2.c); if(dcmp(dis1 - dis2) < 0) return 0; Vector u = c2.c - c1.c; double t = (r + c1.r) / Length(u); if(dcmp(dis1 - dis2)==0){ Point p0 = c1.c + u * t; sol[0] = p0; return 1; } double aa = Length(c1.c - c2.c); double bb = r + c1.r, cc = r + c2.r; double rad = acos((aa * aa + bb * bb - cc * cc) / (2 * aa * bb)); Vector w = Rotate(u, rad); Point p0 = c1.c + w * t; sol[0] = p0; w = Rotate(u, -rad); p0 = c1.c + w * t; sol[1] = p0; return 2; } char op[25]; Point p[4]; double r[3]; int main() { while (~scanf("%s", op)) { if (strcmp(op, "CircumscribedCircle") == 0) { for (int i = 0; i < 3; i++) p[i].read(); Circle ans = CircumscribedCircle(p[0], p[1], p[2]); printf("(%.6f,%.6f,%.6f)\n", ans.c.x, ans.c.y, ans.r); } else if (strcmp(op, "InscribedCircle") == 0) { for (int i = 0; i < 3; i++) p[i].read(); Circle ans = InscribedCircle(p[0], p[1], p[2]); printf("(%.6f,%.6f,%.6f)\n", ans.c.x, ans.c.y, ans.r); } else if (strcmp(op, "TangentLineThroughPoint") == 0) { p[0].read(); scanf("%lf", &r[0]); p[1].read(); Vector v[3]; int tot = getTangents(p[1], Circle(p[0], r[0]), v); double ans[3]; for (int i = 0; i < tot; i++) ans[i] = RealAngleWithX(v[i]); sort(ans, ans + tot); printf("["); for (int i = 0; i < tot; i++) { printf("%.6f", ans[i]); if (i != tot - 1) printf(","); } printf("]\n"); } else if (strcmp(op, "CircleThroughAPointAndTangentToALineWithRadius") == 0) { for (int i = 0; i < 3; i++) p[i].read(); scanf("%lf", &r[0]); vector ans; int tot = CircleThroughAPointAndTangentToALineWithRadius(p[0], p[1], p[2] - p[1], r[0], ans); sort(ans.begin(), ans.end()); printf("["); for (int i = 0; i < tot; i++) { printf("(%.6f,%.6f)", ans[i].x, ans[i].y); if (i != tot - 1) printf(","); } printf("]\n"); } else if (strcmp(op, "CircleTangentToTwoLinesWithRadius") == 0) { Point ans[4]; for (int i = 0; i < 4; i++) p[i].read(); scanf("%lf", &r[0]); int tot = CircleThroughAPointAndTangentALineWithRadius(p[0], p[1] - p[0], p[3], p[3] - p[2], r[0], ans); sort(ans, ans + tot); printf("["); for (int i = 0; i < tot; i++) { printf("(%.6f,%.6f)", ans[i].x, ans[i].y); if (i != tot - 1) printf(","); } printf("]\n"); } else { p[0].read(); scanf("%lf", &r[0]); p[1].read(); scanf("%lf", &r[1]); scanf("%lf", &r[2]); Point ans[4]; int tot = CircleTangentToTwoDisjointCirclesWithRadius(Circle(p[0], r[0]), Circle(p[1], r[1]), r[2], ans); sort(ans, ans + tot); printf("["); for (int i = 0; i < tot; i++) { printf("(%.6f,%.6f)", ans[i].x, ans[i].y); if (i != tot - 1) printf(","); } printf("]\n"); } } return 0; }

首页 上一页 1 2 下一页 尾页 2/2/2
】【打印繁体】【投稿】【收藏】 【推荐】【举报】【评论】 【关闭】 【返回顶部
上一篇LeetCode:Jump Game 下一篇LeetCode| Triangle 三角矩阵的最..

最新文章

热门文章

Hot 文章

Python

C 语言

C++基础

大数据基础

linux编程基础

C/C++面试题目