hdu 4998 Rotate
2014-10-02 16:33
274 查看
平面上有一个二维坐标轴上,进行n次操作,把坐标轴绕着(x,y) (这个坐标总是初始坐标轴的坐标) 逆时针转p弧度。
最后的结果相当于进行一次操作,即绕着(X, Y) 逆时针旋转了P弧度。求 X,Y,P,题目保证总有解.
其实可以发现,最后的P是n次的pi的和,因为这和绕什么点旋转无关。
对任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
很容易发现不管怎么旋转旋转度数相加就是最终度数(>=2*PI时减去2*PI就行了),那么咱们虚拟一个起始点,然后模拟旋转操作,最后得到一个虚拟终点,又虚拟起点和虚拟终点再加上旋转度数就能算出目标坐标了。
还有一种复数的方法,<complex>里面已经有了现成的复数数据类型和函数了,用起来很方便。
这是上交一队的代码,膜拜了
最后的结果相当于进行一次操作,即绕着(X, Y) 逆时针旋转了P弧度。求 X,Y,P,题目保证总有解.
其实可以发现,最后的P是n次的pi的和,因为这和绕什么点旋转无关。
对任意点(x,y),绕一个坐标点(rx0,ry0)逆时针旋转a角度后的新的坐标设为(x0, y0),有公式:
x0= (x - rx0)*cos(a) - (y - ry0)*sin(a) + rx0 ;
y0= (x - rx0)*sin(a) + (y - ry0)*cos(a) + ry0 ;
很容易发现不管怎么旋转旋转度数相加就是最终度数(>=2*PI时减去2*PI就行了),那么咱们虚拟一个起始点,然后模拟旋转操作,最后得到一个虚拟终点,又虚拟起点和虚拟终点再加上旋转度数就能算出目标坐标了。
#include <cstdio> #include <cstring> #include <string> #include <algorithm> #include <iostream> #include <vector> #include <queue> #include <stack> #include <cmath> using namespace std; #define PI acos(-1) main() { double stx, sty, endx, endy, x, y, p, endp, xx, yy; int t, n, i, j, k; cin>>t; while(t--){ cin>>n; stx=sty=xx=yy=endp=0;//(stx,sty)是虚拟起点,(endx,endy)是虚拟终点 while(n--){ scanf("%lf %lf %lf",&x,&y,&p); endp+=p; if(endp>=2*PI) endp-=2*PI; endx=(xx-x)*cos(p)-(yy-y)*sin(p)+x; endy=(xx-x)*sin(p)+(yy-y)*cos(p)+y; xx=endx;yy=endy; } //再把虚拟起点和虚拟终点代入上面公式中化简就得出下面很长。。很长。。的式子了 x=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(endy-stx*sin(endp)-sty*cos(endp))*sin(endp))/(2-2*cos(endp)); y=((endx-stx*cos(endp)+sty*sin(endp))*(1-cos(endp))-(1-cos(endp))*(1-cos(endp))*x)/((1-cos(endp))*sin(endp)); printf("%.10lf %.10lf %.10lf\n",x,y,endp); } }
还有一种复数的方法,<complex>里面已经有了现成的复数数据类型和函数了,用起来很方便。
这是上交一队的代码,膜拜了
#include <cstdlib> #include <cctype> #include <cstring> #include <cstdio> #include <cmath> #include <algorithm> #include <vector> #include <string> #include <iostream> #include <sstream> #include <map> #include <set> #include <queue> #include <stack> #include <fstream> #include <numeric> #include <iomanip> #include <bitset> #include <list> #include <stdexcept> #include <functional> #include <utility> #include <ctime> #include <cassert> #include <complex> using namespace std; #define rep(i,a,n) for (int i=a;i<n;i++) #define per(i,a,n) for (int i=n-1;i>=a;i--) #define pb push_back #define mp make_pair #define all(x) (x).begin(),(x).end() #define fi first #define se second #define SZ(x) ((int)(x).size()) #define ACCU accumulate #define TWO(x) (1<<(x)) #define TWOL(x) (1ll<<(x)) #define clr(a) memset(a,0,sizeof(a)) #define POSIN(x,y) (0<=(x)&&(x)<n&&0<=(y)&&(y)<m) #define PRINTC(x) cout<<"Case #"<<++__<<": "<<x<<endl #define POP(x) (__builtin_popcount(x)) #define POPL(x) (__builtin_popcountll(x)) typedef vector<int> VI; typedef vector<string> VS; typedef vector<double> VD; typedef long long ll; typedef long double LD; typedef pair<int,int> PII; typedef pair<ll,ll> PLL; typedef vector<ll> VL; typedef vector<PII> VPII; typedef complex<double> CD; const int inf=0x20202020; const ll mod=1000000007; const double eps=1e-9; const double pi=3.1415926535897932384626; const int DX[]={1,0,-1,0},DY[]={0,1,0,-1}; ll powmod(ll a,ll b) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll powmod(ll a,ll b,ll mod) {ll res=1;a%=mod;for(;b;b>>=1){if(b&1)res=res*a%mod;a=a*a%mod;}return res;} ll gcd(ll a,ll b) { return b?gcd(b,a%b):a;} // head int _,n; CD k,b,p; double x,y,c; int main() { for (scanf("%d",&_);_;_--) { k=CD(1,0);b=CD(0,0); scanf("%d",&n); rep(i,0,n) { scanf("%lf%lf%lf",&x,&y,&c); p=CD(x,y); k=k*CD(cos(c),sin(c)); b=(b-p)*CD(cos(c),sin(c))+p; } double the=arg(k); while (the<0) the+=2*pi; while (the>=2*pi) the-=2*pi; p=b/(CD(1,0)-k); printf("%.10f %.10f %.10f\n",real(p),imag(p),the); } }
相关文章推荐
- 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 平面坐标变换
- 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 --几何
- HDU 4998 Rotate(计算几何 绕点旋转)