51nod 1298 圆与三角形 (计算几何)
2024-08-30 12:17:59
http://www.51nod.com/onlineJudge/questionCode.html#!problemId=1298
求出圆心到三条线段的最短距离,然后判断是否有顶点在圆外,就把全部情况举出来。
#include <cstdio>
#include <cstring>
#include <cmath>
#include <algorithm>
using namespace std;
const double PI = acos(-1.0);
double torad(double deg) { return deg/ * PI; } struct Point
{
double x, y;
Point(double x=, double y=):x(x),y(y) { }
}; typedef Point Vector; Vector operator + (const Vector& A, const Vector& B) { return Vector(A.x+B.x, A.y+B.y); }
Vector operator - (const Point& A, const Point& B) { return Vector(A.x-B.x, A.y-B.y); }
Vector operator * (const Vector& A, double p) { return Vector(A.x*p, A.y*p); }
Vector operator / (const Vector& A, double p) { return Vector(A.x/p, A.y/p); } bool operator < (const Point& a, const Point& b) //结构体运算符的重载
{
return a.x < b.x || (a.x == b.x && a.y < b.y);
} const double eps = 1e-;
int dcmp(double x) { if(fabs(x) < eps) return ; else return x < ? - : ; } bool operator == (const Point& a, const Point &b)
{
return dcmp(a.x-b.x) == && dcmp(a.y-b.y) == ;
} //基本运算:
double dist(const Vector& A, const Vector& B) {return sqrt(pow(A.x-B.x,)+pow(A.y-B.y,));}
double Dot(const Vector& A, const Vector& B) { return A.x*B.x + A.y*B.y; }
double Length(const Vector& A) { return sqrt(Dot(A, A)); }
double Angle(const Vector& A, const Vector& B) { return acos(Dot(A, B) / Length(A) / Length(B)); }
double Cross(const Vector& A, const Vector& B) { return A.x*B.y - A.y*B.x; }
double Area2(Point A, Point B, Point C) {return Cross(B-A, C-A);} //向量旋转 rad是弧度
Vector Rotate(const Vector& A, double rad)
{
return Vector(A.x*cos(rad)-A.y*sin(rad), A.x*sin(rad)+A.y*cos(rad));
}
//点和直线:
//两直线的交点
Point GetLineIntersection(const Point& P, const Point& v, const Point& Q, const Point& w)
{
Vector u = P-Q;
double t = Cross(w, u) / Cross(v, w);
return P+v*t;
} //点到直线的距离
double DistanceToLine(const Point& P, const Point& A, const Point& B)
{
Vector v1=B-A, v2=P-A;
return fabs(Cross(v1,v2)) / Length(v1);
} //点到线段的距离
double DistanceToSegment(const Point& P, const Point& A, const Point& B)
{
if(A == B) return Length(P-A);
Vector v1 = B - A, v2 = P - A, v3 = P - B;
if(dcmp(Dot(v1, v2)) < ) return Length(v2);
else if(dcmp(Dot(v1, v3)) > ) return Length(v3);
else return fabs(Cross(v1, v2)) / Length(v1);
} //点在直线上的投影
Point GetLineProjection(const Point &P, const Point &A,const Point &B)
{
Vector v = B - A;
return A+v*(Dot(v, P-A) / Dot(v, v));
} //线段相交判定
bool SegmentProperIntersection(const Point& a1, const Point& a2, const Point& b1, const Point& b2)
{
double c1 = Cross(a2-a1,b1-a1), c2 = Cross(a2-a1,b2-a1),
c3 = Cross(b2-b1,a1-b1), c4=Cross(b2-b1,a2-b1);
return dcmp(c1)*dcmp(c2)< && dcmp(c3)*dcmp(c4)<;
} //判断点在线段上(两个端点除外)
bool OnSegment(const Point& p, const Point& a1, const Point& a2)
{
return dcmp(Cross(a1-p, a2-p)) == && dcmp(Dot(a1-p, a2-p)) < ;
} int main()
{
freopen("a.txt","r",stdin);
int t;
Vector s,p[];
double r,x;
scanf("%d",&t);
while(t--)
{
scanf("%lf%lf%lf",&s.x,&s.y,&r);
for(int i=;i<;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
int ans=;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
x=DistanceToSegment(s,p[],p[]);
if(x<=r) ans++;
bool flag=;
for(int i=;i<;i++)
{
if(dist(s,p[i])>r)
{
flag=;break;
}
}
// printf("%d %d\n",ans,flag);
if(ans>=&&flag) puts("Yes");
else puts("No");
}
return ;
}
最新文章
- 11.11光棍节工作心得——github/MVP
- Linux 内核常见宏定义
- 第二次C语言作业
- Android Studio 入门指南
- Oracle存储过程中传入参数,传出字符串
- conn,stmt,rset 的关闭(规范)
- 使用HttpURLConnection下载文件时出现 java.io.FileNotFoundException彻底解决办法
- ibatis把表名作为一个参数报错问题的解决方案
- 队列(链式存储)JAVA代码
- JS获取select的值
- asp.net后台的一些操作
- Android App开发常用专题开源代码
- win10快捷键大全
- Java Selenium 定位元素 实现的一个注册功能
- Going from u to v or from v to u? POJ - 2762(强连通 有向最长路径)
- REST架构简析(原论文整理)
- Oracle EBS FORM 更改记录状态
- 【原创】大叔问题定位分享(31)hive metastore报错
- Spring MVC基础知识整理➣数据校验与格式化
- pip install whl
热门文章
- 对于JS == 运算的一些理解
- 微软最新的Web服务器Katana发布了版本3
- spring常用注解笔记
- absolute元素水平居中
- Android BitmapFactory.decodeFile(filePath, options) 返回 Null 6.0权限
- Xamarin.Forms跨平台开发入门-第二部分:深入解析
- spring-mvc hello world (1)
- Record these plug-ins of vscode
- iTOP-4418/6818开发板支持锂电池供电方案
- vue vueRouter vuex Axios webpack 前端常用内容