UVa 11178 Morley's Theorem (几何问题)
2016-05-31 20:19
405 查看
题意:给定三角形的三个点,让你求它每个角的三等分线所交的顶点。
析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点,
以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了。
要求BD和CD就得先求那个夹角ABC和ACD,然后三等分。
代码如下:
析:根据自己的以前的数学知识,应该很容易想到思想,比如D点,就是应该求直线BD和CD的交点,
以前还得自己算,现在计算机帮你算,更方便,主要注意的是旋转是顺时针还是逆时针,不要搞错了。
要求BD和CD就得先求那个夹角ABC和ACD,然后三等分。
代码如下:
#include <iostream> #include <cstdio> #include <cstring> #include <cmath> using namespace std; const int maxn = 500 + 10; const double eps = 1E-10; struct Point{ double x, y; Point(double xx = 0, double yy = 0) : x(xx), y(yy) { } }; typedef Point Vector; Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y); } Vector operator - (Vector A, Vector B) { return Vector(A.x-B.x, A.y-B.y); } Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p); } double Dot(Vector A, Vector B){ return A.x*B.x + A.y*B.y; } double Length(Vector A){ return sqrt(Dot(A, A)); } double Angle(Vector A, Vector B){ return acos(Dot(A, B) / Length(A) / Length(B)); } double Cross(Vector A, Vector B){ return A.x*B.y - A.y*B.x; } Vector Rotate(Vector A, double rad){ return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad)); } Point GetLineIntersection(Point P, Vector v, Point Q, Vector w){ Vector u = P - Q; double t = Cross(w, u) / Cross(v, w); return P + v*t; } Point solve(Point A, Point B, Point C){ double abc = Angle(A-B, C-B) / 3.0; Vector BD = Rotate(C-B, abc); double acb = Angle(A-C, B-C) / 3.0; Vector CD = Rotate(B-C, -acb); return GetLineIntersection(B, BD, C, CD); } int main(){ int T; cin >> T; Point A, B, C, D, E, F; double x, y; while(T--){ scanf("%lf %lf", &x, &y); A = Point(x, y); scanf("%lf %lf", &x, &y); B = Point(x, y); scanf("%lf %lf", &x, &y); C = Point(x, y); D = solve(A, B, C); E = solve(B, C, A); F = solve(C, A, B); printf("%.6lf %.6lf %.6lf %.6lf %.6lf %.6lf\n", D.x, D.y, E.x, E.y, F.x, F.y); } return 0; }
相关文章推荐
- Android中pendingIntent的深入理解
- MIN-IP报文解析
- iOS-UIScrollView-图片缩放
- 重写与重载
- 第14周-阅读程序(2)
- OpenCV2之Mat简介
- 投票操作管理系统
- SVM入门(七)为何需要核函数
- hdu1151(二分图最大独立集)
- 优秀网址
- hdu1285 确定比赛名次(拓扑排序)
- C++之对象的new与delete
- hdu3068——最长回文
- 设计模式—简单工厂模式
- OS_ioStream
- ofbiz详解(Java开放电子商务平台)
- 立体类族共有的抽象类
- Android开发陷阱:利用PendingIntent传递唯一的Intent
- php项目开发经验-2个月学习php经历
- HDU 5363 Key Set