Truyen2U.Net quay lại rồi đây! Các bạn truy cập Truyen2U.Com. Mong các bạn tiếp tục ủng hộ truy cập tên miền mới này nhé! Mãi yêu... ♥

bedanhangoi

struct Point3D

    {

        public float X, Y, Z;

        public Point3D(float x, float y, float z)

        {

            X = x;

            Y = y;

            Z = z;

        }

    }

    struct wireframe

    {

        public Point3D[] vert;

        public int[,] edge;

    }

    public partial class Form1 : Form

    {

        wireframe w;

        Graphics g;

        public Form1()

        {

            InitializeComponent();

            g = this.CreateGraphics();

        }

        wireframe MakeWireframe(string dinh, string canh )

        {

            wireframe w;

            FileStream f = new FileStream(dinh, FileMode.Open);

            StreamReader sr = new StreamReader(f);

            string line;

            int n = 0, i = 0;

            string[] s;

            line = sr.ReadLine();

            n = Convert.ToInt32(line);

            w.vert = new Point3D[n];

            while (!sr.EndOfStream)

            {

                line = sr.ReadLine();

                s = line.Split();

                w.vert[i] = new Point3D(Convert.ToInt32(s[0]), Convert.ToInt32(s[1]), Convert.ToInt32(s[2]));

                i++;

            }

            f.Close();

            f = new FileStream(canh, FileMode.Open);

            sr = new StreamReader(f);

            n = Convert.ToInt32(sr.ReadLine());

            w.edge = new int[n, 2];

            i = 0;

            while (!sr.EndOfStream)

            {

                line = sr.ReadLine();

                s = line.Split();

                w.edge[i, 0] = Convert.ToInt32(s[0]);

                w.edge[i, 1] = Convert.ToInt32(s[1]);

                i++;

            }

            f.Close();

            return w;

        }

        void VeWOXY(wireframe w, Graphics g, int W, int H, Color c)

        {

            Point3D p1, p2;

            PointF Q1, Q2;

            for (int i = 0; i < w.edge.GetLength(0); i++)

            {

                p1 = w.vert[w.edge[i, 0]];

                p2 = w.vert[w.edge[i, 1]];

                Q1 = ChieuSSOXY(p1);

                Q2 = ChieuSSOXY(p2);

                Myline(g, W, H, Q1, Q2, c);

            }

        }

        void VeWOYZ(wireframe w, Graphics g, int W, int H, Color c)

        {

            Point3D p1, p2;

            PointF Q1, Q2;

            for (int i = 0; i < w.edge.GetLength(0); i++)

            {

                p1 = w.vert[w.edge[i, 0]];

                p2 = w.vert[w.edge[i, 1]];

                Q1 = ChieuSSOYZ(p1);

                Q2 = ChieuSSOYZ(p2);

                Myline(g, W, H, Q1, Q2, c);

            }

        }

        void VeWOZX(wireframe w, Graphics g, int W, int H, Color c)

        {

            Point3D p1, p2;

            PointF Q1, Q2;

            for (int i = 0; i < w.edge.GetLength(0); i++)

            {

                p1 = w.vert[w.edge[i, 0]];

                p2 = w.vert[w.edge[i, 1]];

                Q1 = ChieuSSOZX(p1);

                Q2 = ChieuSSOZX(p2);

                Myline(g, W, H, Q1, Q2, c);

            }

        }

        void Myline(Graphics g, int W, int H, PointF p1, PointF p2, Color c)

        {

            p1.Y = H - p1.Y;

            p1.X += W;

            p2.Y = H - p2.Y;

            p2.X += W;

            g.DrawLine(new Pen(Color.Red), p1, p2);

        }

        PointF ChieuSSOXY(Point3D p)

        {

            PointF Q = new PointF();

            Q.X = p.X;

            Q.Y = p.Y;

            return Q;

        }

        PointF ChieuSSOYZ(Point3D p)

        {

            PointF Q = new PointF();

            Q.Y = p.Y;

            Q.X = p.Z;

            return Q;

        }

        PointF ChieuSSOZX(Point3D p)

        {

            PointF Q = new PointF();

            Q.X = p.X;

            Q.Y = p.Z;

            return Q;

        }

        private void Form1_Load(object sender, EventArgs e)

        {

            w = MakeWireframe("C:/Users/Lupj/Desktop/17-57/WindowsFormsApplication5/dinh.txt", "C:/Users/Lupj/Desktop/17-57/WindowsFormsApplication5/canh.txt");

        }

        private void Form1_Paint(object sender, PaintEventArgs e)

        {

        }

        private void OXY_Click(object sender, EventArgs e)

        {

            g.Clear(BackColor);

            VeWOXY(w, g, this.ClientSize.Width / 2, this.ClientSize.Height / 2, Color.Red);

        }

        private void OYZ_Click(object sender, EventArgs e)

        {

            g.Clear(BackColor);

            VeWOYZ(w, g, this.ClientSize.Width / 2, this.ClientSize.Height / 2, Color.Blue);

        }

        private void OZX_Click(object sender, EventArgs e)

        {

            g.Clear(BackColor);

            VeWOZX(w, g, this.ClientSize.Width / 2, this.ClientSize.Height / 2, Color.Black);

        }

        Point3D XoayOx(Point3D p, float al)

        {

            Point3D q = new Point3D();

            q.X = p.X;

            q.Y = (float)(p.Y * Math.Cos(al) - p.Z * Math.Sin(al));

            q.Z = (float)(p.Y * Math.Sin(al) + p.Z * Math.Cos(al));

            return q;

        }

        void XoayWOx(ref wireframe w, float al)

        {

            for (int i = 0; i < w.vert.Length; i++)

            {

                w.vert[i] = XoayOx(w.vert[i], al);

            }

        }

        Point3D XoayOy(Point3D p, float al)

        {

            Point3D q = new Point3D();

            q.Y = p.Y;

            q.X = (float)(p.Z * Math.Sin(al) + p.X * Math.Cos(al));

            q.Z = (float)(p.Z * Math.Cos(al) - p.X * Math.Sin(al));

            return q;

        }

        void XoayWOy(ref wireframe w, float al)

        {

            for (int i = 0; i < w.vert.Length; i++)

            {

                w.vert[i] = XoayOy(w.vert[i], al);

            }

        }

        Point3D XoayOz(Point3D p, float al)

        {

            Point3D q = new Point3D();

            q.Z = p.Z;

            q.Y = (float)(p.X * Math.Sin(al) + p.Y * Math.Cos(al));

            q.X = (float)(p.X * Math.Cos(al) - p.Y * Math.Sin(al));

            return q;

        }

        void XoayWOz(ref wireframe w, float al)

        {

            for (int i = 0; i < w.vert.Length; i++)

            {

                w.vert[i] = XoayOz(w.vert[i], al);

            }

        }

        private void Form1_KeyDown(object sender, KeyEventArgs e)

        {

            //switch (e.KeyCode)

            //{

            //    case Keys.X:

            //        {

            //        }

        }

        PointF ChieuPhoiCanhOYZ(Point3D p, int e)

        {

            PointF Q = new PointF();

            Q.X = p.Y/(1-p.X/e);

            Q.Y = p.Z/(1-p.X/e);

            return Q;

        }

        void VeWPhoiCanhOYZ(wireframe w, Graphics g, int W, int H, Color c)

        {

            Point3D p1, p2;

            PointF Q1, Q2;

            for (int i = 0; i < w.edge.GetLength(0); i++)

            {

                p1 = w.vert[w.edge[i, 0]];

                p2 = w.vert[w.edge[i, 1]];

                Q1 = ChieuPhoiCanhOYZ(p1,500);

                Q2 = ChieuPhoiCanhOYZ(p2,500);

                Myline(g, W, H, Q1, Q2, c);

            }

        }

        private void PhoiCanh_Click(object sender, EventArgs e)

        {

            VeWPhoiCanhOYZ(w, g, this.ClientSize.Width / 2, this.ClientSize.Height / 2, Color.Blue);

        }

Bạn đang đọc truyện trên: Truyen2U.Com

Tags: