Coverage 圆与直线的交点

本文介绍了一种计算手机用户在特定路径上获得信号覆盖率的方法。通过解析路径与多个信号塔的位置和传输半径,利用韦达定理求解路径与信号塔覆盖区域的交集,最终得出信号覆盖的百分比。

Coverage

Time Limit: 1000ms
Memory Limit: 32768KB
64-bit integer IO format:  %I64d      Java class name:  Main
A cell phone user is travelling along a line segment with end points having integer coordinates. In order for the user to have cell phone coverage, it must be within the transmission radius of some transmission tower. As the user travels along the path, cell phone coverage may be gained (or lost) as the user moves inside the radius of some tower (or outside of the radii of all towers). Given the location of up to 100 towers and their transmission radii, you are to compute the percentage of cell phone coverage the user has
along the specified path. The (x,y) coordinates are integers between -100 and 100, inclusive, and the tower radii are integers between 1 and 100, inclusive.

Input

Your program will be given a sequence of configurations, one per line, of the form: N C0X C0Y C1X C1Y T1X T1Y T1R T2X T2Y T2R ... Here, N is the number of towers, (C0X,C0Y) is the start of path of the cell phone user,
(C1X,C1Y) is the end of the path, (TkX,TkY) is the position of the kth tower, and TkR is its transmission radius. The start and end points of the paths are distinct. The last problem is terminated by the line 0

Output

For each configuration, output one line containing the percentage of coverage the cell phone has, rounded to two decimal places.

Sample Input

3 0 0 100 0 0 0 10 5 0 10 15 0 10
1 0 0 100 0 40 10 50
0

Sample Output

25.00
88.99
分析:给出一条路径 再给出n个塔及每个塔发出的信号波长,求被信号覆盖的路所占总路程的百分比;

韦达定理 求线与圆的交点;

 PS:当直线斜率不存在的时候 将直角坐标系翻转90度 即可以在输入的过程中将点的横纵坐标对调 即可保证斜率不存在的情况下也能表示出斜率

<span style="font-size:18px;">#include <iostream>
#include <stdio.h>
#include <string.h>
#include <math.h>
#include <algorithm>
using namespace std;
struct gg
{
    double x,y,r,lx,rx;
} a[105];
bool cmp(gg a,gg b)
{
    return a.lx<b.lx;
}
int main()
{
    int n;
    while (scanf("%d",&n))
    {
        if (n==0)break;
        double sx,sy,ex,ey,flag=0,temp;
        scanf("%lf%lf%lf%lf",&sx,&sy,&ex,&ey);
        if (sx==ex)
        {
            temp=sx;
            sx=sy;
            sy=temp;
            temp=ex;
            ex=ey;
            ey=temp;
            flag=1;
        }
        double k,c;
        k=(ey-sy)/(ex-sx);
        c=ey-k*ex;
        for (int i=0; i<n; i++)
        {
            scanf("%lf%lf%lf",&a[i].x,&a[i].y,&a[i].r);
            if(flag)
            {
                temp=a[i].x;
                a[i].x=a[i].y;
                a[i].y=temp;
            }
            double A,B,C,T;
            A=1+k*k;
            B=-2*a[i].x+2*k*c-2*a[i].y*k;
            C=c*c+a[i].y*a[i].y+a[i].x*a[i].x-2*a[i].y*c-a[i].r*a[i].r;
            T=B*B-4*A*C;
            if(T>0)
            {
                a[i].lx=(-B-sqrt(T))/(2*A);
                a[i].rx=(-B+sqrt(T))/(2*A);
                if(a[i].lx>max(sx,ex)||a[i].rx<min(sx,ex))//不在范围
                a[i].lx=a[i].rx=-111;
                else
                {
                    if(a[i].lx<min(sx,ex))a[i].lx=min(sx,ex);
                    if(a[i].rx>max(sx,ex))a[i].rx=max(sx,ex);
                }
            }
            else
                a[i].lx=a[i].rx=-111;

        }
        sort(a,a+n,cmp);
        double sum=0,l=a[0].lx,r=a[0].rx;
        for (int i=0; i<n; i++)
        {
            if(a[i].lx<r)
            {
                r=r>a[i].rx?r:a[i].rx;
            }
            else
            {
                sum+=r-l;
                l=a[i].lx;
                r=a[i].rx;
            }
            if (i==n-1)
                sum+=r-l;
        }
        printf("%.2lf\n",sum/((ex-sx)>0?(ex-sx):(sx-ex))*100);
    }
    return 0;
}</span>




情况(1):雷达探测区域边界地形切面首末交点 M、N 位于山峰点的同侧。雷达探测区域部分被遮挡,此时应当修正为以闭合曲线 OMNO为边界的区域。 情况(2):雷达探测区域边界地形切面首末交点 M、N 位于山峰点的异侧。雷达探测区域部分被遮挡,这种情况应当修正为以闭合曲线OMPQO为边界的区域。 单峰修正算法具体实现: 定义二维数组 RadioVC[m,n]存放修正后的雷达探测区域抽样点集。抽样方位角i上,若雷达最大探测边界曲线数字地形曲线不相交,则该方位角探测区域未受影响,不需要修正;若相交且按逆时针方向的首末两交点为Mi、Ni,则受到影响,需要修正。 Step1:在方位角i一定时:俯仰角[j]令j从0到 n-1 遍历,Mi是雷达探测区域边界抽样点高程首次小于该点数字地形高程的点;俯仰角[j]令j从n-1到0遍历,Ni是雷达探测区域边界抽样点高程首次小于该点数字地形高程的点。因此,可以利用该特征,通过一个嵌套的循环找出Mi和Ni对应的俯仰角在俯仰角数组[n]的索引值n_Mi和n_Ni。将方位角i,i 从 0 到 m-1 遍历所有的抽样方位角[i],出所有受影响的方位角方向上的交点Mi和Ni在俯仰角数组[n]中的索引值n_Mi和n_Ni,将结果存放在二维数组Index[m ,2]。 Step2:判断Mi、Ni位于 P 的同侧还是异侧。对MiNi在水平面的投影线段M'iN'i按间距M'iN'i/(n_Ni-n_Mi)平均采样,出采样点对应水平面的 x 和 z 坐标值,根据数字地形产生机理,地形网格分辨率为11,对 x 和 z 按照四舍五入法取整,确定对应抽样点地形高层,保存一维地形点集数组LandVC[n_Ni-n_Mi+1] 。分析可知:若同侧,影响部分地形高程逐渐增大;若异侧,影响部分地形高程先增大后减小。依照此规律,确定结论,且异侧时,出山峰点Pi。解山峰点用一个循环来判断。若一直随循环次数增大逐渐增大,则说明n_Mi、n_Ni位于 P 的同侧,否则,记录首次减小时循环次数,令 n_P=循环次数-1,判断为位于异侧,且可以判定LandVC[n_P]就是山峰点P。 Step3:若Mi、Ni同侧,则只需将方位角j的雷达探测边界曲线MiNi修正为数字地形边界曲线MiNi即可。 若Mi、Ni异侧,则根据“ Step2”出的山峰点Pi,雷达探测区域边界曲线MiNiQi修正为地形曲线MiPi和直线PiQi,Qi为OPi延长线雷达探测区域边界的交点。MiPi修正,根据出的Pi对应俯仰角数组[n]的索引值n_Pi,在索引值n_Mi至n_Pi对应采样修正为地形曲线MiPi;PiQi修正,首先确定Qi位置。Qi是雷达探测边界点高程直线OQi上点高程大小的分界点。遍历雷达探测区域抽样点,找出雷达探测区域点高程首次大于直线 OQ 上点高程的索引值,令n_Qi=索引值。雷达探测区域边界点俯仰角索引值从n_Pi+1到n_Qi,可修正为线段PiQi对应的采样点。 Step4:按以上方法,修正所有受地形影响的方位角,得到修正后的雷达探测区域点数组RadioVC[m,n]。最后,将得到的点数组按照方向和方向连接成线,实现修正后的雷达探测区域。利用以上的方法,给出单峰修正的matlab代码
最新发布
05-13
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值