Rotate

hdu4998:http://acm.hdu.edu.cn/showproblem.php?pid=4998

题意:给你n个点,以及绕每个点旋转的弧度。然后,问你经过这n次旋转,平面中的点总的效果是相当于哪个点旋转了多少弧度。

题解:我的第一道计算几何。可以选两个点,求出旋转之后的对应点,然后分别求出这两个点的中垂线,中垂线的交点就是要求的点,弧度就是所有弧度之和mod(2*pi)

 1 #include<iostream>
 2 #include<cstdio>
 3 #include<cstring>
 4 #include<algorithm>
 5 #include<cmath>
 6 const double pi=3.14159265;
 7 using namespace std;
 8 int n;
 9 struct Point{
10   double x;
11   double y;
12   double s;
13 }num[20];
14 struct LINE{
15    double a,b,c;
16    Point s;
17 };
18 Point HHH(Point o,double alpha,Point p) {//点p绕着o旋转alpha弧度
19     Point tp;
20     p.x-=o.x;
21     p.y-=o.y;
22     tp.x=p.x*cos(alpha)-p.y*sin(alpha)+o.x;
23     tp.y=p.y*cos(alpha)+p.x*sin(alpha)+o.y;
24     return tp;
25  }
26 bool CCC(LINE l1,LINE l2,Point&p){//两条直线是否相交,如果相交,则交点为p
27   double d=l1.a*l2.b-l2.a*l1.b;
28     if(abs(d)<1e-6)    return false;
29     p.x = (l2.c*l1.b-l1.c*l2.b)/d;
30     p.y = (l2.a*l1.c-l1.a*l2.c)/d;
31     return true;
32 }
33 LINE DDD(const Point &_a, const Point &_b){//求两点之间垂直平分线
34         LINE ret;
35         ret.s.x = (_a.x + _b.x)/2;
36         ret.s.y = (_a.y + _b.y)/2;
37         ret.a = _b.x - _a.x;
38         ret.b = _b.y - _a.y;
39         ret.c = (_a.y - _b.y) * ret.s.y + (_a.x - _b.x) * ret.s.x;
40         return ret;
41 }
42
43 LINE EEE(Point a,Point b){//求经过两点的中垂线
44     LINE ret;
45     if(abs(a.x-b.x)<1e-6){
46         ret.a=1;
47         ret.b=0;
48         ret.c=-a.x;
49         return ret;
50     }
51     ret.a=a.y-b.y;
52     ret.b=b.x-a.x;
53     ret.c=a.x*b.y-a.y*b.x;
54     return ret;
55 }
56 int main(){
57    int T;
58    scanf("%d",&T);
59    while(T--){
60       scanf("%d",&n);
61       double sum=0;
62       for(int i=1;i<=n;i++){
63          scanf("%lf%lf%lf",&num[i].x,&num[i].y,&num[i].s);
64          sum+=num[i].s;
65       }
66       Point s1,s2;
67       s1.x=2.345,s1.y=4.123;
68       s2.x=11.345,s2.y=12.123;
69       Point t1=s1,t2=s2;
70       for(int i=1;i<=n;i++){
71          Point temp=HHH(num[i],num[i].s,t1);
72          t1=temp;
73       }
74        for(int i=1;i<=n;i++){
75          Point temp=HHH(num[i],num[i].s,t2);
76          t2=temp;
77       }
78       LINE one1=DDD(s1,t1);
79       LINE one2=DDD(s2,t2);
80       Point a;
81       if(CCC(one1,one2,a)){
82         if(sum>2*pi)
83         sum-=2*pi;
84         printf("%lf %lf %lf\n",a.x,a.y,sum);
85       }
86       else{
87           LINE ttt=EEE(s1,s2);
88           CCC(one1,ttt,a);
89         if(sum>2*pi)
90          sum-=2*pi;
91          printf("%lf %lf %lf\n",a.x,a.y,sum);
92       }
93    }
94 }

时间: 2024-10-05 18:07:52

Rotate的相关文章

CSS3 transform 属性详解(skew, rotate, translate, scale)

写这篇文章是因为在一个前端QQ群里,网友 "小豆豆" (应他要求要出现他的网名......) ,问skew的角度怎么算,因为他看了很多文章还是不能理解skew的原理.于是,我觉得有必要写个博文,帮助那些不懂的人,让他们看了此文就懂. 进入正题: 先说明下,电脑屏幕的XY轴跟我们平时所说的直角坐标系是不一样的.如下图: 图上的盒子就是代表我们的电脑屏幕,原点就是屏幕的左上角,竖直向下为X轴正方向,水平向右为Y轴正方向. 1.倾斜skew 先看图 每个图下方都有skew的参数.粗的红色的线

Leet Code OJ 189. Rotate Array [Difficulty: Easy]

题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note: Try to come up as many solutions as you can, there are at least 3 different ways to solve thi

leetcode 【 Rotate Image 】python 实现

题目: You are given an n x n 2D matrix representing an image. Rotate the image by 90 degrees (clockwise). Follow up:Could you do this in-place? 代码:oj测试通过 Runtime: 53 ms 1 class Solution: 2 # @param matrix, a list of lists of integers 3 # @return a list

Rotate Array

LeetCode 189 Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. Note:Try to come up as many solutions as you can, there are at least 3 different ways to s

CSS3 skew倾斜、rotate旋转动画

css3出现之前.我们实现一个对象的一组连续动画须要通过JavaScript或Jquery编写,脚本代码较为复杂: 若须要实现倾斜.旋转之类的动画难度将更高(我还没试过用JavaScript或Jquery怎样实现),并且即使能实现预计花的时间代价及维护难度是非常大的,非常多时候仅仅能依靠绘图工具制作此类动画文件: 有时候在想假设不用脚本语言,也不用绘图工作制作动画文件.就能在网页上实现倾斜.旋转之类的动画效果多好. 近期挤出一些业余时间学习CSS3,当中就包括非常多动画演示样例,花了点时间学习和

Rotate Image

参照计算机图形学图形变换即可. public class Solution { public void rotate(int[][] matrix) { if(matrix.length<=1)return ; float dip=(float) ((matrix.length-1)/2.0); int[][] res=new int[matrix.length][matrix.length]; for(int i=0;i<matrix.length;i++) for(int j=0;j<

How to Rotate Tomcat catalina.out

If catalina.out becomes 2GB in size, tomcat crashes and fails to start without any error message. To avoid this scenario you should rotate catalina.out frequently. This article describes how to setup auto rotation of catalina.out on a linux/unix mach

189. Rotate Array----Array----Easy----20160925

问题: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. 思路2: 用一个额外的数组把数组完全复制过去 代码2: class Solution { public: void rotate(vector<int>& nums, int k) { i

【LeetCode】189. Rotate Array 解题小结

题目: Rotate an array of n elements to the right by k steps. For example, with n = 7 and k = 3, the array [1,2,3,4,5,6,7] is rotated to [5,6,7,1,2,3,4]. 这道题目 有很多种解法,我用的是这种,相对也好理解,先所有元素reverse,再0-(n-k)的元素reverse,然后(n-k)-n的元素reverse. class Solution { pub

Rotate List

Given a list, rotate the list to the right by k places, where k is non-negative. For example:Given 1->2->3->4->5->NULL and k = 2,return 4->5->1->2->3->NULL. 1 /** 2 * Definition for singly-linked list. 3 * public class ListNo