我目前正在处理一个3d bin打包问题,我希望将结果表示为图像。
我将结果存储为包装对象列表,如下所示
public class LoadedPackage
{
private PackingObject packingObject;
private int xloc, yloc, zloc;
private bool flipped = false;
}
public class PackingObject
{
private int ID, checkerMaster, height, width, depth, number;
}
我想使用xloc,yloc,zloc和尺寸一次绘制包1以构建图像。是否有某种图像库方式可以做到这一点,或者我将被迫使用openGL解决方案,这对我来说只是一个简单的图像看起来有点过分。
我在考虑使用2d gdi lib的等轴测法
答案 0 :(得分:0)
最后,我选择了等距方法,并为每个包添加了一个方法,将自身从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;
}