思路:以某一个面为底面,将展开的图形折合回去,进而将二位坐标转化为三维坐标。
#include <iostream>
#include <cstdio>
#include <cstring>
#include <cmath>
using namespace std;
struct block{
double minx, maxx, miny, maxy;
};
block r[10];
double a, b, c;
int getid(double x1, double y1)
{
int i;
for (i = 0; i < 6; ++i)
if(x1>=r[i].minx && x1 <= r[i].maxx && y1 >= r[i].miny && y1<= r[i].maxy)
return i;
return 0;
}
void reset(int id, double &x, double &y, double &z)
{
switch(id) {
case 0:
z = y-r[id].miny;
y = r[id].miny;
break;
case 1:
z = r[id].maxx - x;
x = r[id].maxx;
break;
case 2:
z = 0;
break;
case 3:
z = x - r[id].minx;
x = r[id].minx;
break;
case 4:
z = r[id].maxy - y;
y = r[id].maxy;
break;
case 5:
z = c;
y = b+b+c-(y-r[id].miny);
break;
}
}
void init()
{
r[0].minx = c;
r[0].maxx = c+c;
r[0].miny = b+c+b;
r[0].maxy = r[0].miny+c;
r[1].minx = 0;
r[1].miny = b+c;
r[1].maxx = c;
r[1].maxy = r[1].miny + b;
r[2].minx = c;
r[2].maxx = r[2].minx + a;
r[2].miny = b+c;
r[2].maxy = r[2].miny+b;
r[3].minx = c + a;
r[3].maxx = r[3].minx + c;
r[3].miny = b+c;
r[3].maxy = r[3].miny+b;
r[4].minx = c;
r[4].maxx = r[4].minx + a;
r[4].miny = b;
r[4].maxy = r[4].miny+c;
r[5].minx = c;
r[5].maxx = r[5].minx + a;
r[5].miny = 0;
r[5].maxy = r[5].miny+b;
}
double getdis(double x, double y, double z, double x2, double y2, double z2)
{
double dx, dy, dz;
dx = x - x2;
dy = y - y2;
dz = z - z2;
return sqrt(dx*dx+dy*dy+dz*dz);
}
int main()
{
double x, y, z, x2, y2, z2;
scanf("%lf %lf %lf", &a, &b, &c);
scanf("%lf %lf", &x, &y);
scanf("%lf %lf", &x2, &y2);
init();
int id;
id = getid(x, y);
reset(id, x, y, z);
id = getid(x2, y2);
reset(id, x2, y2, z2);
double ans = getdis(x, y, z, x2, y2, z2);
printf("%.8lf\n", ans);
return 0;
}