【HDU】4773 Problem of Apollonius

本文探讨了利用圆的反演解决特定几何问题的方法,即寻找过定点并与两个给定圆外切的所有圆。文章详细介绍了反演原理,包括反演点的性质、直线和圆的反形,并通过实例解释如何将问题转化为求外公切线,避免了复杂的方程求解。

题意

给定相离的两个圆(圆心坐标以及半径)以及圆外的一个定点\(P\),求出过点\(P\)的且与已知的两个圆外切的所有圆(输出总数+圆心、半径)。

分析

如果强行解方程,反正我是不会。
本题用到新姿势:圆的反演。
二维上的圆的反演通常是指定一个圆\(C\)为基础,其圆心\(O\)为反演中心,其半径\(r\)为反演半径。对于平面上任意一个非反演中心的点\(P\),都有且仅有一个反演点\(P'\),满足\(OP \cdot OP' = r^2\)\(P'\)\(OP\)射线上。对于任意一个二维上的图形,其反形就是图形上的所有点的反演点组成的。
于是可以证明:

  1. \(C\)内的点的反演点在\(C\)外,\(C\)上的点的反演点就是自身,\(C\)外的点的反演点在\(C\)内。
  2. 任意一条不过反演中心的直线,其反形为过反演中心的圆。(至于过反演中心,我只能理解为这是极限意义下有点已经无限逼近了反演中心所以就算经过)
  3. 任意一个不过反演中心的圆,其反形为不过反演中心的圆,且反演中心为两圆的位似中心。

于是对于本题,交\(3\)个点的圆,可以看做一条直线关于\(P\)点反演得到的圆。由于反演点唯一,所以这条直线肯定与给出的两个圆的反演圆各相交一个点。所以就是这两个圆的反演圆的公切线!我们发现,如果是内公切线,反演成圆后会把一个圆包含,因此不符合题意。所以我们只需要考虑外公切线即可。
但是外公切线的反形圆也可能会出现把给出的两个圆包含的情况,画一下图就能发现这种情况只出现在\(p\)和另外两个反演圆不在公切线的同一侧。

题解

本题要注意反演半径不要开太小,否则会有精度问题。(我是设成10)

\((C_1, r_1)\)关于圆\((P, r)\)反演得到反形\((C_2, r_2)\),我们来求\(r_2\)
根据反演式子可以得到:

$$ \begin{align} (PC_1+r_1) \cdot (PC_2-r_2) = & r^2 \\ (PC_1-r_1) \cdot (PC_2+r_2) = & r^2 \\ \end{align} $$

消去\(PC_2\)可以解得:\[r_2 = \frac{r^2}{2} \left( \frac{1}{PC_1-r_1} - \frac{1}{PC_1+r_1} \right)\]那么再根据\(C_1\)的反演点是\(C_2\),我们也能解出\(C_2\)来。

然后我们需要求切线的反演圆\((O, r_3)\)了,假设切线与圆\((C_2, r_2)\)交于\(A\)
首先\(r_3\)可以由\(P\)到切线的距离\(t\)通过反演定义式求出:\[ 2r_3 \cdot t = r^2 \Rightarrow r_3 = \frac{r^2}{2t} \]然后由于直线\(OP\)\(AC_1\)是平行的(都与切线垂直)
所以根据相似来求出圆心坐标:\[ O = P + \frac{r_3}{r_2} \overrightarrow{C_2 A} \]

#include <cstdio>
#include <cmath>
#include <algorithm>
using namespace std;
typedef double lf;
const lf eps=1e-8;
inline int dcmp(lf x) {
    return x>-eps?x>=eps:-1;
}
struct ip {
    lf x, y;
    ip(lf _x=0, lf _y=0) : x(_x), y(_y) {}
    void scan() {
        scanf("%lf%lf", &x, &y);
    }
};
typedef ip iv;
ip operator + (ip a, iv b) {
    return ip(a.x+b.x, a.y+b.y);
}
iv operator - (ip a, ip b) {
    return iv(a.x-b.x, a.y-b.y);
}
lf operator ^ (iv a, iv b) {
    return a.x*b.y-a.y*b.x;
}
iv operator * (lf k, iv a) {
    return iv(a.x*k, a.y*k);
}
inline lf sqr(lf x) {
    return x*x;
}
lf dis(ip a, ip b) {
    return sqrt(sqr(a.x-b.x)+sqr(a.y-b.y));
}
int onleft(ip a, ip b, iv v) {
    return dcmp(v^(a-b))==1;
}
struct ic {
    ip o;
    lf r;
    void scan() {
        o.scan();
        scanf("%lf", &r);
    }
    ip gen(lf a) {
        return ip(o.x+r*cos(a), o.y+r*sin(a));
    }
    void print() {
        printf("%.8f %.8f %.8f\n", o.x, o.y, r);
    }
}o[2], ans[2], p;
ic inv(ic a) {
    ic b;
    lf d=dis(a.o, p.o), r2=sqr(p.r),
       k1=r2/(d-a.r), k2=r2/(d+a.r);
    b.r=0.5*(k1-k2);
    b.o=p.o+0.5*(k1+k2)/d*(a.o-p.o);
    return b;
}
ic inv(ip a, ip b) {
    ic c;
    c.r=sqr(p.r)/(abs(((b-a)^(p.o-a))/dis(a, b))*2);
    c.o=p.o+(c.r/o[0].r)*(a-o[0].o);
    return c;
}
int cal() {
    int tot=0;
    o[0]=inv(o[0]);
    o[1]=inv(o[1]);
    if(o[0].r<o[1].r) {
        swap(o[0], o[1]);
    }
    iv t=o[1].o-o[0].o;
    lf k1=atan2(t.y, t.x),
       k2=acos((o[0].r-o[1].r)/dis(o[0].o, o[1].o));
    ip a=o[0].gen(k1+k2), b=o[1].gen(k1+k2);
    t=b-a;
    if(onleft(o[0].o, a, t)==onleft(p.o, a, t)) {
        ans[tot++]=inv(a, b);
    }
    a=o[0].gen(k1-k2), b=o[1].gen(k1-k2);
    t=b-a;
    if(onleft(o[0].o, a, t)==onleft(p.o, a, t)) {
        ans[tot++]=inv(a, b);
    }
    return tot;
}
int main() {
    int T;
    scanf("%d", &T);
    while(T--) {
        o[0].scan();
        o[1].scan();
        p.o.scan();
        p.r=10;
        int tot=cal();
        printf("%d\n", tot);
        for(int i=0; i<tot; ++i) {
            ans[i].print();
        }
    }
    return 0;
}

转载于:https://www.cnblogs.com/iwtwiioi/p/4986398.html

Foreword By Andrew Glassner xvii Preface xix Mathematical Notation xxi Pseudo-Code xxiii Contributors xxviii I I I I I I I I I IMAGE PROCESSING MAGE PROCESSING MAGE PROCESSING MAGE PROCESSING MAGE PROCESSING Introduction 3 1. Fast Bitmap Stretching C 4 Tomas Möller 2. General Filtered Image Rescaling C 8 Dale Schumacher 3. Optimization of Bitmap Scaling Operations 17 Dale Schumacher 4. A Simple Color Reduction Filter C 20 Dennis Braggviii CONTENTS 5. Compact Isocontours from Sampled Data 23 Douglas Moore and Joseph Warren 6. Generating Isovalue Contours from a Pixmap C 29 Tim Feldman 7. Compositing Black-and-White Bitmaps 34 David Salesin and Ronen Barzel 8. 2 1 2 -D Depth-of-Field Simulation for Computer 36 Animation Cary Scofield 9. A Fast Boundary Generator for Composited 39 Regions C Eric Furman II II II II II N N N N NUMERICAL AND PROGRAMMING UMERICAL AND PROGRAMMING UMERICAL AND PROGRAMMING UMERICAL AND PROGRAMMING UMERICAL AND PROGRAMMING T T T T TECHNIQUES ECHNIQUES ECHNIQUES ECHNIQUES ECHNIQUES Introduction 47 1. IEEE Fast Square Root C 48 Steve Hill 2. A Simple Fast Memory Allocator C 49 Steve Hill 3. The Rolling Ball C 51 Andrew J. Hanson 4. Interval Arithmetic C 61 Jon Rokne 5. Fast Generation of Cyclic Sequences C 67 Alan W. Paeth 6. A Generic Pixel Selection Mechanism 77 Alan W. Paethix CONTENTS 7. Nonuniform Random Points Sets via Warping 80 Peter Shirley 8. Cross Product in Four Dimensions and Beyond 84 Ronald N. Goldman 9. Face-Connected Line Segment Generation in an n-Dimensional Space C 89 Didier Badouel and Charles A. Wüthrich III III III III III M M M M MODELING AND TRANSFORMATIONS ODELING AND TRANSFORMATIONS ODELING AND TRANSFORMATIONS ODELING AND TRANSFORMATIONS ODELING AND TRANSFORMATIONS Introduction 95 1. Quaternion Interpolation with Extra Spins C 96 Jack Morrison 2. Decomposing Projective Transformations 98 Ronald N. Goldman 3. Decomposing Linear and Affine Transformations 108 Ronald N. Goldman 4. Fast Random Rotation Matrices C 117 James Arvo 5. Issues and Techniques for Keyframing Transformations 121 Paul Dana 6. Uniform Random Rotations C 124 Ken Shoemake 7. Interpolation Using Bézier Curves C 133 Gershon Elber 8. Physically Based Superquadrics C 137 A. H. Barrx CONTENTS I I I I IV V V V V 2-D 2-D 2-D 2-D 2-D GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS Introduction 163 1. A Parametric Elliptical Arc Algorithm C 164 Jerry Van Aken and Ray Simar 2. Simple Connection Algorithm for 2-D Drawing C 173 Claudio Rosati 3. A Fast Circle Clipping Algorithm C 182 Raman V. Srinivasan 4. Exact Computation of 2-D Intersections C 188 Clifford A. Shaffer and Charles D. Feustel 5. Joining Two Lines with a Circular Arc Fillet C 193 Robert D. Miller 6. Faster Line Segment Intersection C 199 Franklin Antonio 7. Solving the Problem of Apollonius and Other 203 Related Problems Constantina Sevici V V V V V 3-D 3-D 3-D 3-D 3-D GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS GEOMETRY AND ALGORITHMS Introduction 213 1. Triangles Revisited 215 Fernando J. López-López 2. Partitioning a 3-D Convex Polygon with an 219 Arbitrary Plane C Norman Chin 3. Signed Distance from Point to Plane C 223 Príamos Georgiadesxi CONTENTS 4. Grouping Nearly Coplanar Polygons into Coplanar Sets C 225 David Salesin and Filippo Tampieri 5. Newell’s Method for Computing the Plane Equation of a Polygon C 231 Filippo Tampieri 6. Plane-to-Plane Intersection C 233 Príamos Georgiades 7. Triangle-Cube Intersection C 236 Douglas Voorhies 8. Fast n-Dimensional Extent Overlap Testing C 240 Len Wanger and Mike Fusco 9. Subdividing Simplices C 244 Doug Moore 10.Understanding Simploids 250 Doug Moore 11. Converting Bézier Triangles into Rectangular Patches C 256 Dani Lischinski 12.Curve Tesselation Criteria through Sampling 262 Terence Lindgren, Juan Sanchez, and Jim Hall Vl Vl Vl Vl Vl R R R R RAY TRACING AND RADIOSITY AY TRACING AND RADIOSITY AY TRACING AND RADIOSITY AY TRACING AND RADIOSITY AY TRACING AND RADIOSITY Introduction 269 1. Ray Tracing with the BSP Tree C 271 Kelvin Sung and Peter Shirley 2. Intersecting a Ray with a Quadric Surface C 275 Joseph M. Cychosz and Warren N. Waggenspack, Jr.xii CONTENTS 3. Use of Residency Masks and Object Space Partitioning to Eliminate Ray-Object Intersection Calculations 284 Joseph M. Cychosz 4. A Panoramic Virtual Screen for Ray Tracing C 288 F. Kenton Musgrave 5. Rectangular Bounding Volumes for Popular Primitives C 295 Ben Trumbore 6. A Linear-Time Simple Bounding Volume Algorithm 301 Xiaolin Wu 7. Physically Correct Direct Lighting for Distribution Ray Tracing C 307 Changyaw Wang 8. Hemispherical Projection of a Triangle C 314 Buming Bian 9. Linear Radiosity Approximation Using Vertex-to-Vertex Form Factors 318 Nelson L. Max and Michael J. Allison 10. Delta Form-Factor Calculation for the Cubic Tetrahedral Algorithm C 324 Jeffrey C. Beran-Koehn and Mark J. Pavicic 11. Accurate Form-Factor Computation C 329 Filippo Tampieri VII VII VII VII VII R R R R RENDERING ENDERING ENDERING ENDERING ENDERING Introduction 337 1. The Shadow Depth Map Revisited 338 Andrew Wooxiii CONTENTS 2. Fast Linear Color Rendering C 343 Russell C. H. Cheng 3. Edge and Bit-Mask Calculations for Anti-Aliasing C 349 Russell C. H. Cheng 4. Fast Span Conversion: Unrolling Short Loops C 355 Thom Grace 5. Progressive Image Refinement Via Gridded Sampling C 358 Steve Hollasch 6. Accurate Polygon Scan Conversion Using Half-Open Intervals C 362 Kurt Fleischer and David Salesin 7. Darklights 366 Andrew S. Glassner 8. Anti-Aliasing in Triangular Pixels 369 Andrew S. Glassner 9. Motion Blur on Graphics Workstations C 374 John Snyder, Ronen Barzel and Steve Gabriel 10. The Shader Cache: A Rendering Pipeline Accelerator 383 James Arvo and Cary Scofeld References 611 Index
评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符  | 博主筛选后可见
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值