您的位置:首页 > 其它

hdu 4773 几何反演 线->圆

2017-11-01 18:54 621 查看
传送门

给定不相交的两个圆以及圆外一点,找一个经过给定点的圆与其他两个圆相切

首先来看反演变换,首先是给定一个圆圆心为O,半径为R

1、圆外一点P与圆内一点P‘会一一对应的反演OP*OP'=R*R

2、经过O的圆,反演后成为不经过O的一条直线

3、不经过O的圆,反演后成为另一个圆,且圆心并不对应

4、不经过O的直线反演后成为一个经过O的圆

5、过O的直线反演后不变

那么这道题就把两个圆反演之后求两圆的公切线,然后反演回去,就会成为一个过O的圆,且与另两圆相切(由反演的过程可看出)

求反演后的圆的圆心,可以将过O的直线所在的那条直径两端点反演,然后再求圆心.

对于一个不过反演中心的圆,怎样求它的反形圆?

很容易知道我们只需要求出反形圆的圆心和半径就可以了。

对于上图我们设圆C1的半径为

,C2的半径为

,反演半径为



那么根据反演的定义有:






那么,消去

得到:







这样我们就得到了反形圆的半径,那么还要求反形圆的圆心。

由于C1和O两点的坐标已知,而且我们知道O,C1,C2位于同一直线上,那么很明显对于C2的坐标,我们可以这样计算:

设O的坐标为

,C1的坐标为

,C2的坐标为



那么有:






至于

由上面解

处可以很容易得到,这样我们就完成了圆的反演变换。


/// .-~~~~~~~~~-._ _.-~~~~~~~~~-.
/// __.' ~. .~ `.__
/// .'// \./ \\`.
/// .'// | \\`.
/// .'// .-~"""""""~~~~-._ | _,-~~~~"""""""~-. \\`.
/// .'//.-" `-. | .-' "-.\\`.
/// .'//______.============-.. \ | / ..-============.______\\`.
/// .'______________________________\|/______________________________`.
#pragma comment(linker, "/STACK:1024000000,1024000000")
#include <vector>
#include <iostream>
#include <string>
#include <map>
#include <stack>
#include <cstring>
#include <queue>
#include <list>
#include <stdio.h>
#include <set>
#include <algorithm>
#include <cstdlib>
#include <cmath>
#include <iomanip>
#include <cctype>
#include <sstream>
#include <functional>
#include <stdlib.h>
#include <time.h>
#include <bitset>
using namespace std;

#define pi acos(-1)
#define s_1(x) scanf("%d",&x)
#define s_2(x,y) scanf("%d%d",&x,&y)
#define s_3(x,y,z) scanf("%d%d%d",&x,&y,&z)
#define s_4(x,y,z,X) scanf("%d%d%d%d",&x,&y,&z,&X)
#define S_1(x) scan_d(x)
#define S_2(x,y) scan_d(x),scan_d(y)
#define S_3(x,y,z) scan_d(x),scan_d(y),scan_d(z)
#define PI acos(-1)
#define endl '\n'
#define srand() srand(time(0));
#define me(x,y) memset(x,y,sizeof(x));
#define foreach(it,a) for(__typeof((a).begin()) it=(a).begin();it!=(a).end();it++)
#define close() ios::sync_with_stdio(0); cin.tie(0);
#define FOR(x,n,i) for(int i=x;i<=n;i++)
#define FOr(x,n,i) for(int i=x;i<n;i++)
#define fOR(n,x,i) for(int i=n;i>=x;i--)
#define fOr(n,x,i) for(int i=n;i>x;i--)
#define W while
#define sgn(x) ((x) < 0 ? -1 : (x) > 0)
#define bug printf("***********\n");
#define db double
#define ll long long
#define mp make_pair
#define pb push_back
typedef long long LL;
typedef pair <int, int> ii;
const int INF=0x3f3f3f3f;
const LL LINF=0x3f3f3f3f3f3f3f3fLL;
const int dx[]={-1,0,1,0,1,-1,-1,1};
const int dy[]={0,1,0,-1,-1,1,-1,1};
const int maxn=2e3+10;
const int maxx=1e3+10;
const double EPS=1e-8;
const double eps=1e-8;
const int mod=1e9+7;
template<class T>inline T min(T a,T b,T c) { return min(min(a,b),c);}
template<class T>inline T max(T a,T b,T c) { return max(max(a,b),c);}
template<class T>inline T min(T a,T b,T c,T d) { return min(min(a,b),min(c,d));}
template<class T>inline T max(T a,T b,T c,T d) { return max(max(a,b),max(c,d));}
template <class T>
inline bool scan_d(T &ret){char c;int sgn;if (c = getchar(), c == EOF){return 0;}
while (c != '-' && (c < '0' || c > '9')){c = getchar();}sgn = (c == '-') ? -1 : 1;ret = (c == '-') ? 0 : (c - '0');
while (c = getchar(), c >= '0' && c <= '9'){ret = ret * 10 + (c - '0');}ret *= sgn;return 1;}

inline bool scan_lf(double &num){char in;double Dec=0.1;bool IsN=false,IsD=false;in=getchar();if(in==EOF) return false;
while(in!='-'&&in!='.'&&(in<'0'||in>'9'))in=getchar();if(in=='-'){IsN=true;num=0;}else if(in=='.'){IsD=true;num=0;}
else num=in-'0';if(!IsD){while(in=getchar(),in>='0'&&in<='9'){num*=10;num+=in-'0';}}
if(in!='.'){if(IsN) num=-num;return true;}else{while(in=getchar(),in>='0'&&in<='9'){num+=Dec*(in-'0');Dec*=0.1;}}
if(IsN) num=-num;return true;}

void Out(LL a){if(a < 0) { putchar('-'); a = -a; }if(a >= 10) Out(a / 10);putchar(a % 10 + '0');}
void print(LL a){ Out(a),puts("");}
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
//cerr << "run time is " << clock() << endl;

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);
}
void Output()
{
printf("%.8lf %.8lf\n",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("%.8f %.8f %.8f\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;
}

void add(Point a,Point b,int &k)
{
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)))
add(a,b,k);
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)))
add(a,b,k);
return k - 2;
}

void solve()
{
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();
}

int main()
{
//freopen( "in.txt" , "r" , stdin );
//freopen( "data.txt" , "w" , stdout );
int t=1;
//init();
s_1(t);
for(int cas=1;cas<=t;cas++)
{
//printf("Case #%d: ",cas);
solve();
}
}
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: