HDU6354 Everything Has Changed
求圆弧的周长
#include<bits/stdc++.h>
using namespace std;
const int MAX=1e2+5;
const double PI=3.14159265358979323846;
const double eps=1e-8;
struct point
{
double x,y;
point(){}
point(double a,double b)
{
x=a;y=b;
}
point operator -(const point &a)const//向量差
{
return point(x-a.x,y-a.y);
}
double operator ^(const point &a)const//向量叉乘
{
return x*a.y-y*a.x;
}
double operator *(const point &a)const//向量点乘
{
return x*a.x+y*a.y;
}
};
double dis(point a,point b)//两点距离sqrt(dis)
{
return (a-b)*(a-b);
}
double cal(point c1,double r1,point c2,double r2)
{
double d = sqrt(dis(c1,c2));
if(r1+r2-d<-eps||fabs(r1-r2)-d>eps) return 0;//判断小⚪与大⚪是否相交
double x = (d*d + r1*r1 - r2*r2)/(2*d);
double t1 = acos(x / r1);//大⚪的夹角/2
double t2 = acos((d - x)/r2);//小⚪的夹角/2
return (t2*r2-t1*r1)*2;//圆弧的周长为角度*半径
}
int main()
{
int t,m;
double R,x,y,r;
point O(0,0);
scanf("%d",&t);
while(t--)
{
scanf("%d%lf",&m,&R);
double ans=R*PI*2;
while(m--)
{
scanf("%lf%lf%lf",&x,&y,&r);
point E(x,y);
ans+=cal(O,R,E,r);
}
printf("%f\n",ans);
}
return 0;
}
两圆相交的面积
double areaover(point c1,double r1,point c2,double r2)
{
double d=sqrt(dis(c1,c2));
if(r1+r2-d<-eps) return 0;
if(fabs(r1-r2)-d>eps)
{
double r=min(r1,r2);
return PI*r*r;
}
double x=(d*d+r1*r1-r2*r2)/(2*d);
double t1=acos(x/r1);
double t2=acos((d-x)/r2);
return r1*r1*t1+r2*r2*t2-d*r1*sin(t1);
}
求三角形的外心(三点确定圆心)
point outcenter(point a,point b,point c)
{
double a1=b.x-a.x,b1=b.y-a.y,c1=(a1*a1+b1*b1)/2;
double a2=c.x-a.x,b2=c.y-a.y,c2=(a2*a2+b2*b2)/2;
double d=a1*b2-a2*b1;
return point(a.x+(c1*b2-c2*b1)/d,a.y+(a1*c2-a2*c1)/d);
}

1万+

被折叠的 条评论
为什么被折叠?



