# 圆的反演变换

15647人阅读 评论(3)

(1)除反演中心外，平面上的每一个点都只有唯一的反演点，且这种关系是对称的，位于反演圆上的点，保持在原处，位于

(2)任意一条不过反演中心的直线，它的反形是经过反演中心的圆，反之亦然，特别地，过反演中心相交的圆，变为不过反

#include <iostream>
#include <string.h>
#include <stdio.h>
#include <math.h>

using namespace std;
double const eps = 1e-8;

struct Point
{
double x,y;
Point(double a = 1.0,double b = 1.0):x(a),y(b){}
Point operator + (const Point &a)
{
return Point(x+a.x,y+a.y);
}
Point operator - (const Point &a)
{
return Point(x-a.x,y-a.y);
}
Point operator * (const double a)
{
return Point(a*x,a*y);
}
Point Trans()
{
return Point(-y,x);
}
void Input()
{
scanf("%lf%lf",&x,&y);
}
} ;

struct Circle
{
Point o;
double r;
Circle(Point a = Point(),double b = 1.0):o(a),r(b) {}
Point getPoint(double alpha)
{
return o + Point(r*cos(alpha),r*sin(alpha));
}
void Input()
{
o.Input();
scanf("%lf",&r);
}
void Output()
{
printf("%.8lf %.8lf %.8lf\n",o.x,o.y,r);
}
} ;

Point p;
Circle c[15];

double dist(Point A,Point B)
{
return sqrt((A.x-B.x)*(A.x-B.x) + (A.y-B.y)*(A.y-B.y));
}

double cross(Point A,Point B,Point C)
{
return (B.x-A.x)*(C.y-A.y) - (B.y-A.y)*(C.x-A.x);
}

int sign(double x)
{
return (x > eps) - (x < -eps);
}

Circle Inverse(Circle C)
{
Circle T;
double t = dist(C.o,p);
double x = 1.0 / (t - C.r);
double y = 1.0 / (t + C.r);
T.r = (x - y) / 2.0;
double s = (x + y) / 2.0;
T.o = p + (C.o - p) * (s / t);
return T;
}

{
double t = cross(a,p,b);
if(t < 0) t = -t;
double d = dist(a,b);
t /= d;
if(t > eps)
{
double w = 0.5 / t;
Point dir = (b-a).Trans();
Point a1 = p + dir * (w / d);
Point b1 = p - dir * (w / d);
if(fabs(cross(a,b,a1)) < fabs(cross(a,b,b1)))
c[k++] = Circle(a1,w);
else
c[k++] = Circle(b1,w);
}
}

int Work()
{
c[0] = Inverse(c[0]);
c[1] = Inverse(c[1]);
if(c[1].r > c[0].r) swap(c[1],c[0]);
Point v = c[1].o - c[0].o;
double alpha = atan2(v.y,v.x);
double d = dist(c[0].o,c[1].o);
double beta  = acos((c[0].r - c[1].r) / d);
int k = 2;
Point a = c[0].getPoint(alpha + beta);
Point b = c[1].getPoint(alpha + beta);
if(sign(cross(a,c[0].o,b)) == sign(cross(a,p,b)) &&
sign(cross(a,c[1].o,b)) == sign(cross(a,p,b)))
a = c[0].getPoint(alpha - beta);
b = c[1].getPoint(alpha - beta);
if(sign(cross(a,c[0].o,b)) == sign(cross(a,p,b)) &&
sign(cross(a,c[1].o,b)) == sign(cross(a,p,b)))
return k - 2;
}

int main()
{
int T;
scanf("%d",&T);
while(T--)
{
c[0].Input();
c[1].Input();
p.Input();
int num = Work();
printf("%d\n",num);
for(int i=0;i<num;i++)
c[i+2].Output();
}
return 0;
}


个人资料
等级：
访问量： 258万+
积分： 2万+
排名： 305
最新评论