又被题给虐了。三维的,不过可以转化为二维来看。
两个点之间有一个球(两点在球外),两个点之间扯一条线,问线的最短距离。
两种情况
1、AB不会碰着球,直接求AB之间距离即可
2、会碰着球。
第二种情况比较纠结,有同学用物理方法说明,那一段弧一定过球的大圆。。。过大圆的话,情况就是下图了,就求得红色线以及在圆上的那段弧了。这个简单,求得红色的角度就能求出来弧长了。
#include <set>
#include <map>
#include <queue>
#include <stack>
#include <math.h>
#include <stdio.h>
#include <stdlib.h>
#include <iostream>
#include <limits.h>
#include <string.h>
#include <string>
#include <algorithm>
#define MID(x,y) ( ( x + y ) >> 1 )
#define L(x) ( x << 1 )
#define R(x) ( x << 1 | 1 )
#define FOR(i,s,t) for(int i=(s); i<(t); i++)
#define BUG puts("here!!!")
#define STOP system("pause")
#define file_r(x) freopen(x, "r", stdin)
#define file_w(x) freopen(x, "w", stdout)
using namespace std;
const double eps = 1e-6;
struct point3 {
double x, y, z;
void get()
{
scanf("%lf%lf%lf", &x, &y, &z);
}
point3(){};
point3(double x, double y, double z) : x(x), y(y), z(z) {}
};
double disp2p(point3 a, point3 b)
{
return sqrt( (a.x - b.x)*(a.x - b.x) +
(a.y - b.y)*(a.y - b.y) +
(a.z - b.z)*(a.z - b.z) );
}
point3 a, b, c;
double r;
double area_triangle(double a,double b,double c)
{
double p = (a+b+c)/2.0;
return sqrt(p*(p-a)*(p-b)*(p-c));
}
int main()
{
a.get(); b.get(); c.get();
scanf("%lf", &r);
double ans = 0;
double ac = disp2p(a, c);
double bc = disp2p(b, c);
double ab = disp2p(a, b);
ans += sqrt( ac*ac - r*r );
ans += sqrt( bc*bc - r*r );
double angc = acos((ac*ac + bc*bc - ab*ab)/(2*ac*bc));
double anga = acos(r/ac);
double angb = acos(r/bc);
double ang = angc - anga - angb;
ans += ang * r;
if( anga + angb >= angc - eps )
printf("%.2lf\n", ab);
else
printf("%.2lf\n", ans);
return 0;
}