最后,我选择了等轴测方法,并为每个包添加了一种方法,将自身从 3d 坐标转换为等轴测坐标。我希望以下代码可以帮助遇到类似困境的其他人!
一个等距立方体有 6 个点,所以我返回一个 6 个点的数组。实际上,我使用 3 个子方法返回 3 个等距多边形以供 GDI lib 处理,但为了这个答案,我将发布更通用的 6 点方法。
public PointF[] convertCoords()
{
float x;
float y;
PointF p;
PointF[] pointFs = new PointF[7];
int x1 = 0;
int y1 = 0;
int z1 = 0;
double rads = Helpers.DegreeToRadian(30);
//point 0 in iso
x = ((float)Math.Cos(rads) * xloc) + ((float)Math.Cos(rads) * yloc);
y = ((float)Math.Sin(rads) * yloc) + zloc - ((float)Math.Sin(rads) * xloc);
y = (-y) + 250;
p = new PointF(x,y);
pointFs[0] = new PointF(p.X,p.Y);
//point 1 in iso
x1 = xloc + packingObject.Depth;
y1 = yloc;
z1 = zloc;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = ((float)Math.Sin(rads) * y1) + z1 - ((float)Math.Sin(rads) * x1);
y = (-y) + 250;
p = new PointF(x, y);
pointFs[1] = new PointF(p.X, p.Y);
//point 2 in iso
x1 = xloc + packingObject.Depth;
y1 = yloc;
z1 = zloc + packingObject.Height;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = (-((float)Math.Sin(rads) * x1)) + ((float)Math.Sin(rads) * y1) + z1;
y = (-y) + 250;
p = new PointF(x, y);
pointFs[2] = new PointF(p.X, p.Y);
//point 3 in iso
x1 = xloc;
y1 = yloc;
z1 = zloc + packingObject.Height;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = (-((float)Math.Sin(rads) * x1)) + ((float)Math.Sin(rads) * y1) + z1;
y = (-y) + 250;
p = new PointF(x, y);
pointFs[3] = new PointF(p.X, p.Y);
//point 4 in iso
x1 = xloc;
y1 = yloc + packingObject.Width;
z1 = zloc + packingObject.Height;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = (-((float)Math.Sin(rads) * x1)) + ((float)Math.Sin(rads) * y1) + z1;
y = (-y) + 250;
p = new PointF(x, y);
pointFs[4] = new PointF(p.X, p.Y);
//point 5 in iso
x1 = xloc + packingObject.Depth;
y1 = yloc + packingObject.Width;
z1 = zloc + packingObject.Height;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = (-((float)Math.Sin(rads) * x1)) + ((float)Math.Sin(rads) * y1) + z1;
y = (-y) + 250;
p = new PointF(x, y);
pointFs[5] = new PointF(p.X, p.Y);
//point 6 in iso
x1 = xloc + packingObject.Depth;
y1 = yloc + packingObject.Width;
z1 = zloc;
x = ((float)Math.Cos(rads) * x1) + ((float)Math.Cos(rads) * y1);
y = (-((float)Math.Sin(rads) * x1)) + ((float)Math.Sin(rads) * y1) + z1;
y = (-y) + 250;
p = new PointF(x, y);
pointFs[6] = new PointF(p.X, p.Y);
return pointFs;
}