In geometry the Fermat point of a triangle, also called Torricelli point, is a point such that the total distance from the three vertices of the triangle to the point is the minimum. It is so named because this problem is first raised by Fermat in a private letter. In the following picture, P 0 is the Fermat point. You may have already known the property that: 

Alice and Bob are learning geometry. Recently they are studying about the Fermat Point.

Alice: I wonder whether there is a similar point for quadrangle.

Bob: I think there must exist one.

Alice: Then how to know where it is? How to prove?

Bob: I don’t know. Wait… the point may hold the similar property as the case in triangle.

Alice: It sounds reasonable. Why not use our computer to solve the problem? Find the Fermat point, and then verify your assumption.

Bob: A good idea.

So they ask you, the best programmer, to solve it. Find the Fermat point for a quadrangle, i.e. find a point such that the total distance from the four vertices of the quadrangle to that point is the minimum.

 

Input

The input contains no more than 1000 test cases.

Each test case is a single line which contains eight float numbers, and it is formatted as below:

1 y 1 x 2 y 2 x 3 y 3 x 4 y 4

i, y i are the x- and y-coordinates of the ith vertices of a quadrangle. They are float numbers and satisfy 0 ≤ x i ≤ 1000 and 0 ≤ y i ≤ 1000 (i = 1, …, 4).

The input is ended by eight -1.

 

Output

For each test case, find the Fermat point, and output the total distance from the four vertices to that point. The result should be rounded to four digits after the decimal point.
 

Sample Input

0 0 1 1 1 0 0 1
1 1 1 1 1 1 1 1
-1 -1 -1 -1 -1 -1 -1 -1
 

四边形费马点

平面四边形中费马点证明相对于三角形中较为简易,也较容易研究。
(1)在凸四边形ABCD中,费马点为两对角线AC、BD交点P。
(2)在凹四边形ABCD中,费马点为凹顶点D(P)。

平面四边形费马点证明图形

经过上述的推导,我们即得出了三角形中费马点的找法:当三角形有一个内角大于或等于120°的时候,费马点就是这个内角的顶点;如果三个内角都在120°以内,那么,费马点就是使得费马点与三角形三顶点的连线两两夹角为120°的点。另一种更为简捷的证明 :设O为三顶点连线最短点,以A为圆心AO为半径做圆P。将圆P视作一面镜子。显然O点应该为B出发的光线经过镜子到C的反射点(如果不是,反射点为O',就会有BO’+ CO' < BO+ CO,而AO’= AO,就会有 AO’+ BO’+ CO' < AO + BO + CO)。
不失一般性。O点对于B、C为圆心的镜子也成立。因此根据对称性AO、BO、CO之间夹角都是120°
(补充说明:AO、BO、CO是每个镜子的法线)
 
取四个点其中一个点或者四个点两两连线的交点,各算一遍即可
感受:赛场上没有及时证明猜想,导致smilewsw一直不敢敲...,几何证明实力太弱,虽然想到镜面反射来证最短,但是没有具体转化
这是萌萌smilewsw代码
 
#include <cstdio>
#include <cstring>
#include <algorithm>
#include <cmath>
#include <vector>
using namespace std; const double eps=1e-10; double add(double a,double b)
{
if(abs(a+b)<eps*(abs(a)+abs(b))) return 0;
return a+b;
} struct point
{
double x,y;
point () {}
point (double x,double y) : x(x),y(y){ }
point operator + (point p)
{
return point (add(x,p.x),add(y,p.y));
}
point operator - (point p)
{
return point (add(x,-p.x),add(y,-p.y));
}
point operator * (double d)
{
return point (x*d,y*d);
}
double dot(point p)
{
return add(x*p.x,y*p.y);
}
double det(point p)
{
return add(x*p.y,-y*p.x);
}
}; bool on_seg(point p1,point p2,point q)
{
return (p1-q).det(p2-q)==0&&(p1-q).dot(p2-q)<=0;
} point intersection(point p1,point p2,point q1,point q2)
{
return p1+(p2-p1)*((q2-q1).det(q1-p1)/(q2-q1).det(p2-p1));
} bool cmp_x(const point&p,const point& q)
{
if(p.x!=q.x) return p.x<q.x;
return p.y<q.y;
} vector<point> convex_hull(point*ps,int n)
{
sort(ps,ps+n,cmp_x);
//for(int i=0;i<n;i++) printf("x=%.f %.f")
int k=0;
vector<point> qs(n*2);
for(int i=0;i<n;i++){
while(k>1&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
for(int i=n-2,t=k;i>=0;i--){
while(k>t&&(qs[k-1]-qs[k-2]).det(ps[i]-qs[k-1])<=0) k--;
qs[k++]=ps[i];
}
qs.resize(k-1);
return qs;
} double dis(point p1,point p2)
{
return sqrt((p1.x-p2.x)*(p1.x-p2.x)+(p1.y-p2.y)*(p1.y-p2.y));
}
bool equ(point p1,point p2)
{
if(fabs(p1.x-p2.x)<eps&&fabs(p1.y-p2.y)<eps)
return true;
return false;
}
int main()
{
point p[10];
for(int i=0;i<4;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
while(p[0].x!=-1&&p[0].y!=-1)
{
vector <point> m;
double minn=100000000,d;
m=convex_hull(p,4);//检查是否四边形
if(m.size()==4)//如果是四边形则加入对角线交点考虑
minn=dis(m[1],m[3])+dis(m[0],m[2]);
for(int i=0;i<4;i++)
{
d=0;
for(int j=0;j<4;j++)
d+=dis(p[i],p[j]);
minn=min(minn,d);
}
printf("%.4f\n",minn);
for(int i=0;i<4;i++)
scanf("%lf%lf",&p[i].x,&p[i].y);
}
return 0;
}

  

hdu 3694 10 福州 现场 E - Fermat Point in Quadrangle 费马点 计算几何 难度:1的更多相关文章

  1. hdu 3695 10 福州 现场 F - Computer Virus on Planet Pandora 暴力 ac自动机 难度:1

    F - Computer Virus on Planet Pandora Time Limit:2000MS     Memory Limit:128000KB     64bit IO Format ...

  2. hdu 3697 10 福州 现场 H - Selecting courses 贪心 难度:0

    Description     A new Semester is coming and students are troubling for selecting courses. Students ...

  3. hdu 3699 10 福州 现场 J - A hard Aoshu Problem 暴力 难度:0

    Description Math Olympiad is called “Aoshu” in China. Aoshu is very popular in elementary schools. N ...

  4. hdu 3696 10 福州 现场 G - Farm Game DP+拓扑排序 or spfa+超级源 难度:0

    Description “Farm Game” is one of the most popular games in online community. In the community each ...

  5. hdu 3682 10 杭州 现场 C - To Be an Dream Architect 简单容斥 难度:1

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  6. hdu 3685 10 杭州 现场 F - Rotational Painting 重心 计算几何 难度:1

    F - Rotational Painting Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  7. hdu 3682 10 杭州 现场 C To Be an Dream Architect 容斥 难度:0

    C - To Be an Dream Architect Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d &a ...

  8. hdu 3687 10 杭州 现场 H - National Day Parade 水题 难度:0

    H - National Day Parade Time Limit:1000MS     Memory Limit:32768KB     64bit IO Format:%I64d & % ...

  9. hdu 4770 13 杭州 现场 A - Lights Against Dudely 暴力 bfs 状态压缩DP 难度:1

    Description Harry: "But Hagrid. How am I going to pay for all of this? I haven't any money.&quo ...

随机推荐

  1. talib 中文文档(三):talib 方法大全

    Function API Examples Similar to TA-Lib, the function interface provides a lightweight wrapper of th ...

  2. Qt::QWindow多窗口争抢置顶状态解决方案

    有时候我们会有这种需求,自己的桌面程序需要置顶,但是程序包含了很多窗口,可能我们要求窗口1,2都在其它桌面程序之上,但是窗口1必须随时在窗口2之上. Qt提供的置顶方式是在windowsflags上增 ...

  3. centos LAMP第三部分php,mysql配置 php配置文件 配置php的error_log 配置php的open_basedir 安装php的扩展模块 phpize mysql配置第二十一节课

    centos   LAMP第三部分php,mysql配置 php配置文件   配置php的error_log  配置php的open_basedir 安装php的扩展模块 phpize  mysql配 ...

  4. SQL Server简洁查询正在运行SQL(等待事件)

    通常我们可以使用 sp_who2 我们希望更加简洁的信息,下面这个查询使用系统表sys.sysprocesses,以及sys.dm_exec_sql_text做OUTER APPLY. T-SQL是这 ...

  5. Linux光标移动异常

    刚刚安装完毕CentOS7.5,进行基础优化来着,发现我的光标具有如下神奇的故障. 无法移动到头部? 刚开始还以为是ISO镜像的问题,后校验了阿里云官网镜像的MD5值,和本地镜像MD5对比之后, 发现 ...

  6. ASP.NET之报表--RDLC(一)---附源码

    听同事介绍到RDLC,之前有了解过报表,但是确实没什么放在心上.最近有空,就研究下了. 一.RDLC实现 1.步骤 (1)首先新建一个项目RDLCDemo (2)新建一个DataSet数据集,并且绑定 ...

  7. Entity Framework在WCF中序列化的问题(转)

    问题描述 如果你在WCF中用Entity Framework来获取数据并返回实体对象,那么对下面的错误一定不陌生. 接收对 http://localhost:5115/ReService.svc 的 ...

  8. Kernel space是啥?

    今天因为查一个Java zero copy的问题,遇到了kernel space.之前是耳闻过内核空间的,但是看到kernel space不知道是啥.知道的太少,除了学习,我也做不了啥.因为自己认知有 ...

  9. js正则表达式的使用详解

    本文转自:http://www.jb51.net/article/39623.htm 1定义正则表达式2关于验证的三个这则表达式方法3正则表达式式的转义字符 1定义正则表达式在js中定义正则表达式很简 ...

  10. 在JAVA可移植性的来源的三方面

    软件可移植性的概念是与软件从某一环境转移到另一环境下的难易程度.为获得较高的可移植性,在设计过程中常采用通用的程序设计语言和运行支撑环境.尽量不用与系统的底层相关性强的语言.下面介绍JAVA的可移植性 ...