uva 11178 - Morley's Theorem(训练指南)
来源:互联网 发布:一流程序员算法 编辑:程序博客网 时间:2024/06/05 17:08
思路:这题注意练习一下向量的旋转,和直线的相交。
注意代码中用vector表示向量,用point表示点,这一点还是非常好的。
今天是六一儿童节哈,在图书馆A题,呵呵。
计算几何不同于解析几何,计算几何对误差非常敏感,解析几何用一个点和一个斜率表示一条不垂直X轴的直线;计算几何用一个点和一个向量同样可以表示二维平面的
一条直线而且即使直线垂直X轴也不需要特殊处理。 所以两条用向量表示的直线在相交的条件下就可以求解交点了。
题目中主要是直线的旋转,然后是用向量表示的直线求解交点!
#include <iostream>#include <cstdio>#include <cstdlib>#include <cmath>#include <algorithm>using namespace std;struct point { double x; double y; point(double x = 0, double y = 0) : x(x), y(y) {}};typedef point Vector;Vector operator - (point A, point B) { return point(A.x-B.x, A.y-B.y);}Vector operator + (Vector A, Vector B) { return Vector(A.x+B.x, A.y+B.y);}const double eps = 1e-10;int dcmp(double x) { if(fabs(x) < eps) return 0; if(x > 0) return 1; return -1;}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 Cross(Vector A, Vector B) { return A.x*B.y - A.y*B.x;}Vector operator * (Vector A, double p) { return Vector(A.x*p, A.y*p);}double Angle(Vector A, Vector B) { return acos((Dot(A, B))/Length(A)/Length(B));}Vector Rotate(Vector A, double rad) { //把向量旋转rad弧度, 有兴趣可以用三角函数推导一下 return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));}//调用前确保两条直线相交。当且仅当Cross(v,w)非零。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 read_point() { point tmp; scanf("%lf%lf", &tmp.x, &tmp.y); return tmp;}point getD(point A, point B, point C) { Vector v1 = C - B, v2 = A - B; double a1 = Angle(v1, v2); //两个向量的夹角。 v1 = Rotate(v1, a1/3); //逆时针旋转,弧度. Vector v3 = A - C, v4 = B - C; double a3 = Angle(v3, v4); v3 = Rotate(v3, a3*2/3); return GetLineIntersection(B, v1, C, v3);//求直线的交点.}int main(){ int T; point A, B, C, D, E, F; scanf("%d", &T); while(T--) { A = read_point(); B = read_point(); C = read_point(); D = getD(A, B, C); E = getD(B, C, A); F = getD(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;}/**测试数据:211 1 2 2 1 20 0 100 0 50 501.316987 1.816987 1.183013 1.683013 1.366025 1.63397556.698730 25.000000 43.301270 25.000000 50.000000 13.397460**/
- uva 11178 - Morley's Theorem(训练指南)
- uva 11178 - Morley's Theorem(几何)
- UVA 11178 Morley's Theorem(几何)
- UVA 11178 Morley's Theorem(Morley定理)
- 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-11178Morley'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
- C#实现P2P应用程序
- 无线模块调试总结
- Tomcat_曹建波的个人总结(第一次课)
- JavaScript面向切面编程
- VC++6.0转到VS2008
- uva 11178 - Morley's Theorem(训练指南)
- http协议_齐禄禄的个人总结(第二次课)
- Java Dao工厂设计模式
- Servlet开发基础_常瑞鹏的个人总结(第三次课)
- 易拓开发经验分享(一)
- HttpServletResponse应用_侯子腾的个人总结(第四次课)
- 深入浅出MFC学习笔记:MFC六大关键技术仿真之动态生成
- java基础之类继承
- HttpServletRequest应用_李晖晖的个人总结(第五次课)