[poj] 1375 Interval || 圆的切线&和直线的交点

原题

每组数据给出一些圆(障碍物)的圆心和半径,一个点和一条线段,求站在这个点,能开到的线段的部分的左端点和右端点。没有则输出“No View”



相当于求过该点的圆的两条切线,切线外即为可见的地方。
借鉴于这个blog:http://blog.csdn.net/acm_cxlove/article/details/7896110
只要求出两条直线和竖直的夹角,然后通过向量旋转即可得到交点横坐标。

#include<cstdio>
#include<algorithm>
#include<cmath>
using namespace std;
int n;
double r,d;
struct point
{
    double x,y;
    point() {}
    point(double _x,double _y) : x(_x),y(_y) {}
    point operator - (const point &b) const
    {
        return point(b.x-x,b.y-y);
    }
    double dis()
    {
        return sqrt(x*x+y*y);
    }
}p,q;
struct edge
{
    double l,r;
    bool operator < (const edge &b) const
    {
        if (l==b.l) return r<b.r;
        return l<b.l;
    }
}line[510];

int main()
{
    while (~scanf("%d",&n) && n)
    {
    scanf("%lf%lf",&p.x,&p.y);
    for (int i=0;i<n;i++)
    {
        scanf("%lf%lf%lf",&q.x,&q.y,&r);
        d=(p-q).dis();
        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);
    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\n",L,R);
    }
    return 0;
}
时间: 2024-08-04 01:42:31

[poj] 1375 Interval || 圆的切线&和直线的交点的相关文章

poj1375Intervals(点到圆的切线)

链接 貌似这样的叫解析几何 重点如何求得过光源到圆的切线与地板的交点x坐标,可以通过角度及距离来算,如图, 根据距离和半径可以求得角度a.b.r,自然也可以求得d1,d2. 至于方向问题,在求r得时候 可以使r = asin((p.x-c.x)/d) p为源点,c为圆心 ,d为两点距离. 若在反方向,自然r为负角 ,并不影响最后的结果. 排序后,统计区间就可以了. 1 #include <iostream> 2 #include<cstdio> 3 #include<cstr

POJ 1375

可以通过顶角角度来计算切线与坐标轴的坐标 开始还以为有公式可以算,谁知道原来是解二元一次方程,靠.. #include <iostream> #include <cstdio> #include <algorithm> #include <cmath> using namespace std; const int MAX=1050; struct point{ double x; int flag; point(){ flag=0;} }p[MAX]; do

poj3819 Coverage (求直线与圆的交占直线的百分比 )

题意:给你一条直线和若干个圆,求圆与直线相交的长度占整条直线的比例 解题思路:通过定比分点的方法求出圆与直线的交占圆的比例. 第一步:(确定投影的方向是x轴还是y轴) (1)当直线的line.s(x, y), line.e(x, y)的line.s.x与line.e.x不同一时候,这条直线能够等同于起点为line.s.x, line.e.x; (2)不满足(1)时(即line.s.x==line.e.x时),当直线的line.s(x, y), line.e(x, y)的line.s.y与line

两边点连直线求交点总数 树状数组或线段树 poj 3067 Japan

http://poj.org/problem?id=3067 Japan Time Limit: 1000MS   Memory Limit: 65536K Total Submissions: 23602   Accepted: 6369 Description Japan plans to welcome the ACM ICPC World Finals and a lot of roads must be built for the venue. Japan is tall island

poj 1556 zoj1721 BellmanFord 最短路+判断直线相交

http://poj.org/problem?id=1556 The Doors Time Limit: 1000MS   Memory Limit: 10000K Total Submissions: 6120   Accepted: 2455 Description You are to find the length of the shortest path through a chamber containing obstructing walls. The chamber will a

hdu 2857 点在直线上的投影+直线的交点

Mirror and Light Time Limit: 2000/1000 MS (Java/Others)    Memory Limit: 32768/32768 K (Java/Others)Total Submission(s): 814    Accepted Submission(s): 385 Problem Description The light travels in a straight line and always goes in the minimal path b

计算两条直线的交点(C#)

从其他地方看到的源码是有问题的. /// <summary> /// 计算两条直线的交点 /// </summary> /// <param name="lineFirstStar">L1的点1坐标</param> /// <param name="lineFirstEnd">L1的点2坐标</param> /// <param name="lineSecondStar"

计蒜客 直线的交点(计算几何 + 逆序对)

题目链接 直线的交点 两条直线的交点如果落在两个平板之内的话 假设这两条直线和两条平板的交点横坐标分别为  $x1, x2, X1, X2$ 那么有$(x2 - x1)(X2 - X1) < 0$ 于是这就转化成了一个经典问题 我们求出所有直线和平板的两个交点的横坐标,按其中一个平板的横坐标排序, 然后对另一个平板的横坐标求逆序对即可. #include <bits/stdc++.h> using namespace std; #define rep(i, a, b) for (int

求平面内两条直线的交点

The  and  coordinates of the point of intersection of two non-vertical lines can easily be found using the following substitutions and rearrangements. Suppose that two lines have the equations  and  where  and  are the slopes (gradients) of the lines