コード例 #1
0
ファイル: Form1.cs プロジェクト: SheyChen/PnA_Class3_Demo
        private void Button_ChangeViewAngle_Click(object sender, EventArgs e)
        {
            panel_draw_Paint(sender, null);                                       //讓畫布觸發
            double deltXAng, deltYAng, deltZAng;
            double Deg2Rad = Math.PI / 180.0;

            Matrix3D AxisVec = new Matrix3D();

            AxisVec.Value[0] = new double[] { 200, 0, 0 };
            AxisVec.Value[1] = new double[] { 0, 200, 0 };
            AxisVec.Value[2] = new double[] { 0, 0, 200 };

            deltXAng = Convert.ToDouble(textBox_XAngle.Text) * Deg2Rad;
            deltYAng = Convert.ToDouble(textBox_YAngle.Text) * Deg2Rad;
            deltZAng = Convert.ToDouble(textBox_ZAngle.Text) * Deg2Rad;
            Matrix3D MatrixAngX = new Matrix3D();                                //宣告X軸的轉換矩陣

            MatrixAngX.Value[0] = new double[] { 1, 0, 0 };
            MatrixAngX.Value[1] = new double[] { 0, Math.Cos(deltXAng), -Math.Sin(deltXAng) };
            MatrixAngX.Value[2] = new double[] { 0, Math.Sin(deltXAng), Math.Cos(deltXAng) };

            Matrix3D MatrixAngY = new Matrix3D();                                //宣告Y軸的轉換矩陣

            MatrixAngY.Value[0] = new double[] { Math.Cos(deltYAng), 0, Math.Sin(deltYAng) };
            MatrixAngY.Value[1] = new double[] { 0, 1, 0 };
            MatrixAngY.Value[2] = new double[] { -Math.Sin(deltYAng), 0, Math.Cos(deltYAng) };

            Matrix3D MatrixAngZ = new Matrix3D();                                 //宣告Z軸的轉換矩陣

            MatrixAngZ.Value[0] = new double[] { Math.Cos(deltZAng), -Math.Sin(deltZAng), 0 };
            MatrixAngZ.Value[1] = new double[] { Math.Sin(deltZAng), Math.Cos(deltZAng), 0 };
            MatrixAngZ.Value[2] = new double[] { 0, 0, 1 };

            Matrix3D MatrixAng2 = new Matrix3D();

            MatrixAng2 = Matrix3D.MatrixMult(MatrixAngX, MatrixAngY);
            MatrixAng2 = Matrix3D.MatrixMult(MatrixAng2, MatrixAngZ);        //把三個轉換矩陣乘起來
            MatrixAng  = Matrix3D.MatrixMult(MatrixAng, MatrixAng2);

            //InvMat = Matrix3D.MatrixMult(InvMat, Matrix3D.InvMatrux(MatrixAng2));
            NewAxisVec = Matrix3D.MatrixMult(MatrixAng, AxisVec);
            drawLine(penBlue, 0, 0, NewAxisVec.Value[0][0], NewAxisVec.Value[1][0]);
            drawLine(penGreen, 0, 0, NewAxisVec.Value[0][1], NewAxisVec.Value[1][1]);
            drawLine(penYellow, 0, 0, NewAxisVec.Value[0][2], NewAxisVec.Value[1][2]);

            Xang                = Xang + Convert.ToDouble(textBox_XAngle.Text);
            Yang                = Yang + Convert.ToDouble(textBox_YAngle.Text);
            Zang                = Zang + Convert.ToDouble(textBox_ZAngle.Text);
            label_XAng.Text     = "(X軸已旋轉" + Xang.ToString() + "度)";
            label_YAng.Text     = "(Y軸已旋轉" + Yang.ToString() + "度)";
            label_ZAng.Text     = "(Z軸已旋轉" + Zang.ToString() + "度)";
            textBox_XAngle.Text = textBox_YAngle.Text = textBox_ZAngle.Text = "0";  //初始化
        }
コード例 #2
0
ファイル: Form1.cs プロジェクト: SheyChen/PnA_Class3_Demo
 private void Button_PanelInitial_Click(object sender, EventArgs e)
 {
     panel_draw_Paint(sender, null);                                         //讓畫布觸發
     drawLine(penBlue, 0, 0, 200, 0);                                        //藍色的X軸
     drawLine(penGreen, 0, 0, 0, 200);                                       //綠色的Y軸
     drawCircle(penRed, 0, 0, 5);                                            //紅色的Z軸
     Axis_X.Visible  = Axis_Y.Visible = true;                                //開啟坐標軸標示
     Axis_X.Location = new Point(CenterPoint.X + 120, CenterPoint.Y - 10);   //給定標示座標
     Axis_Y.Location = new Point(CenterPoint.X, CenterPoint.Y - 120);
     /*-----初始化-----*/
     textBox_Cx.Text     = textBox_Cy.Text = textBox_Cr.Text = "0";
     textBox_XAngle.Text = textBox_YAngle.Text = textBox_ZAngle.Text = "0";
     MatrixAng.Value[0]  = new double[] { 1, 0, 0 };
     MatrixAng.Value[1]  = new double[] { 0, 1, 0 };
     MatrixAng.Value[2]  = new double[] { 0, 0, 1 };
     Xang            = Yang = Zang = 0.0;
     label_XAng.Text = "(X軸已旋轉" + Xang.ToString() + "度)";
     label_YAng.Text = "(Y軸已旋轉" + Yang.ToString() + "度)";
     label_ZAng.Text = "(Z軸已旋轉" + Zang.ToString() + "度)";
 }
コード例 #3
0
ファイル: Form1.cs プロジェクト: SheyChen/PnA_Class3_Demo
 private void Form1_Load(object sender, EventArgs e)
 {
     penRed              = new Pen(Color.Red, 2);
     penGreen            = new Pen(Color.Green, 2);
     penBlue             = new Pen(Color.Blue, 2);
     penGray             = new Pen(Color.Gray, 1);
     penMag              = new Pen(Color.Magenta, 3);
     penYellow           = new Pen(Color.Yellow, 2);
     myGraph             = this.panel_Draw.CreateGraphics();
     CenterPoint         = new Point(panel_Draw.Location.X + (panel_Draw.Width / 2), panel_Draw.Location.Y + (panel_Draw.Height / 2));
     Axis_X.Visible      = Axis_Y.Visible = Axis_Z.Visible = false;                          //關閉坐標軸標示
     textBox_Cx.Text     = textBox_Cy.Text = textBox_Cr.Text = "0";
     textBox_XAngle.Text = textBox_YAngle.Text = textBox_ZAngle.Text = "0";
     MatrixAng.Value[0]  = new double[] { 1, 0, 0 };
     MatrixAng.Value[1]  = new double[] { 0, 1, 0 };
     MatrixAng.Value[2]  = new double[] { 0, 0, 1 };
     textBox_Arm1_X.Text = "0"; textBox_Arm1_Y.Text = "0"; textBox_Arm1_Z.Text = "100";
     textBox_Arm2_X.Text = "0"; textBox_Arm2_Y.Text = "100"; textBox_Arm2_Z.Text = "0";
     textBox_Arm3_X.Text = "100"; textBox_Arm3_Y.Text = "0"; textBox_Arm3_Z.Text = "0";
     Xang            = Yang = Zang = 0.0;
     label_XAng.Text = "(X軸已旋轉" + Xang.ToString() + "度)";
     label_YAng.Text = "(Y軸已旋轉" + Yang.ToString() + "度)";
     label_ZAng.Text = "(Z軸已旋轉" + Zang.ToString() + "度)";
 }