hdu 4998 Rotate(几何)
2014-09-17 22:23
330 查看
题目链接:hdu 4998 Rotate
题目大意:给定n次旋转,每次旋转给定旋转中心和角度,问说n次旋转的等价旋转,包括中心和角度。
解题思路:根据旋转的公式:
x′=(x−rx)∗cos(r)−(y−ry)∗sin(r)+rx
y′=(x−rx)∗sin(r)+(y−ry)∗cos(r)+ry
假设起始点(0,0),经过n次旋转后得到(x',y')然后根据公式去求x,y。
题目大意:给定n次旋转,每次旋转给定旋转中心和角度,问说n次旋转的等价旋转,包括中心和角度。
解题思路:根据旋转的公式:
x′=(x−rx)∗cos(r)−(y−ry)∗sin(r)+rx
y′=(x−rx)∗sin(r)+(y−ry)∗cos(r)+ry
假设起始点(0,0),经过n次旋转后得到(x',y')然后根据公式去求x,y。
#include <cstdio> #include <cstring> #include <cmath> #include <algorithm> using namespace std; const double pi = 4 * atan(1.0); struct point { double x, y; point (double x = 0, double y = 0) { this->x = x; this->y = y; } point rotate (double rx, double ry, double r) { double x0 = (x - rx) * cos(r) - (y - ry) * sin(r) + rx; double y0 = (x - rx) * sin(r) + (y - ry) * cos(r) + ry; return point(x0, y0); } }; int main () { int cas, n; scanf("%d", &cas); while (cas--) { double R = 0, x, y, r; scanf("%d", &n); point S; while (n--) { scanf("%lf%lf%lf", &x, &y, &r); R += r; if (R >= 2 * pi) R -= 2 * pi; S = S.rotate(x, y, r); } double a = 1 - cos(R), b = sin(R); double xx = (a * S.x - b * S.y) / (a * a + b * b); double yy = (a * S.y + b * S.x) / (a * a + b * b); printf("%.10lf %.10lf %.10lf\n", xx, yy, R); } return 0; }
相关文章推荐
- HDU 4998 Rotate(计算几何)2014年鞍山赛区网络赛
- hdu 4998 Rotate(计算几何)
- HDU 4998 Rotate --几何
- hdu 4998 Rotate 计算几何 点的旋转
- HDU 4998 Rotate (二维图形几何变换)
- HDU 4998 Rotate(计算几何 绕点旋转)
- HDU 4998 Rotate(计算几何 绕点旋转)
- 【几何模板加点小思路】hdu-4998 Rotate
- HDU 4998 Rotate --几何
- HDU 4998 Rotate 计算几何
- HDU 4998 Rotate(计算几何/绕弧度旋转/模板的巧用)
- HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online
- HDU 4998 Rotate 简单几何旋转问题
- hdu 4998——Rotate
- HDU 4998 Rotate
- ACM学习历程—Rotate(HDU 2014 Anshan网赛)(几何)
- HDU 4998 Rotate
- 【计算几何】 HDOJ 4998 Rotate
- HDU 4998 Rotate
- HDU 4998 Rotate (几何变换——旋转)