poj 2957 计算几何向量的旋转
2011-10-09 18:18
507 查看
View Code
把向量旋转到一个圆内,三点确定一个圆
#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; }
相关文章推荐
- poj 2194 Stacking Cylinders 计算几何之向量旋转
- POJ 2079(计算几何初步——凸包加旋转卡壳)
- 计算几何之向量旋转
- POJ 2187(计算几何+旋转卡壳法或暴力)
- Board Wrapping(计算几何求凸包加向量的旋转)
- [Poj 2187]计算几何之凸包(三) {旋转卡壳初步}
- 【计算几何】 Andrew凸包算法 + 旋转卡壳(以求点对最长距离为例) -- 以 POJ 2187 Beauty Contest 为例
- POJ 2187 Beauty Contest [旋转卡壳]【计算几何】
- POJ 2187 计算几何之旋转卡壳
- Archipelago - SGU 120(计算几何向量旋转)
- 计算几何,三维向量的旋转
- POJ2991_Crane_计算几何::向量化|向量旋转公式||线段树维护向量和
- poj 2957 计算几何向量的旋转
- sdut 2603:Rescue The Princess(第四届山东省省赛原题,计算几何,向量旋转 + 向量交点)
- POJ 2991 Crane(线段树:维护向量+计算几何)
- 计算几何初步-向量的旋转 Rescue The Princess
- poj 2991 线段树 成段更新 + 向量旋转
- [HDU1115]Lifting the Stone(计算几何-三角形的[心]+角度计算+旋转)
- POJ 1556 计算几何+最短路
- 向量旋转的计算公式