HDOJ 4998 Rotate(求直线交点、绕定点旋转)
2014-09-14 10:58
183 查看
也是醉了,不懂为什么最后的角度就是所有角度之和,但是题目这么说了,我也就这么做了好了。。。
#include <iostream> #include <stdlib.h> #include <stdio.h> #include <math.h> #include <algorithm> using namespace std; const int maxn = 15; const double pi = acos(-1.0); typedef struct Point { double x, y, p; Point(double _x = 0, double _y = 0, double _p = 0): x(_x), y(_y), p(_p) {} Point operator +(Point argu) { return Point(x + argu.x, y + argu.y); } Point operator -(Point argu) { return Point(x - argu.x, y - argu.y); } double operator ^(Point argu) { return x * argu.y - y * argu.x; } Point operator *(double k) { return Point(x * k, y * k); } Point operator /(double k) { return Point(x / k, y / k); } Point rotate(Point argu) { Point r = argu - (*this); return Point(x + r.x * cos(p) - r.y * sin(p), y + r.x * sin(p) + r.y * cos(p)); } void push(double nx, double ny) { x = nx; y = ny; } void in(void) { scanf("%lf%lf%lf", &x, &y, &p); } void out(void) { printf("%.10lf %.10lf ", x, y); } }Vector; Point pp[maxn]; Point reala, realb, stana, stanb; Point mida, midb; Vector va, vb; double xa = 10010, ya = 10010, xb = 10010, yb = 10020; Point get_center(Point p, Vector v, Point q, Vector w) { Vector u = p - q; double t = (w ^ u) / (v ^ w); return (p + (v * t)); } int main() { //freopen("1002.in", "r", stdin); stana.push(xa, ya); stanb.push(xb, yb); int t; scanf("%d", &t); while(t--) { int n; double ang = 0.0; scanf("%d", &n); reala.push(xa, ya); realb.push(xb, yb); for(int i = 0; i < n; i++) { pp[i].in(); ang += pp[i].p; } ang = fmod(ang, 2.0 * pi); for(int i = 0; i < n; i++) { reala = pp[i].rotate(reala); realb = pp[i].rotate(realb); } mida = (stana + reala) / 2; midb = (stanb + realb) / 2; Vector va = Point(reala.y - stana.y, stana.x - reala.x); Vector vb = Point(realb.y - stanb.y, stanb.x - realb.x); Point c = get_center(mida, va, midb, vb); if(ang) { c.out(); printf("%.10lf\n", ang); } else printf("%.10lf %.10lf %.10lf\n", 0.0, 0.0, 0.0); } return 0; }
相关文章推荐
- hdoj_1466计算直线的交点数
- 网易游戏笔试题─两个圆相交,交点是A1,A2。现在过A1点做一直线与两个圆分别相交另外一点B1,B2。 B1B2可以绕着A1点旋转。问在什么情况下,B1B2最长
- HDOJ 题目1466 计算直线的交点数(动态规划)
- hdoj1466 计算直线的交点数 ( DP )
- HDOJ 1466 计算直线的交点数
- hdoj 1466 计算直线的交点数 (几何 DP)
- hdoj 1466计算直线的交点数(经典dp)
- hdoj 4998 平面旋转
- 网易游戏笔试题─两个圆相交,交点是A1,A2。现在过A1点做一直线与两个圆分别相交另外一点B1,B2。 B1B2可以绕着A1点旋转。问在什么情况下,B1B2最长
- HDOJ 题目2857 Mirror and Light(关于直线对称点,直线交点)
- hdoj4741 求空间中不平行的两条直线的最短距离及最短线段与两直线的交点
- 网易游戏笔试题─两个圆相交,交点是A1,A2。现在过A1点做一直线与两个圆分别相交另外一点B1,B2。 B1B2可以绕着A1点旋转。问在什么情况下,B1B2最长
- hdu 4998 Rotate 计算几何 点的旋转
- HDU 4998 Rotate 平面旋转
- hdoj 计算直线交点个数
- HDOJ&nbsp;&nbsp;1466&nbsp;&nbsp;&nbsp;计算直线的交点数
- Uva 11178 Morley's Theorem 向量旋转+求直线交点
- HDU 4998 Rotate(计算几何 绕点旋转)
- HDOJ-----1466---计算直线的交点数---动态规划
- UVa11178 - Morley's Theorem(向量旋转+直线交点)