已知一个展开的盒子,和上面的两个点,求这个盒子拼好后,这两个点的距离。
二维的转三维,然后计算距离即可。细节很繁呐。。
我的get_id函数是分块儿的,然后in_it 是判断在哪个块儿,然后change是坐标转换。
#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")
using namespace std;
const double eps = 1e-6;
struct point{
double x, y;
void get()
{
scanf("%lf%lf", &x, &y);
}
void P(double xx, double yy)
{
x = xx; y = yy;
}
};
struct point3{
double x, y, z;
point3(){};
point3( double x, double y, double z):x(x), y(y), z(z){}
void P(double xx, double yy, double zz)
{
x = xx; y = yy; z == zz;
}
};
struct rectangle{ point a, b;};
rectangle re[10];
point3 u, v;
double a, b, c;
point p1, p2;
bool dy(double x,double y) { return x > y + eps;} // x > y
bool xy(double x,double y) { return x < y - eps;} // x < y
bool dyd(double x,double y) { return x > y - eps;} // x >= y
bool xyd(double x,double y) { return x < y + eps;} // x <= y
bool dd(double x,double y) { return fabs( x - y ) < eps;} // x == y
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) );
}
void get_id()
{
re[1].a.P(0, c+b); re[1].b.P(c, 2*b+c);
re[2].a.P(c, 2*b+c); re[2].b.P(a+c, 2*(b+c));
re[3].a.P(c, b+c); re[3].b.P(a+c, 2*b+c);
re[4].a.P(a+c, b+c); re[4].b.P(2*c+a, 2*b+c);
re[5].a.P(c, b); re[5].b.P(a+c, b+c);
re[6].a.P(c, 0); re[6].b.P(c+a, b);
}
int in_it(point p)
{
FOR(i, 1, 7)
if( dyd(p.x, re[i].a.x) && dyd(p.y, re[i].a.y)
&& xyd(p.x, re[i].b.x) && xyd(p.y, re[i].b.y) )
return i;
}
point3 change(point p, int id)
{
switch(id)
{
case 1: return point3(0, 2 * b + c - p.y, c - p.x);
case 2: return point3(p.x - c, 0, p.y - 2 * b - c);
case 3: return point3(p.x - c, 2 * b + c - p.y, 0);
case 4: return point3(a, 2 * b + c - p.y, p.x - a - c);
case 5: return point3(p.x - c, b, b + c - p.y);
case 6: return point3(p.x - c, p.y, c);
}
}
int main()
{
scanf("%lf%lf%lf", &a, &b, &c);
p1.get(); p2.get();
get_id();
int id_1 = in_it(p1);
int id_2 = in_it(p2);
point3 pp1 = change(p1, id_1);
point3 pp2 = change(p2, id_2);
double ans = disp2p(pp1, pp2);
printf("%.16lf\n", ans);
return 0;
}