Hard Evidence -UVa 11562


Hard Evidence

\epsfbox{p115xx.eps}

The young reporter Janne is planning to take a photo of a secret government installation. He needs to obtain evidence of the many serious crimes against good sense that are being committed there, so as to create a scandal and possibly win a Pulitzer. Unfortunately, the base is surrounded by a high fence with high voltage wires running around. Janne does not want to risk being electrocuted, so he wants to take a photo from outside the fence. He can bring a tripod as high as the fence to take a photo, so if he wants he can stand right beside the fence and take his picture. The secret installation is a convex polygon. The fence has a form of a circle. Of course Janne wants to make a photo with maximal possible detail level.

Consider taking a photo of the base from some point P outside the fence. Let Q be the left-most point of the base when viewed from P , and let R be the right-most point of the base when viewed from P . Then the view angle of the base at P is the angle at P in the triangle formed by the three points P , Q and R .

The detail level of the photo depends on the view angle of the base at the point from which the photo is taken. Therefore he wants to find a point to maximize this angle.

Input

The input file contains several test cases, each of them as described below.

The first line of the input file contains two integer numbers: n and r -- the number of vertices of the polygon and the radius of the fence (3$ \le$n$ \le$200 , 1$ \le$r$ \le$1000 ). The following n lines contain two real numbers each -- the coordinates of the vertices of the polygon listed in counterclockwise order. It is guaranteed that all vertices of the polygon are strictly inside the fence circle, and that the polygon is convex. The center of the fence circle is located at the origin, (0, 0) .

Output

For each test case, write to the output the maximal view angle a for the photo ( 0$ \le$a < 2$ \pi$ ), on a line by itself. Any answer with either absolute or relative error smaller than 10-6 is acceptable.

Sample Input

4 2
-1.0 -1.0
1.0 -1.0
1.0 1.0
-1.0 1.0

Sample Output

1.5707963268


题意:找到最大的能够看到的角度。

思路:先预处理,即找到相邻的两个点的连线与圆的交点的两个点所分别对应的角度,找到所有可能的情况,然后对这两个点进行三分操作,找到最大的角度。

另外预处理的那部分几何不好,所有从网上借鉴的代码,不过剩下的部分是我写的。

AC代码如下:

#include<cstdio>
#include<cstring>
#include<cmath>
#include<algorithm>
using namespace std;
const double eps=1e-8,pi=3.14159265358979;
double x[210],y[210],start[210],end[210],r;
int n;
void QuadraticEquation(double a, double b, double c, double &res1, double &res2)
{   double d = b * b - 4 * a * c;
    if (d < 0) return ;
    d = sqrt(d);
    res1 = (-b + d) / (2 * a);
    res2 = (-b - d) / (2 * a);
    return ;
}
double solve(double mi,int i,int j)
{ double x1,y1,a,b,c,angle,ans;
  if(j>n)
   j=1;
  x1=r*cos(mi);
  y1=r*sin(mi);
  a=(x1-x[i])*(x1-x[i])+(y1-y[i])*(y1-y[i]);
  b=(x1-x[j])*(x1-x[j])+(y1-y[j])*(y1-y[j]);
  c=(x[i]-x[j])*(x[i]-x[j])+(y[i]-y[j])*(y[i]-y[j]);
  angle=(a+b-c)/(2*sqrt(a*b));
  ans=acos(angle);
  return ans;
}
int main()
{ int i,j,k,t;
  double dx,dy,a,b,c,res1,res2,mi,mi1,mi2,val,val1,val2,angle,ans,px1,px2,py1,py2,left,right,st1,end1,st2,end2;
  while(~scanf("%d%lf",&n,&r))
  { ans=0;val=0;angle=0;ans=0;
    for(i=1;i<=n;i++)
     scanf("%lf%lf",&x[i],&y[i]);
    for(i=1;i<=n;i++)
    { j=i+1;
      if(j>n)
       j=1;
       dx = x[j] - x[i], dy = y[j] - y[i];
       c = x[i] * x[i] + y[i] * y[i] - r * r;
       a = dx * dx + dy * dy, b = 2 * (dx * x[i] + dy * y[i]);
       QuadraticEquation(a, b, c, res1, res2);
       px1 = x[i] + res1 * dx, py1 = y[i] + res1 * dy;
       px2 = x[i] + res2 * dx, py2 = y[i] + res2 * dy;
       start[i] = atan2(py2, px2);
       end[i] = atan2(py1, px1);
    }
    for(i=1;i<=n;i++)
    { j=i;
      left=start[i];
      right=end[j];
      if(left>right)
       right+=pi*2;
      while(true)
      { while(left+eps<right)
        { mi=(right-left)/3;
          mi1=left+mi;
          mi2=left+mi*2;
          val1=solve(mi1,i,j+1);
          val2=solve(mi2,i,j+1);
          if(val1>val2)
           right=mi2;
          else
           left=mi1;
        }
        if(val1>angle)
         angle=val1;
        j++;
        if(j>n)
         j=1;
        st1=start[i];
        end1=end[i];
        if(st1>end1)
         end1+=2*pi;
        st2=start[j];
        if(st1<=st2 && st2<=end1)
        { left=st2;
          right=end1;
          continue;
        }
        st2+=2*pi;
        if(st1<=st2 && st2<=end1)
        { left=st2;
          right=end1;
          continue;
        }
        break;
      }
    }
    printf("%.10f\n",angle);
  }
}



内容概要:本文详细介绍了900W或1Kw,20V-90V 10A双管正激可调电源充电机的研发过程和技术细节。首先阐述了项目背景,强调了充电机在电动汽车和可再生能源领域的重要地位。接着深入探讨了硬件设计方面,包括PCB设计、磁性器件的选择及其对高功率因数的影响。随后介绍了软件实现,特别是程序代码中关键的保护功能如过流保护的具体实现方法。此外,文中还提到了充电机所具备的各种保护机制,如短路保护、欠压保护、电池反接保护、过流保护和过温度保护,确保设备的安全性和可靠性。通讯功能方面,支持RS232隔离通讯,采用自定义协议实现远程监控和控制。最后讨论了散热设计的重要性,以及为满足量产需求所做的准备工作,包括提供详细的PCB图、程序代码、BOM清单、磁性器件和散热片规格书等源文件。 适合人群:从事电力电子产品研发的技术人员,尤其是关注电动汽车充电解决方案的专业人士。 使用场景及目标:适用于需要高效、可靠充电解决方案的企业和个人开发者,旨在帮助他们快速理解和应用双管正激充电机的设计理念和技术要点,从而加速产品开发进程。 其他说明:本文不仅涵盖了理论知识,还包括具体的工程实践案例,对于想要深入了解充电机内部构造和工作原理的人来说是非常有价值的参考资料。
评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值