把向量旋转到一个圆内,三点确定一个圆
#include<stdio.h>
#include<math.h>
#include<stdlib.h>
const double pi=acos(-1.0);
const double eps = 1e-8;
struct Line {
double a, b, c;
};
struct Point {
double x, y;
Point operator - (const Point& t) const {
Point tmp;
tmp.x = x - t.x;
tmp.y = y - t.y;
return tmp;
}
Point operator + (const Point& t) const {
Point tmp;
tmp.x = x + t.x;
tmp.y = y + t.y;
return tmp;
}
bool operator == (const Point& t) const {
return fabs(x-t.x) < eps && fabs(y-t.y) < eps;
}
};
inline Line Turn(Point& s, Point& e) { // 线段转直线
Line ln;
ln.a = s.y - e.y;
ln.b = e.x - s.x;
ln.c = s.x*e.y - e.x*s.y;
return ln;
}
inline bool line_inst(Line l1, Line l2, Point &p) { // 直线相交
double d = l1.a*l2.b - l2.a*l1.b;
if ( fabs(d) < eps ) return false;
p.x = (-l1.c*l2.b + l2.c*l1.b) / d;
p.y = (-l1.a*l2.c + l2.a*l1.c) / d;
return true;
}
bool out_center(Point& u, Point& v, Point& w, Point& p) { // 外接圆心
Point a, b, c, d;
a.x = (u.x + w.x) / 2;
a.y = (u.y + w.y) / 2;
b.x = a.x + u.y - w.y;
b.y = a.y - u.x + w.x;
c.x = (v.x + w.x) / 2;
c.y = (v.y + w.y) / 2;
d.x = c.x + v.y - w.y;
d.y = c.y - v.x + w.x;
return line_inst(Turn(a, b), Turn(c, d), p);
}
void Vector_rotation(Point a,Point cir,double angle,Point &p)//向量的旋转,传入-已知点,圆心,转的角度
{
double alf=atan2(a.y-cir.y,a.x-cir.x); //要注意是正转还是反转
double r=sqrt((a.x-cir.x)*(a.x-cir.x)+(a.y-cir.y)*(a.y-cir.y));
p.x=r*cos(alf-angle)+cir.x;
p.y=r*sin(alf-angle)+cir.y;
}
int main()
{
int t,k1,k2;
int i,j;
while(scanf("%d%d%d",&t,&k1,&k2)!=EOF)
{
Point cir;
Point p0,p1,p2,b,c,p;
cir.x=0,cir.y=0;
if(t==0) continue;
scanf("%lf%lf%lf%lf%lf%lf",&p0.x,&p0.y,&b.x,&b.y,&c.x,&c.y);
Vector_rotation(b,cir,1.0*(k1)/t*2*pi,p1);
Vector_rotation(c,cir,1.0*(k1+k2)/t*2*pi,p2);
out_center(p0,p1,p2,p);
printf("%.0lf\n",sqrt(p.x*p.x+p.y*p.y));
}
return 0;
}