uva 11178 Morley's Theorem (2D Geometry)
2013-04-29 20:48
453 查看
http://uva.onlinejudge.org/index.php?option=com_onlinejudge&Itemid=8&page=show_problem&problem=2119
在uva跪了一个下午后提交这题,AC了。这题更简单,就是套入几何模板,求出交点就可以了。
这题测试通过了几何模板中的相交判断并求出交点等几个函数。
代码如下:
View Code
——written by Lyon
在uva跪了一个下午后提交这题,AC了。这题更简单,就是套入几何模板,求出交点就可以了。
这题测试通过了几何模板中的相交判断并求出交点等几个函数。
代码如下:
View Code
#include <cstdio> #include <cstring> #include <cmath> #include <vector> #include <iostream> #include <algorithm> using namespace std; #define REP(i, n) for (int i = 0; i < (n); i++) struct Point { double x, y; Point() {} Point(double x, double y) : x(x), y(y) {} } ; template<class T> T sqr(T x) { return x * x;} // basic calculations typedef Point Vec; Vec operator + (Vec a, Vec b) { return Vec(a.x + b.x, a.y + b.y);} Vec operator - (Vec a, Vec b) { return Vec(a.x - b.x, a.y - b.y);} Vec operator * (Vec a, double p) { return Vec(a.x * p, a.y * p);} Vec operator / (Vec a, double p) { return Vec(a.x / p, a.y / p);} const double eps = 1e-8; int sgn(double x) { return fabs(x) < eps ? 0 : (x < 0 ? -1 : 1);} bool operator < (Point a, Point b) { return a.x < b.x || (a.x == b.x && a.y < b.y);} bool operator == (Point a, Point b) { return sgn(a.x - b.x) == 0 && sgn(a.y - b.y) == 0;} double dotDet(Vec a, Vec b) { return a.x * b.x + a.y * b.y;} double vecLen(Vec x) { return sqrt(sqr(x.x) + sqr(x.y));} double angle(Vec a, Vec b) { return acos(dotDet(a, b) / vecLen(a) / vecLen(b));} double crossDet(Vec a, Vec b) { return a.x * b.y - a.y * b.x;} double triArea(Point a, Point b, Point c) { return fabs(crossDet(b - a, c - a));} Vec rotate(Vec x, double rad) { return Vec(x.x * cos(rad) - x.y * sin(rad), x.x * sin(rad) + x.y * cos(rad));} Vec normal(Vec x) { double len = vecLen(x); return Vec(- x.y / len, x.x / len); } struct Line { Point s, t; Line() {} Line(Point s, Point t) : s(s), t(t) {} } ; typedef Line Seg; bool onSeg(Point x, Point a, Point b) { return sgn(crossDet(a - x, b - x)) == 0 && sgn(dotDet(a - x, b - x)) < 0;} bool onSeg(Point x, Seg s) { return onSeg(x, s.s, s.t);} // 0 : not intersect // 1 : proper intersect // 2 : improper intersect int segIntersect(Point a, Point c, Point b, Point d) { Vec v1 = b - a, v2 = c - b, v3 = d - c, v4 = a - d; int a_bc = sgn(crossDet(v1, v2)); int b_cd = sgn(crossDet(v2, v3)); int c_da = sgn(crossDet(v3, v4)); int d_ab = sgn(crossDet(v4, v1)); if (a_bc * c_da > 0 && b_cd * d_ab > 0) return 1; if (onSeg(b, a, c) && c_da) return 2; if (onSeg(c, b, d) && d_ab) return 2; if (onSeg(d, c, a) && a_bc) return 2; if (onSeg(a, d, b) && b_cd) return 2; return 0; } int segIntersect(Seg a, Seg b) { return segIntersect(a.s, a.t, b.s, b.t);} // point of the intersection of 2 lines Point lineIntersect(Point P, Vec v, Point Q, Vec w) { Vec u = P - Q; double t = crossDet(w, u) / crossDet(v, w); return P + v * t; } Point lineIntersect(Line a, Line b) { return lineIntersect(a.s, a.t - a.s, b.s, b.t - b.s);} // directed distance double pt2Line(Point x, Point a, Point b) { Vec v1 = b - a, v2 = x - a; return crossDet(v1, v2) / vecLen(v1); } double pt2Line(Point x, Line L) { return pt2Line(x, L.s, L.t);} double pt2Seg(Point x, Point a, Point b) { if (a == b) return vecLen(x - a); Vec v1 = b - a, v2 = x - a, v3 = x - b; if (sgn(dotDet(v1, v2)) < 0) return vecLen(v2); if (sgn(dotDet(v1, v3)) > 0) return vecLen(v3); return fabs(crossDet(v1, v2)) / vecLen(v1); } double pt2Seg(Point x, Seg s) { return pt2Seg(x, s.s, s.t);} struct Poly { vector<Point> pt; Poly() {} Poly(vector<Point> pt) : pt(pt) {} double area() { double ret = 0.0; int sz = pt.size(); for (int i = 1; i < sz; i++) { ret += crossDet(pt[i], pt[i - 1]); } return fabs(ret / 2.0); } } ; /****************** template above *******************/ Point p[3]; Point cal(Point a, Point b, Point c) { double angB = fabs(angle(c - b, a - b) / 3.0); double angC = fabs(angle(b - c, a - c) / 3.0); Vec v1, v2; v1 = rotate(c - b, angB); v2 = rotate(b - c, -angC); // return lineIntersect(Line(b, b + v1), Line(c, c + v2)); return lineIntersect(b, v1, c, v2); } int main() { // freopen("in", "r", stdin); int n; cin >> n; while (n--) { for (int i = 0; i < 3; i++) { cin >> p[i].x >> p[i].y; } for (int i = 0; i < 3; i++) { Point tmp = cal(p[i % 3], p[(i + 1) % 3], p[(i + 2) % 3]); if (i) putchar(' '); printf("%.10f %.10f", tmp.x, tmp.y); } cout << endl; } return 0; }
——written by Lyon
相关文章推荐
- Uva 11178 Morley's Theorem
- UVA 11178 Morley's Theorem(旋转+直线交点)
- UVA 11178 - Morley's Theorem 向量
- UVa 11178 (简单练习) Morley's Theorem
- uva 11178 Morley's Theorem(计算几何-点和直线)
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
- uva 11178 Morley's Theorem
- 简单几何(求交点) UVA 11178 Morley's Theorem
- UVa 11178 Morley's Theorem (几何问题)
- UVA 11178 Morley's Theorem (计算几何)
- UVA - 11178 Morley's Theorem
- 【UVa 11178】Morley's Theorem (计算几何)
- UVA 11178 || Morley's Theorem (向量旋转求交点
- Uva 12304 2D Geometry 110 in 1!
- uva11178 Morley's Theorem
- Uva 12304 2D Geometry 110 in 1!(圆综合题)
- UVA 12304 - 2D Geometry 110 in 1!(计算几何)
- Uva - 11178 - Morley's Theorem
- uva 11178 - Morley's Theorem(训练指南)
- Uva 12304 2D Geometry 110 in 1!