hdu 3532 Max Angle

本文介绍了一个计算几何中特定角度的算法实现,通过使用atan2函数调整角度范围,并针对多点集合计算最小覆盖角度,适用于计算二维平面上点之间的相对角度问题。
部署运行你感兴趣的模型镜像
1. atan2(y,x)返回值在 -pi 到 pi 之间。要划区间
2.当两线段夹角 angel > pi 时 , 取 angle = 2Pi - angle .
#include <stdio.h>
#include <iostream>
#include <math.h>
using namespace std;
#define FOR(i,s,e) for (int (i)=(s);(i)<(e);i++)
const double INF  = 1E20;
const double eps = 1E-10;
const int  MAXV = 300;
const double PI  = 3.1415926535897932384626;
/* 基本几何结构 */
struct POINT
{
 double x;
 double y;
 POINT(double a=0, double b=0) { x=a; y=b;} //constructor
};

double myatan2(double y,double x)
{
    double t = atan2(y,x);

    return t >= 0 ? t : t + 2*PI;
}
double angle[1010];
POINT p[1011];
int main()
{
    int n;
    // freopen("in.txt","r",stdin);
    while (scanf("%d",&n),n>0)
    {
        FOR(i,0,n)
        {
            scanf("%lf%lf",&p[i].x,&p[i].y);
        }
        double max = -500;
        FOR(i,0,n)
        {
            int num = 0;
            FOR(j,0,n)
            if (i != j)
            angle[num++] = myatan2(p[i].y-p[j].y,p[i].x-p[j].x);
            sort(angle,angle+num);
            double min = INF;
            FOR(j,0,num-1)
            {
                double a = angle[j+1]-angle[j] < PI ? angle[j+1]-angle[j] : 2*PI-angle[j+1]-angle[j];
                if (min > a)
                min = a;
            }

            if (min > max)
            max = min ;

        }
        printf("%.4lf\n",fabs(max/PI*180));
    }
    return 0;
}


您可能感兴趣的与本文相关的镜像

Stable-Diffusion-3.5

Stable-Diffusion-3.5

图片生成
Stable-Diffusion

Stable Diffusion 3.5 (SD 3.5) 是由 Stability AI 推出的新一代文本到图像生成模型,相比 3.0 版本,它提升了图像质量、运行速度和硬件效率

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

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值