1503: 点到圆弧的距离

Time Limit: 1 Sec  Memory Limit: 128 MB  Special Judge
Submit: 325  Solved: 70
[Submit][Status][Web
Board
]

Description

输入一个点P和一条圆弧(圆周的一部分),你的任务是计算P到圆弧的最短距离。换句话说,你需要在圆弧上找一个点,到P点的距离最小。
提示:请尽量使用精确算法。相比之下,近似算法更难通过本题的数据。

Input

输入包含最多10000组数据。每组数据包含8个整数x1,
y1, x2, y2, x3, y3, xp, yp。圆弧的起点是A(x1,y1),经过点B(x2,y2),结束位置是C(x3,y3)。点P的位置是
(xp,yp)。输入保证A, B, C各不相同且不会共线。上述所有点的坐标绝对值不超过20。

Output

对于每组数据,输出测试点编号和P到圆弧的距离,保留三位小数。你的输出和标准输出之间最多能有0.001的误差。

Sample Input

0 0 1 1 2 0 1 -1
3 4 0 5 -3 4 0 1

Sample Output

Case 1: 1.414
Case 2: 4.000

HINT

 

Source

 
思路:根据三点确定圆心和半径;关键是确定扇形区域(尤其是优弧)
 
 
 
 
确定点在扇形区域就分两种情况,在圆内和圆外;不在扇形区域就是min(到A,到C)距离最短的;
 
 
转载请注明出处:寻找&星空の孩子 
 
 
具体见代码:
 
 #include<stdio.h>
#include<math.h>
#define PI acos(-1.0)
#include<algorithm>
using namespace std;
struct Point
{
double x;
double y;
Point(double x=,double y=):x(x),y(y) {} //构造函数,方便代码编写
} pt;
struct Traingle
{
struct Point p[];
} Tr;
struct Circle
{
struct Point center;
double r;
} ans;
//计算两点距离
double Dis(struct Point p, struct Point q)
{
double dx=p.x-q.x;
double dy=p.y-q.y;
return sqrt(dx*dx+dy*dy);
}
//计算三角形面积
double Area(struct Traingle ct)
{
return fabs((ct.p[].x-ct.p[].x)*(ct.p[].y-ct.p[].y)-(ct.p[].x-ct.p[].x)*(ct.p[].y-ct.p[].y))/2.0;
}
//求三角形的外接圆,返回圆心和半径(存在结构体"圆"中)
struct Circle CircumCircle(struct Traingle t)
{
struct Circle tmp;
double a, b, c, c1, c2;
double xA, yA, xB, yB, xC, yC;
a = Dis(t.p[], t.p[]);
b = Dis(t.p[], t.p[]);
c = Dis(t.p[], t.p[]);
//根据 S = a * b * c / R / 4;求半径 R
tmp.r = (a*b*c)/(Area(t)*4.0);
xA = t.p[].x;
yA = t.p[].y;
xB = t.p[].x;
yB = t.p[].y;
xC = t.p[].x;
yC = t.p[].y;
c1 = (xA*xA+yA*yA - xB*xB-yB*yB) / ;
c2 = (xA*xA+yA*yA - xC*xC-yC*yC) / ;
tmp.center.x = (c1*(yA - yC)-c2*(yA - yB)) / ((xA - xB)*(yA - yC)-(xA - xC)*(yA - yB));
tmp.center.y = (c1*(xA - xC)-c2*(xA - xB)) / ((yA - yB)*(xA - xC)-(yA - yC)*(xA - xB));
return tmp;
} typedef Point Vector; Vector operator + (Vector A,Vector B)
{
return Vector(A.x+B.x,A.y+B.y);
} Vector operator - (Point A,Point B)
{
return Vector(A.x-B.x,A.y-B.y);
} Vector operator * (Vector A,double p)
{
return Vector(A.x*p,A.y*p);
} Vector operator / (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 Dot(Vector A,Vector B)
{
return A.x*B.x+A.y*B.y;
}
double length(Vector A)
{
return sqrt(Dot(A,A));
}
double Angle(Vector A,Vector B)
{
return acos(Dot(A,B)/length(A)/length(B));
} double Cross(Vector A,Vector B)
{
return A.x*B.y-B.x*A.y;
}
double Area2(Point A,Point B,Point C)
{
return Cross(B-A,C-A);
}
double len; int main()
{
int ca=;
while(scanf("%lf%lf%lf%lf%lf%lf%lf%lf",&Tr.p[].x,&Tr.p[].y,&Tr.p[].x,&Tr.p[].y,&Tr.p[].x,&Tr.p[].y,&pt.x,&pt.y)!=EOF)
{
// printf("%lf %lf\n%lf %lf\n%lf %lf\n%lf %lf\n",Tr.p[0].x,Tr.p[0].y,Tr.p[1].x,Tr.p[1].y,Tr.p[2].x,Tr.p[2].y,pt.x,pt.y);
Circle CC=CircumCircle(Tr);
// printf("%lf %lf,r=%lf",CC.center.x,CC.center.y,CC.r);
Point A(Tr.p[].x,Tr.p[].y),O(CC.center.x,CC.center.y),C(Tr.p[].x,Tr.p[].y),D(pt.x,pt.y),B(Tr.p[].x,Tr.p[].y); Vector OA(A-O),OB(B-O),OC(C-O),OD(D-O);
if(Cross(OA,OB)<=&&Cross(OB,OC)<=||Cross(OA,OB)>=&&Cross(OB,OC)<&&Cross(OA,OC)>||Cross(OA,OB)<&&Cross(OB,OC)>=&&Cross(OA,OC)>)//顺
{
if(Cross(OA,OD)<=&&Cross(OD,OC)<=||Cross(OA,OD)>=&&Cross(OD,OC)<&&Cross(OA,OC)>||Cross(OA,OD)<&&Cross(OD,OC)>=&&Cross(OA,OC)>)
{
len=fabs(length(D-O));
if(len<=CC.r) len=CC.r-len;
else len=len-CC.r;
}
else
{
len=min(fabs(length(A-D)),fabs(length(C-D)));
}
}
else if(Cross(OA,OB)>=&&Cross(OB,OC)>=||Cross(OA,OB)>&&Cross(OB,OC)<=&&Cross(OA,OC)<||Cross(OA,OB)<=&&Cross(OB,OC)>&&Cross(OA,OC)<)//逆
{
if(Cross(OA,OD)>=&&Cross(OD,OC)>=||Cross(OA,OD)>&&Cross(OD,OC)<=&&Cross(OA,OC)<||Cross(OA,OD)<=&&Cross(OD,OC)>&&Cross(OA,OC)<)
{
len=fabs(length(D-O));
if(len<=CC.r) len=CC.r-len;
else len=len-CC.r;
}
else
{
len=min(fabs(length(A-D)),fabs(length(C-D)));
}
} printf("Case %d: %0.3f\n",ca++,len);
}
return ;
}
/*
0 0 1 1 2 0 1 -1
3 4 0 5 -3 4 0 1
0 0 1 1 1 -1 0 -1
*/
 

点到圆弧的距离(csu1503)+几何的更多相关文章

  1. csuoj 1503: 点到圆弧的距离

    http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 1503: 点到圆弧的距离 时间限制: 1 Sec  内存限制: 128 MB  Speci ...

  2. csu 1503: 点到圆弧的距离

    1503: 点到圆弧的距离 Time Limit: 1 Sec  Memory Limit: 128 MB  Special JudgeSubmit: 614  Solved: 101[Submit] ...

  3. CSU 1503: 点到圆弧的距离(计算几何)

    题目描述 输入一个点 P 和一条圆弧(圆周的一部分),你的任务是计算 P 到圆弧的最短距离.换句话 说,你需要在圆弧上找一个点,到 P点的距离最小. 提示:请尽量使用精确算法.相比之下,近似算法更难通 ...

  4. csu-acm 1503: 点到圆弧的距离

    1503: 点到圆弧的距离 分析: 先判断点和圆心的连线是否在圆弧范围内,如果在,最短距离即到圆心的距离减去半径的绝对值:反之,为到端点的最短距离. 具体看注释 #include <bits/s ...

  5. CSU 1503 点到圆弧的距离(2014湖南省程序设计竞赛A题)

    题目链接:http://acm.csu.edu.cn/OnlineJudge/problem.php?id=1503 解题报告:分两种情况就可以了,第一种是那个点跟圆心的连线在那段扇形的圆弧范围内,这 ...

  6. POJ1584 判断多边形是否为凸多边形,并判断点到直线的距离

    求点到直线的距离: double dis(point p1,point p2){   if(fabs(p1.x-p2.x)<exp)//相等的  {    return fabs(p2.x-pe ...

  7. ArcGIS 点到直线的距离

    /****点到直线的距离*** * 过点(x1,y1)和点(x2,y2)的直线方程为:KX -Y + (x2y1 - x1y2)/(x2-x1) = 0 * 设直线斜率为K = (y2-y1)/(x2 ...

  8. LA 3027 Corporative Network 并查集记录点到根的距离

    Corporative Network Time Limit: 3000MS   Memory Limit: Unknown   64bit IO Format: %lld & %llu [S ...

  9. OpenCV学习(34) 点到轮廓的距离

    在OpenCV中,可以很方便的计算一个像素点到轮廓的距离,计算距离的函数为: double pointPolygonTest(InputArray contour, Point2f pt, bool ...

随机推荐

  1. [转]深入理解 GRE tunnel

    我以前写过一篇介绍 tunnel 的文章,只是做了大体的介绍.里面多数 tunnel 是很容易理解的,因为它们多是一对一的,换句话说,是直接从一端到另一端.比如 IPv6 over IPv4 的 tu ...

  2. Pool:小对象缓存or复用

    对象复用 使用链表作为pool来保存要复用的对象. pool字段 obtain recycle 案例1 android.os.Message private static Message sPool; ...

  3. 初探APT攻击

    首发于i春秋 作者:joe     所属团队:Arctic Shell 团队博客地址:https://www.cnblogs.com/anbus/   0x1:关于APT的相关介绍:     APT是 ...

  4. 前端“黑话”polyfill

    前言 在Web前端开发这个日新月异的时代,总是需要阅读一些最新的英文技术博客来跟上技术的发展的潮流.而有时候会遇到一些比较高频的“黑话”,在社区里面可能已经是人人皆知的“共同语言”,而你接触的少就偏偏 ...

  5. 吴恩达机器学习笔记34-模型选择和交叉验证集(Model Selection and Train_Validation_Test Sets)

    假设我们要在10 个不同次数的二项式模型之间进行选择: 显然越高次数的多项式模型越能够适应我们的训练数据集,但是适应训练数据集并不代表着能推广至一般情况,我们应该选择一个更能适应一般情况的模型.我们需 ...

  6. Day7:html和css

    Day7:html和css 如果有浮动,会导致脱标,定位也能脱标,我们没有清除浮动,因为里面有子绝父相. 清除浮动的方法 额外标签法,在最后一个浮动元素后面添加一个空的标签代码: <div st ...

  7. 第59节:Java中的html和css语言

    欢迎到我的简书查看我的文集 前言: HTML 英文: HyperText Markup Language内容 html是超文本标记语言,是网页语言的基础知识,html是通过标签来定义的语言,所有代码都 ...

  8. 意料之外,情理之中,Spring.NET 3.0 版本发布-

    意料之外,情理之中,Spring.NET 3.0 版本发布- 备受社区和企业开发者广泛关注的Spring.NET在上周发布了3.0版本,并且目前已经保持着持续的更新,让我们一起来看一看他究竟发布了哪些 ...

  9. stc15f104w模拟串口使用

    stc15f104w单片机体积小,全8个引脚完全够一般的控制使用,最小系统也就是个电路滤波----加上一个47uf电容和一个103电容即可,但因为其是一个5V单片机,供电需要使用5V左右电源. 该款单 ...

  10. Docker简介以及操作

    Docker 简介 Docker 是一个开源项目,诞生于 2013 年初,最初是 dotCloud 公司内部的一个业余项目.它基于 Google 公司推出的 Go 语言实现. 项目后来加入了 Linu ...