二维几何⚪专题

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);
}

 

评论
成就一亿技术人!
拼手气红包6.0元
还能输入1000个字符
 
红包 添加红包
表情包 插入表情
 条评论被折叠 查看
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值