hdu4998 Rotate【计算几何】
Your little sister likes to rotate things. To put it easier to analyze, your sister makes n rotations. In the i-th time, she makes everything in the plane rotate counter-clockwisely around a point ai by a radian of pi.
Now she promises that the total effect of her rotations is a single rotation around a point A by radian P (this means the sum of pi is not a multiplier of 2π).
Of course, you should be able to figure out what is A and P :).
InputThe first line contains an integer T, denoting the number of the test cases.
For each test case, the first line contains an integer n denoting the number of the rotations. Then n lines follows, each containing 3 real numbers x, y and p, which means rotating around point (x, y) counter-clockwisely by a radian of p.
We promise that the sum of all p's is differed at least 0.1 from the nearest multiplier of 2π.
T<=100. 1<=n<=10. 0<=x, y<=100. 0<=p<=2π.
OutputFor each test case, print 3 real numbers x, y, p, indicating that the overall rotation is around (x, y) counter-clockwisely by a radian of p. Note that you should print p where 0<=p<2π.
Your answer will be considered correct if and only if for x, y and p, the absolute error is no larger than 1e-5.
Sample Input
1
3
0 0 1
1 1 1
2 2 1
Sample Output
1.8088715944 0.1911284056 3.0000000000
划重点!
一个点绕定点旋转的坐标公式:
在平面坐标上,任意点P(x1,y1),绕一个坐标点Q(x2,y2)旋转θ角度后,新的坐标设为(x, y)的计算公式:
- x= (x1 - x2)*cos(θ) - (y1 - y2)*sin(θ) + x2 ;
- y= (x1 - x2)*sin(θ) + (y1 - y2)*cos(θ) + y2 ;
这道题里最后的旋转角度就是前面所有的旋转角度加起来 因为不管绕哪一个点旋转 整个画面都转过了相同的角度 画面上的每一个点也都转过了相同的角度
先设一个点 对于每一次旋转都对这个点进行旋转 就可以得到最后的时候这个点的坐标
在根据这个点最后的坐标与最开始的坐标 可以反推出旋转中心
emmm感觉自己高中学的几何的公式都忘光了 计算能力也大大下降 解一个复杂一点的方程都解不出了啊天哪好难过
#include <iostream>
#include <algorithm>
#include <cstring>
#include <cstdio>
#include <cmath>
using namespace std;
#define PI 3.1415926
#define EPS 1.0e-5
int t, n;
struct point{
double x, y;
}p[15];
point rot(point& p, point& ding, double theta)
{
point c;
c.x = (p.x - ding.x) * cos(theta) - (p.y - ding.y) * sin(theta) + ding.x;
c.y = (p.x - ding.x) * sin(theta) + (p.y - ding.y) * cos(theta) + ding.y;
return c;
}
int main()
{
cin>>t;
while(t--){
scanf("%d",&n);
double anangle = 0.0;
point a, b;
a.x = -1.0; a.y = -20.0;
b.x = -1.0; b.y = -20.0;
for(int i = 0; i < n; i++){
double angle;
scanf("%lf%lf%lf",&p[i].x, &p[i].y, &angle);
a = rot(a, p[i], angle);
anangle += angle;
while(anangle >= 2 * PI){
anangle -= 2 * PI;
}
}
point ans;
ans.y =(a.x*sin(anangle)+a.y*(1-cos(anangle))-(b.x*cos(anangle)-b.y*sin(anangle))*sin(anangle)-(b.x*sin(anangle)+b.y*cos(anangle))*(1-cos(anangle)))/(2-2*cos(anangle));
ans.x=(a.x*(1-cos(anangle))-a.y*sin(anangle)-(b.x*cos(anangle)-b.y*sin(anangle))*(1-cos(anangle))+(b.x*sin(anangle)+b.y*cos(anangle))*sin(anangle))/(2-2*cos(anangle));
printf("%.6f %.6f %.6f\n", ans.x, ans.y, anangle);
}
return 0;
}
hdu4998 Rotate【计算几何】的更多相关文章
- hdu4998 Rotate 计算几何
Noting is more interesting than rotation! Your little sister likes to rotate things. To put it easie ...
- HDU 4998 Rotate (计算几何)
HDU 4998 Rotate (计算几何) 题目链接http://acm.hdu.edu.cn/showproblem.php?pid=4998 Description Noting is more ...
- 【几何模板加点小思路】hdu-4998 Rotate
用几何模板敲的,也有直接公式推的,追求短代码的可以点右上角小红了...... 题意就是想想一个物体分别做绕某一点(给出坐标)旋转p度(给出角度)后,其位置等价于绕哪一点旋转多少度,输出该等价点及其等价 ...
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
Rescue The Princess Time Limit: 1000ms Memory limit: 65536K 有疑问?点这里^_^ 题目描述 Several days ago, a b ...
- HDU 4063 Aircraft(计算几何)(The 36th ACM/ICPC Asia Regional Fuzhou Site —— Online Contest)
题目链接:http://acm.hdu.edu.cn/showproblem.php?pid=4063 Description You are playing a flying game. In th ...
- Rotate
hdu4998:http://acm.hdu.edu.cn/showproblem.php?pid=4998 题意:给你n个点,以及绕每个点旋转的弧度.然后,问你经过这n次旋转,平面中的点总的效果是相 ...
- UVA12304 2D Geometry 110 in 1! 计算几何
计算几何: 堆几何模版就能够了. . .. Description Problem E 2D Geometry 110 in 1! This is a collection of 110 (in bi ...
- 计算几何总结(Part 1~2)
Preface 对于一个初三连三角函数都不会的蒟蒻来说计算几何简直就是噩梦. 反正都是要学的也TM没办法,那就慢慢一点点学起吧. 计算几何要有正确的板子,不然那种几百行CODE的题写死你. 本蒟蒻的学 ...
- UVA 12304 - 2D Geometry 110 in 1! - [平面几何基础题大集合][计算几何模板]
题目链接:https://cn.vjudge.net/problem/UVA-12304 题意: 作为题目大合集,有以下一些要求: ①给出三角形三个点,求三角形外接圆,求外接圆的圆心和半径. ②给出三 ...
随机推荐
- Android跑指定包Monkey脚本
Android跑指定包Monkey脚本 adb shell monkey –p com.android.mms --throttle 1000 -v -v -v -s 1 --ignore-secur ...
- 5 -- Hibernate的基本用法 --1 2 基本映射方式
ORM工具提供了持久化类和数据表之间的映射关系.实际上,所有的ORM工具大致上都遵循相同的映射思路,ORM基本映射有如下几条映射关系: ⊙ 数据表映射类 : 持久化类被映射到一个数据表.程序使用这个持 ...
- MongoDB中的聚合操作
根据MongoDB的文档描述,在MongoDB的聚合操作中,有以下五个聚合命令. 其中,count.distinct和group会提供很基本的功能,至于其他的高级聚合功能(sum.average.ma ...
- css背景图等比例缩放,盒子随背景图等比例缩放
很多时候我们给网站了一个大banner,但是随着屏幕的变化,背景会变形,我们知道background-size可以实现背景图等比例缩放,但是,我们想让下面的盒子根据缩放后背景图的高度,也能自动向上挤. ...
- ios开发之--字符串局部改变颜色
改变指定位置字符的颜色,代码如下: NSString *descStr = @"楼主"; NSString *nickStr = [NSString stringWithForma ...
- 重新生成RF的测试库API文档
在dos窗口下执行如下命令: 命令:python -m robot.libdoc 库名称 生成的API文件名.html 例如:python -m robot.libdoc MongoDBLibrar ...
- Unity Shader 获取模型空间坐标
CGPROGRAM // Physically based Standard lighting model, and enable shadows on all light types #pragma ...
- ISD9160学习笔记04_ISD9160音频编码代码分析
前言 录音例程涉及了录音和播放两大块内容,上篇笔记说了播放,这篇就来说说录音这块,也就是音频编码这部分功能. 上篇笔记中的这段话太装逼了,我决定再复制下,嘿嘿. “我的锤子便签中有上个月记下的一句话, ...
- 从经典问题来看 Copy 方法
经典面试题:为什么 NSString 类型成员变量的修饰属性用 copy 而不是 strong (或 retain ) ? 在初学 iOS 的时候,可能会被灌输这么一个常识,切记 NSString 的 ...
- 【python3】window下 vscode 配置 python3开发环境
本文以python3.7 为例 一 下载python3 url : https://www.python.org/downloads/windows/ 提示: 安装过程中.记得勾选 添加环境变量 二 ...