Пример #1
0
        public static VsObject Prism(VsPolygon3 bs, double thickness)
        {
            VsObject ret = new VsObject();
            Matrix44 m   = new Matrix44();

            ret.Add(new VsPolygon3(bs));
            m.SetTMat(0.0D, 0.0D, thickness);
            VsPolygon3 p = (VsPolygon3)bs.Transform(m);

            int n = bs.pol.NVertex();

            for (int i = 0; i < n; i++)
            {
                int j = i + 1;
                if (j >= n)
                {
                    j = 0;
                }
                Polygon3D temp = new Polygon3D();
                temp.AddVertex(new Vector3D(bs.pol.GetVertex(i)));
                temp.AddVertex(new Vector3D(p.pol.GetVertex(i)));
                temp.AddVertex(new Vector3D(p.pol.GetVertex(j)));
                temp.AddVertex(new Vector3D(bs.pol.GetVertex(j)));
                ret.Add(new VsPolygon3(temp, new Material(bs.mate)));
            }

            p.pol.Reverse();
            ret.Add(p);

            return(ret);
        }
Пример #2
0
 public void SetPol(Polygon3D pl)
 {
     for (int i = 0; i < pl.NVertex(); i++)
     {
         AddVertex(new Vector3D(pl.GetVertex(i)));
     }
 }
Пример #3
0
        public static VsObject Pyramid(VsPolygon3 bs, Vector3D top)
        {
            VsObject ret = new VsObject();
            Matrix44 m   = new Matrix44();

            ret.Add(new VsPolygon3(bs));

            int n = bs.pol.NVertex();

            for (int i = 0; i < n; i++)
            {
                int j = i + 1;
                if (j >= n)
                {
                    j = 0;
                }
                Polygon3D temp = new Polygon3D();
                temp.AddVertex(new Vector3D(bs.pol.GetVertex(j)));
                temp.AddVertex(new Vector3D(bs.pol.GetVertex(i)));
                temp.AddVertex(new Vector3D(top));
                ret.Add(new VsPolygon3(temp, new Material(bs.mate)));
            }

            return(ret);
        }
Пример #4
0
 public VsPolygon()
 {
     type     = "VsPolygon";
     faceflag = true;
     col      = Color.Black;
     pol      = new Polygon3D();
     faceflag = pol.BackfaceCheck();
 }
Пример #5
0
 public VsPolygon(int np, double[] x, double[] y, double[] z, Color c)
 {
     type     = "VsPolygon";
     faceflag = true;
     col      = c;
     pol      = new Polygon3D(np, x, y, z);
     faceflag = pol.BackfaceCheck();
 }
Пример #6
0
 public VsPolygon(Polygon3D p, Color c)
 {
     type     = "VsPolygon";
     faceflag = true;
     col      = c;
     pol      = p;
     faceflag = pol.BackfaceCheck();
 }
Пример #7
0
 public VsPolygon(VsPolygon p)
 {
     type     = "VsPolygon";
     faceflag = true;
     col      = p.col;
     pol      = new Polygon3D(p.pol);
     faceflag = p.faceflag;
 }
Пример #8
0
 public VsPolygon2(Polygon3D p, Color c, Color cb)
 {
     type     = "VsPolygon2";
     faceflag = true;
     col      = c;
     colB     = cb;
     pol      = p;
     faceflag = pol.BackfaceCheck();
 }
Пример #9
0
 public VsPolygon2(VsPolygon2 p)
 {
     type     = "VsPolygon2";
     faceflag = true;
     col      = p.col;
     colB     = p.colB;
     pol      = new Polygon3D(p.pol);
     faceflag = p.faceflag;
 }
Пример #10
0
 public VsPolygon3(Polygon3D p, Material material)
 {
     type     = "VsPolygon3";
     col      = Color.Black;
     faceflag = true;
     mate     = material;
     pol      = p;
     faceflag = pol.BackfaceCheck();
 }
Пример #11
0
 public VsPolygon3()
 {
     type     = "VsPolygon3";
     col      = Color.Black;
     faceflag = true;
     mate     = new Material();
     pol      = new Polygon3D();
     faceflag = pol.BackfaceCheck();
 }
Пример #12
0
 public VsPolygon2()
 {
     type     = "VsPolygon2";
     faceflag = true;
     col      = Color.Blue;
     colB     = Color.Red;
     pol      = new Polygon3D();
     faceflag = pol.BackfaceCheck();
 }
Пример #13
0
 public VsPolygon(int np, double[] x, double[] y, double[] z, int r, int g,
                  int b)
 {
     type     = "VsPolygon";
     faceflag = true;
     col      = Color.FromArgb(r, g, b);
     pol      = new Polygon3D(np, x, y, z);
     faceflag = pol.BackfaceCheck();
 }
Пример #14
0
 public VsPolygon4(int np, double[] x, double[] y, double[] z, Material material, Material materialB)
 {
     type     = "VsPolygon4";
     col      = Color.Black;
     faceflag = true;
     mate     = material;
     mateB    = materialB;
     pol      = new Polygon3D(np, x, y, z);
     faceflag = pol.BackfaceCheck();
 }
Пример #15
0
 public Polygon3D(Polygon3D pl)
 {
     MAX_VERTEX = 64;
     vertex     = new Vector3D[64];
     n_vertex   = 0;
     for (int i = 0; i < pl.NVertex(); i++)
     {
         AddVertex(new Vector3D(pl.GetVertex(i)));
     }
 }
Пример #16
0
 public VsPolygon3(VsPolygon3 p)
 {
     type     = "VsPolygon3";
     col      = Color.Black;
     faceflag = true;
     mate     = new Material(p.mate);
     col      = p.col;
     pol      = new Polygon3D(p.pol);
     faceflag = p.faceflag;
 }
Пример #17
0
        public Polygon3D Project(Projector proj)
        {
            Polygon3D ret = new Polygon3D();

            for (int i = 0; i < NVertex(); i++)
            {
                ret.AddVertex(proj.Project(GetVertex(i)));
            }

            return(ret);
        }
Пример #18
0
        public Polygon3D Transform(Matrix44 mat)
        {
            Polygon3D ret = new Polygon3D();

            for (int i = 0; i < NVertex(); i++)
            {
                ret.AddVertex(GetVertex(i).MultMat(mat));
            }

            return(ret);
        }
Пример #19
0
        public void Reverse()
        {
            Polygon3D temp = new Polygon3D(this);

            int n = n_vertex;

            for (int i = 0; i < n; i++)
            {
                SetVertex(i, new Vector3D(temp.GetVertex(n - i - 1)));
            }
        }
Пример #20
0
        public Polygon3D Vs_polygon_clip_3df(Polygon3D poly)
        {
            Polygon3D s = new Polygon3D();
            Polygon3D r = new Polygon3D();

            s.SetPol(poly);
            double zmin = s.ZMin();
            double zmax = s.ZMax();

            if (zmax < 0.10000000000000001D)
            {
                return(r);
            }
            if (zmin >= 0.10000000000000001D)
            {
                r.SetPol(poly);
                return(r);
            }
            for (int i = 0; i < s.NVertex(); i++)
            {
                int j;
                if (i == s.NVertex() - 1)
                {
                    j = 0;
                }
                else
                {
                    j = i + 1;
                }
                double xi = s.GetVertex(i).x;
                double yi = s.GetVertex(i).y;
                double zi = s.GetVertex(i).z;
                double xj = s.GetVertex(j).x;
                double yj = s.GetVertex(j).y;
                double zj = s.GetVertex(j).z;
                if (zi >= 0.10000000000000001D)
                {
                    r.AddVertex(new Vector3D(xi, yi, zi));
                    if (zj < 0.10000000000000001D)
                    {
                        double t = (0.10000000000000001D - zi) / (zj - zi);
                        r.AddVertex(new Vector3D(xi + (xj - xi) * t, yi + (yj - yi) * t, 0.10000000000000001D));
                    }
                }
                else if (zj >= 0.10000000000000001D)
                {
                    double t_0 = (0.10000000000000001D - zi) / (zj - zi);
                    r.AddVertex(new Vector3D(xi + (xj - xi) * t_0, yi + (yj - yi) * t_0, 0.10000000000000001D));
                }
            }

            return(r);
        }
Пример #21
0
        public Polygon3D Vs_polygon_clip_2d(Polygon3D poly)
        {
            Polygon3D s     = new Polygon3D();
            Polygon3D r     = new Polygon3D();
            double    vxmin = vp_xmin - 0.40000000000000002D;
            double    vymin = vp_ymin - 0.40000000000000002D;
            double    vxmax = vp_xmax + 0.40000000000000002D;
            double    vymax = vp_ymax + 0.40000000000000002D;

            s.SetPol(poly);
            double xmin = poly.XMin();
            double xmax = poly.XMax();
            double ymin = poly.YMin();
            double ymax = poly.YMax();

            if (xmax < vxmin || xmin > vxmax || ymax < vymin || ymin > vymax)
            {
                return(r);
            }
            if (xmin >= vxmin && xmax <= vxmax && ymin >= vymin && ymax <= vymax)
            {
                r.SetPol(poly);
                return(r);
            }
            if (xmin >= vxmin)
            {
                r.SetPol(s);
            }
            else
            {
                for (int i = 0; i < s.NVertex(); i++)
                {
                    int j;
                    if (i == s.NVertex() - 1)
                    {
                        j = 0;
                    }
                    else
                    {
                        j = i + 1;
                    }
                    double xi = s.GetVertex(i).x;
                    double yi = s.GetVertex(i).y;
                    double xj = s.GetVertex(j).x;
                    double yj = s.GetVertex(j).y;
                    if (xi >= vxmin)
                    {
                        r.AddVertex(new Vector3D(xi, yi, 0.0D));
                        if (xj < vxmin)
                        {
                            r.AddVertex(new Vector3D(vxmin, yi
                                                     + ((yj - yi) * (vxmin - xi)) / (xj - xi), 0.0D));
                        }
                    }
                    else if (xj >= vxmin)
                    {
                        r.AddVertex(new Vector3D(vxmin, yi
                                                 + ((yj - yi) * (vxmin - xi)) / (xj - xi), 0.0D));
                    }
                }
            }
            s = new Polygon3D();
            if (ymin >= vymin)
            {
                s.SetPol(r);
            }
            else
            {
                for (int i_0 = 0; i_0 < r.NVertex(); i_0++)
                {
                    int j_1;
                    if (i_0 == r.NVertex() - 1)
                    {
                        j_1 = 0;
                    }
                    else
                    {
                        j_1 = i_0 + 1;
                    }
                    double xi_2 = r.GetVertex(i_0).x;
                    double yi_3 = r.GetVertex(i_0).y;
                    double xj_4 = r.GetVertex(j_1).x;
                    double yj_5 = r.GetVertex(j_1).y;
                    if (yi_3 >= vymin)
                    {
                        s.AddVertex(new Vector3D(xi_2, yi_3, 0.0D));
                        if (yj_5 < vymin)
                        {
                            s.AddVertex(new Vector3D(xi_2 + ((xj_4 - xi_2) * (vymin - yi_3)) / (yj_5 - yi_3), vymin, 0.0D));
                        }
                    }
                    else if (yj_5 >= vymin)
                    {
                        s.AddVertex(new Vector3D(xi_2 + ((xj_4 - xi_2) * (vymin - yi_3)) / (yj_5 - yi_3), vymin, 0.0D));
                    }
                }
            }
            r = new Polygon3D();
            if (xmax <= vxmax)
            {
                r.SetPol(s);
            }
            else
            {
                for (int i_6 = 0; i_6 < s.NVertex(); i_6++)
                {
                    int j_7;
                    if (i_6 == s.NVertex() - 1)
                    {
                        j_7 = 0;
                    }
                    else
                    {
                        j_7 = i_6 + 1;
                    }
                    double xi_8  = s.GetVertex(i_6).x;
                    double yi_9  = s.GetVertex(i_6).y;
                    double xj_10 = s.GetVertex(j_7).x;
                    double yj_11 = s.GetVertex(j_7).y;
                    if (xi_8 <= vxmax)
                    {
                        r.AddVertex(new Vector3D(xi_8, yi_9, 0.0D));
                        if (xj_10 > vxmax)
                        {
                            r.AddVertex(new Vector3D(vxmax, yi_9 + ((yj_11 - yi_9) * (vxmax - xi_8)) / (xj_10 - xi_8), 0.0D));
                        }
                    }
                    else if (xj_10 <= vxmax)
                    {
                        r.AddVertex(new Vector3D(vxmax, yi_9 + ((yj_11 - yi_9) * (vxmax - xi_8)) / (xj_10 - xi_8), 0.0D));
                    }
                }
            }
            s = new Polygon3D();
            if (ymax <= vymax)
            {
                s.SetPol(r);
            }
            else
            {
                for (int i_12 = 0; i_12 < r.NVertex(); i_12++)
                {
                    int j_13;
                    if (i_12 == r.NVertex() - 1)
                    {
                        j_13 = 0;
                    }
                    else
                    {
                        j_13 = i_12 + 1;
                    }
                    double xi_14 = r.GetVertex(i_12).x;
                    double yi_15 = r.GetVertex(i_12).y;
                    double xj_16 = r.GetVertex(j_13).x;
                    double yj_17 = r.GetVertex(j_13).y;
                    if (yi_15 <= vymax)
                    {
                        s.AddVertex(new Vector3D(xi_14, yi_15, 0.0D));
                        if (yj_17 > vymax)
                        {
                            s.AddVertex(new Vector3D(xi_14 + ((xj_16 - xi_14) * (vymax - yi_15)) / (yj_17 - yi_15),
                                                     vymax, 0.0D));
                        }
                    }
                    else if (yj_17 <= vymax)
                    {
                        s.AddVertex(new Vector3D(xi_14 + ((xj_16 - xi_14) * (vymax - yi_15)) / (yj_17 - yi_15), vymax, 0.0D));
                    }
                }
            }
            return(s);
        }