0

我目前正在研究一个 3d 装箱问题,我想将我的结果表示为图像。

我将结果存储为打包对象列表,如下所示

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 的等距方法

4

1 回答 1

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;
    }
于 2012-09-03T07:54:07.010 回答