hdu 4998 Rotate(计算几何)
来源:互联网 发布:物品记录软件 编辑:程序博客网 时间:2024/09/21 13:30
题目链接:
http://acm.hdu.edu.cn/showproblem.php?pid=4998
解题思路:
题目大意:给定n个点和n个角度,平面内任意一个点依次以这些点Point(i)为旋转中心,逆时针旋转 R(i)度,求最后相当于绕哪个点旋转多少度,求这个点的坐标以及旋转的角度。
算法思想:
一个点(x,y)绕另外一个点(x0,y0)旋转 r0 度的公式为:
x1= (x - x0)*cos(r0) - (y - y0)*sin(r0) + x0 ;
y1= (x - x0)*sin(r0) + (y - y0)*cos(r0) + y0 ;
最后旋转点肯定是xx,tmp1的垂直平分线以及由yy,tmp2的垂直平分线的交点,旋转角度rad = (r1+r2+.....+rn)%(2*pi)。
最后直接套模板即可。。。http://blog.csdn.net/piaocoder/article/details/47403265
AC代码:
#include <iostream>#include <cstdio>#include <algorithm>#include <cmath>using namespace std;const double eps = 1e-5;const double pi = acos(-1.0);struct Point{ double x,y; Point(double x = 0,double y = 0):x(x),y(y){} // 构造函数,方便代码编写};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);}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 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));}Vector Normal(Vector A){ double L = Length(A); return Vector(-A.y/L,A.x/L);}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;}int main(){ int T; scanf("%d",&T); while(T--){ int n; scanf("%d",&n); Point xx(-1,0),yy(1,0); Point tmp1 = xx,tmp2 = yy,tmp3; double x, rad = 0; for(int i = 0; i < n; i++){ scanf("%lf%lf%lf",&tmp3.x,&tmp3.y,&x); tmp1 = Rotate(tmp1-tmp3,x)+tmp3; tmp2 = Rotate(tmp2-tmp3,x)+tmp3; rad += x; } Point tt1 = (xx+tmp1)/2, tt2 = (yy+tmp2)/2; Vector v1,v2; v1 = Normal(tmp1-xx);v2 = Normal(tmp2-yy); Point ans = GetLineIntersection(tt1,v1,tt2,v2); while(rad > 2*pi) rad -= 2*pi; printf("%.10lf %.10lf %.10lf\n",ans.x,ans.y,rad); } return 0;}
0 0
- hdu 4998 Rotate(计算几何)
- HDU 4998 Rotate 计算几何
- HDU 4998 Rotate(计算几何 绕点旋转)
- HDU 4998 Rotate(计算几何 绕点旋转)
- hdu 4998 Rotate(几何)
- HDU 4998 Rotate --几何
- hdu 4998 Rotate 计算几何 点的旋转
- 【计算几何】 HDOJ 4998 Rotate
- HDU 4998 Rotate(计算几何)2014年鞍山赛区网络赛
- HDU 4998 Rotate (二维图形几何变换)
- HDU 4998 Rotate (几何变换——旋转)
- hdu4998 Rotate(计算几何+模拟)
- HDU 4998 Rotate 计算几何 2014 ACM/ICPC Asia Regional Anshan Online
- HDU 4998 Rotate(计算几何/绕弧度旋转/模板的巧用)
- HDU 4998 Rotate 简单几何旋转问题
- hdu 4998 简单计算几何
- hdu 2876 (计算几何)
- hdu 5733 (计算几何)
- Volley(二) ImageRequest、Imageloader、NetworkImageView加载图片
- 微信公众平台的后台开发流程(一)
- 自定义 json的返回格式 : JsonSerializer
- char* BSTR CString 之间转换
- mac电脑上将文件夹显示或者隐藏的命令
- hdu 4998 Rotate(计算几何)
- 不太常见的C函数
- iOS开源库
- WiFi基本知识
- Android开发之软键盘遮盖EditText
- oracle数据库表的解锁问题
- mybatis实战系列(三)mybatis中的分页使用 动态分页 物理分页
- 解决Win7&Win8 64位下Source Insight提示未完整安装的问题
- Developer--Services