HDU 4998 (点的旋转) Rotate

为了寻找等效旋转操作,我们任选两个点P0和Q0,分别绕这n个点旋转一定的角度后最终得到Pn和Qn

然后已知:P0和Pn共圆,Q0和Qn共圆。所以要找的等效旋转点就是这两个线段的垂直平分线交点O。

等效的角度的计算,可以利用已知的等腰三角形(这里有两个)△P0PnR,做一条垂线(三线合一的性质),再利用反三角函数计算半角,再乘二

还有一种特殊情况就是,如果答案比平角要大,我们计算的角度就不对了。

此时可以让P0逆时针旋转90°得到一个P1,然后将P1和Pn的坐标分别代入直线P0R的方程,如果异号,说明P1和Pn在直线两侧;同号说明同侧。

也就是异侧的话,就要将所求角度用2π减去它。

 //#define LOCAL
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std; void Rote(double& a1, double& b1, double a2, double b2, double p)
{
double tempx = a1, tempy = b1;
tempx = cos(p)*(a1 - a2) + sin(p)*(b2 - b1) + a2;
tempy = sin(p)*(a1 - a2) + cos(p)*(b1 - b2) + b2;
a1 = tempx;
b1 = tempy;
} double dis(double a1, double b1, double a2, double b2)
{
return sqrt((a1-a2)*(a1-a2) + (b1-b2)*(b1-b2));
} int main(void)
{
#ifdef LOCAL
freopen("Bin.txt", "r", stdin);
#endif int T;
scanf("%d", &T);
while(T--)
{
int n;
scanf("%d", &n);
double P0x = 0.123, P0y = 0.312, Q0x = 1.589, Q0y = 1.455;
double Pnx = P0x, Pny = P0y, Qnx = Q0x, Qny = Q0y;
for(int i = ; i < n; ++i)
{
double P1x, P1y, alpha;
scanf("%lf%lf%lf", &P1x, &P1y, &alpha);
Rote(Pnx, Pny, P1x, P1y, alpha);
Rote(Qnx, Qny, P1x, P1y, alpha);
}
double A1 = P0x - Pnx, B1 = P0y - Pny, C1 = (P0x*P0x + P0y*P0y - Pnx*Pnx - Pny*Pny) / ;
double A2 = Q0x - Qnx, B2 = Q0y - Qny, C2 = (Q0x*Q0x + Q0y*Q0y - Qnx*Qnx - Qny*Qny) / ;
double ansx = (C1*B2 - C2*B1) / (A1*B2 - A2*B1);
double ansy = (C1*A2 - C2*A1) / (B1*A2 - B2*A1); double zx = (P0x + Pnx) / , zy = (P0y + Pny) / ;
double ansa = acos(dis(zx,zy, ansx, ansy) / dis(P0x, P0y, ansx, ansy)) * ; double P1x = ansx - (P0y - ansy), P1y = ansy + (P0x - ansx);
if(((P0y-ansy)*(P1x-ansx)-(P0x-ansx)*(P1y-ansy)) * ((P0y-ansy)*(Pnx-ansx)-(P0x-ansx)*(Pny-ansy)) < )
ansa = 3.1415926536 * - ansa; printf("%.10lf %.10lf %.10lf\n", ansx, ansy, ansa);
}
return ;
}

代码君

还有一种复数的方法,<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=;
const double eps=1e-;
const double pi=3.1415926535897932384626;
const int DX[]={,,-,},DY[]={,,,-};
ll powmod(ll a,ll b) {ll res=;a%=mod;for(;b;b>>=){if(b&)res=res*a%mod;a=a*a%mod;}return res;}
ll powmod(ll a,ll b,ll mod) {ll res=;a%=mod;for(;b;b>>=){if(b&)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(,);b=CD(,);
scanf("%d",&n);
rep(i,,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<) the+=*pi;
while (the>=*pi) the-=*pi;
p=b/(CD(,)-k);
printf("%.10f %.10f %.10f\n",real(p),imag(p),the);
}
}

外来的代码君

上一篇:yum安装下的nginx,如何添加模块,和添加第三方模块


下一篇:Lind.DDD.Plugins~插件模式的集成