Reprinted please indicate the source, thank youHttp://blog.csdn.net/acm_cxlove/article/details/7854526
By --- cxlove
Question: Give a light source, give some circles, and calculate the projection interval.
Http://poj.org/problem? Id = 1375
Calculates the coordinates of the intersection between the tangent and the X axis, sorts and merges them.
Finding the tangent between a point and a circle is an analytic ry ???
The figure is ugly, so happy... First, corner A can be obtained by distance between the radius and PQ, and corner B can also be obtained.
Then we can find the angle between the two tangent and the Y axis, which are a + B and B-A respectively. We do not need to care about the positive and negative values. Then we need to ask for the distance. The negative angle is +, and the result is not affected.
For details, seeCode, Concise 1A
# Include <iostream> # include <fstream> # include <iomanip> # include <cstdio> # include <cstring> # include <algorithm> # include <cstdlib> # include <cmath> # include <set> # include <map> # include <queue> # include <stack> # include <string> # include <vector> # include <sstream> # include <ctime> # include <cassert> # define ll long # define EPS 1e-8 # define INF 999999.0 # define zero () ABS (a) <EPS # define N 20 # define mod 100000007 # define PI AC OS (-1.0) using namespace STD; struct point {Double X, Y; point () {} Point (double Tx, double ty) {x = TX; y = ty ;}} p, q; struct node {double L, R;} line [505]; double dist (point P1, point P2) {return SQRT (p1.x-p2.x) * (p1.x-p2.x) + (p1.y-p2.y) * (p1.y-p2.y);} bool CMP (node N1, node N2) {return n1.l <n2.l;} int main () {int N; Double R; while (scanf ("% d", & N )! = EOF & N) {scanf ("% lf", & P. x, & P. y); For (INT I = 0; I <n; I ++) {scanf ("% lf", & Q. x, & Q. y, & R); double D = dist (p, q); Double A = Asin (R/D), B = Asin (P. x-q.x)/d); double ang1 = a + B, ang2 = B-A; line [I]. L = P. x-p.y * Tan (ang1); line [I]. R = P. x-p.y * Tan (ang2) ;}sort (line, line + N, CMP); double L = line [0]. l, r = line [0]. r; For (INT I = 1; I <n; I ++) {If (line [I]. l> r) {printf ("%. 2f %. 2f \ n ", l, R); L = line [I]. l; r = line [I]. r;} else r = max (line [I]. r, R);} printf ("%. 2f %. 2f \ n ", l, R);} return 0 ;}