private void BTSur2_Click_1(object sender, RoutedEventArgs e)
 {
     double Hhudu, Vhudu, Dis;
     Hhudu = ToolCase.HARadom;
     Vhudu = ToolCase.VARadom;
     Dis = ToolCase.DistanceRadom;
     SeconP = ToolCase.CalculationOfCoordinatePoints(StationPoint, Dis, Hhudu, Vhudu);
     LBP2Dis.Content = Dis.ToString("f03");
     LBHA.Content = ToolCase.huduTojiaodu(Hhudu);
     LBVA.Content = ToolCase.huduTojiaodu(Vhudu);
 }
 private void BtMeasuring1_Click(object sender, RoutedEventArgs e)
 {
     double Hhudu, Vhudu, Dis;
     //           string SQL = null;
     Hhudu = ToolCase.HARadom;
     Vhudu = ToolCase.VARadom;
     Dis = ToolCase.DistanceRadom;
     //坐标
     Point_A = ToolCase.CalculationOfCoordinatePoints(StationPoint, Dis, Hhudu, Vhudu);
     LBHA.Content = ToolCase.huduTojiaodu(Hhudu);
     LbVA.Content = ToolCase.huduTojiaodu(Vhudu);
     LbdcA.Content = "完成";
 }
        private void BTSurvey_Click(object sender, RoutedEventArgs e)
        {

            double Hhudu = 0;
            double Distance = 0;
            double Vhudu = 0;
            double HD, SD, VD, FW;
            PointData PD = new PointData();


            if (SurveyNumber == 0)
            {
                Hhudu = ToolCase.HARadom;
                Vhudu = ToolCase.VARadom;
                Distance = ToolCase.DistanceRadom;
                //已知距离方位角反算测站坐标
                StartPoint.X = StationPoint.X - Distance * Math.Cos(Hhudu);
                StartPoint.Y = StationPoint.Y - Distance * Math.Cos(Hhudu);
                SurveyNumber = 1;
                //显示第一点数据信息
                SD = ToolCase.IIPointSD(StationPoint,StartPoint);
                HD = ToolCase.IIPointHD(StationPoint, StartPoint);
                VD = ToolCase.IIPointVD(StationPoint, StartPoint);
                FW = ToolCase.IIPointFW(StationPoint, StartPoint);
                LBFW.Content = ToolCase.huduTojiaodu(FW);
                LBXJ.Content = SD.ToString("f03");
                LbPJ.Content = HD.ToString("f03");
                LbGC.Content = VD.ToString("f03");

                //数据显示
                PD.N = StartPoint.X.ToString("f3");
                PD.E = StartPoint.Y.ToString("f03");
                PD.Z = (10.87).ToString("f03");
                PD.HA = ToolCase.huduTojiaodu(Hhudu);
                PD.VA = ToolCase.huduTojiaodu(Vhudu);
                PD.HD = (Distance * Math.Cos(Vhudu)).ToString("f03");
                PD.VD = (Distance * Math.Sin(Vhudu)).ToString("f03");
                PD.SD = Distance.ToString("f03");

                Point_N.DataContext = PD;
                Point_E.DataContext = PD;
                Point_Z.DataContext = PD;
                Point_HA.DataContext = PD;
                Point_VA.DataContext = PD;
                Point_HD.DataContext = PD;
                Point_VD.DataContext = PD;
                Point_SD.DataContext = PD;
            }
            else
            {
                Hhudu = ToolCase.HARadom;
                Vhudu = ToolCase.VARadom;
                Distance = ToolCase.DistanceRadom;
                SeconPoint = ToolCase.CalculationOfCoordinatePoints(StationPoint, Distance, Hhudu, Vhudu);
                SurveyNumber = SurveyNumber + 1;
                SD = ToolCase.IIPointSD(StartPoint, SeconPoint);
                HD = ToolCase.IIPointHD(StartPoint, SeconPoint);
                VD = ToolCase.IIPointVD(StartPoint, SeconPoint);
                FW = ToolCase.IIPointFW(StartPoint, SeconPoint);
                LBFW.Content = ToolCase.huduTojiaodu(FW);
                LBXJ.Content = SD.ToString("f03");
                LbPJ.Content = HD.ToString("f03");
                LbGC.Content = VD.ToString("f03");

                PD.N = SeconPoint.X.ToString("f3");
                PD.E = SeconPoint.Y.ToString("f03");
                PD.Z = (10.87).ToString("f03");
                PD.HA = ToolCase.huduTojiaodu(Hhudu);
                PD.VA = ToolCase.huduTojiaodu(Vhudu);
                PD.HD = (Distance * Math.Cos(Vhudu)).ToString("f03");
                PD.VD = (Distance * Math.Sin(Vhudu)).ToString("f03");
                PD.SD = Distance.ToString("f03");

                Point_N.DataContext = PD;
                Point_E.DataContext = PD;
                Point_Z.DataContext = PD;
                Point_HA.DataContext = PD;
                Point_VA.DataContext = PD;
                Point_HD.DataContext = PD;
                Point_VD.DataContext = PD;
                Point_SD.DataContext = PD;
                if (IsLock == false)
                {
                    StartPoint.X = SeconPoint.X;
                    StartPoint.Y = SeconPoint.Y;
                    StartPoint.Z = SeconPoint.Z;
                }
            }
        }
        private void BTSave_Click(object sender, RoutedEventArgs e)
        {
            //计算平面方程
            /* 
               A(x - x1) + B(y - y1) + C(z - z1) = 0 (点法式)
               A = (y3 - y1)*(z3 - z1) - (z2 -z1)*(y3 - y1);
               B = (x3 - x1)*(z2 - z1) - (x2 - x1)*(z3 - z1);
               C = (x2 - x1)*(y3 - y1) - (x3 - x1)*(y2 - y1);
             直线方程:
             * m = Lx2 - Lx1;
             * n = Ly2 - Ly1;
             * p = Lz2 - Lz1;
             
             */
            double A, B, C, D;//平面方程参数
            double m, n, p;//直线方程参数
            double ZX_X, ZX_Y, ZX_Z;//重心坐标
            double Hhudu, Vhudu, Dis;
            //           double denrtaX = 0, denrtaY = 0, denrtaZ = 0;
            string SQL = null;
            Point_ylj Point_P = new Point_ylj();
            Point_ylj Point_jiao = new Point_ylj();
            double t = 0;
            //平面方程
            A = (Point_C.Y - Point_A.Y) * (Point_C.Z - Point_A.Z) - (Point_B.Z - Point_A.Z) * (Point_C.Y - Point_A.Y);
            B = (Point_C.X - Point_A.X) * (Point_B.Z - Point_A.Z) - (Point_B.X - Point_A.X) * (Point_C.Z - Point_A.Z);
            C = (Point_B.X - Point_A.X) * (Point_C.Y - Point_A.Y) - (Point_C.X - Point_A.X) * (Point_B.Y - Point_A.Y);
            D = -A * Point_A.X - B * Point_A.Y - C * Point_A.Z;
            //三个点重心坐标
            ZX_X = Point_A.X + Point_B.X + Point_C.X;
            ZX_Y = Point_A.Y + Point_B.Y + Point_C.Y;
            ZX_Z = Point_A.Z + Point_B.Z + Point_C.Z;

            Hhudu = ToolCase.HARadom;
            Vhudu = ToolCase.VARadom;
            Dis = ToolCase.DistanceRadom;
            //坐标
            Point_P = ToolCase.CalculationOfCoordinatePoints(StationPoint, Dis, Hhudu, Vhudu);
            //已知两点建直线方程
            m = Point_P.X - StationPoint.X;
            n = Point_P.Y - StationPoint.Y;
            p = Point_P.Z - StationPoint.Z;
            //直线与平面的焦点
            if (A * m + B * n + C * p == 0)  //判断直线是否与平面平行   
            {
                myMessageBox my = new myMessageBox();
                my.show("直线与平面平行,无法确定交点");
            
                //MessageBox.Show("直线与平面平行,无法确定交点");
            }
            else
            {
                t = -(StationPoint.X * A + StationPoint.Y * B + StationPoint.Z * C + D) / (A * m + B * n + C * p);
                Point_jiao.X = StationPoint.X + m * t;
                Point_jiao.Y = StationPoint.Y + n * t;
                Point_jiao.Z = StationPoint.Z + p * t;
            }
            LBHA.Content = ToolCase.huduTojiaodu(Hhudu);
            LbVA.Content = ToolCase.huduTojiaodu(Vhudu);
            //显示坐标信息
            //数据显示
            PD.N = Point_jiao.X.ToString("f3");
            PD.E = Point_jiao.Y.ToString("f03");
            PD.Z = (10.87).ToString("f03");
            PD.HA = ToolCase.huduTojiaodu(Hhudu);
            PD.VA = ToolCase.huduTojiaodu(Vhudu);
            PD.HD = (Dis * Math.Cos(Vhudu)).ToString("f03");
            PD.VD = (Dis * Math.Sin(Vhudu)).ToString("f03");
            PD.SD = Dis.ToString("f03");

            Point_N.DataContext = PD;
            Point_E.DataContext = PD;
            Point_Z.DataContext = PD;
            Point_HA.DataContext = PD;
            Point_VA.DataContext = PD;
            Point_HD.DataContext = PD;
            Point_VD.DataContext = PD;
            Point_SD.DataContext = PD;
            //画图
            int caseSwitch = -1;
            caseSwitch = CBProj.SelectedIndex;
            switch (caseSwitch)
            {
                case 1:
                    //NE投影Z=0
                    Draw_ylj(Point_jiao.X, Point_jiao.Y, ZX_X, ZX_Y);
                    break;
                case 2:
                    //NZ投影Y=0
                    Draw_ylj(Point_jiao.X, Point_jiao.Z, ZX_X, ZX_Z);
                    break;
                default:
                    //EZ投影X=0
                    Draw_ylj(Point_jiao.Y, Point_jiao.Z, ZX_Y, ZX_Z);
                    break;
            }
            //获取的点加入数据库
            SQL = "INSERT INTO NEZCoord (PName,PCode,N,E,Z) values ('" + TbPname.Text + "','" + CBcode.SelectionBoxItem.ToString() + "','" + Point_jiao.X.ToString("f03") + "','" + Point_jiao.Y.ToString("f03") + "','" + Point_jiao.Z.ToString("f03") + "')";
            //  MessageBox.Show(SQL);
            DBClass.Manipulation_CMD(SQL);
            TbPname.Text = ToolCase.PointNumberAdd1(TbPname.Text);
        }
        private void BTSave_Click(object sender, RoutedEventArgs e)
        {
            string SQL = null;
            double Dis_YX = 0;
            double Vhudu = 0;//核实
            arfa = (Hhudu_B - Hhudu_A) / 2;
            if (Distance > 0 && arfa > 0)
            {
                Point_ylj Point_Center = new Point_ylj();
                //圆心距离
                Dis_YX = Distance * (1 / (1 - Math.Tan(arfa)));
                //圆心方位角
                Hhudu_YX = Hhudu_A + arfa;

                //圆心坐标
                Point_Center = ToolCase.CalculationOfCoordinatePoints(StationPoint, Dis_YX, Hhudu_YX, 0);
                //画图
                Draw_ylj(Point_Center.X, Point_Center.Y, StationPoint.X, StationPoint.Y);
                //显示数据

                //数据显示
                PD.N = Point_Center.X.ToString("f3");
                PD.E = Point_Center.Y.ToString("f03");
                PD.Z = (10.87).ToString("f03");
                PD.HA = ToolCase.huduTojiaodu(Hhudu_YX);
                PD.VA = ToolCase.huduTojiaodu(Vhudu);
                PD.HD = (Dis_YX * Math.Cos(Vhudu)).ToString("f03");
                PD.VD = (Dis_YX * Math.Sin(Vhudu)).ToString("f03");
                PD.SD = Dis_YX.ToString("f03");

                Point_N.DataContext = PD;
                Point_E.DataContext = PD;
                Point_Z.DataContext = PD;
                Point_HA.DataContext = PD;
                Point_VA.DataContext = PD;
                Point_HD.DataContext = PD;
                Point_VD.DataContext = PD;
                Point_SD.DataContext = PD;
                //添加数据库
                SQL = "INSERT INTO NEZCoord (PName,PCode,N,E,Z) values ('" + TbPname.Text + "','" + CBcode.SelectionBoxItem.ToString() + "','" + Point_Center.X.ToString("f03") + "','" + Point_Center.Y.ToString("f03") + "','" + Point_Center.Z.ToString("f03") + "')";
                //  MessageBox.Show(SQL);
                DBClass.Manipulation_CMD(SQL);
                TbPname.Text = ToolCase.PointNumberAdd1(TbPname.Text);
            }
            else
            {
                myMessageBox my = new myMessageBox();
                my.show("没有测角或者测距");
              
               // MessageBox.Show("没有测角或者测距");
            }
        }
 public static double IIPointFW(Point_ylj FirstP, Point_ylj SeconP)
 {
     //先求出AB的象限角:
     //θ=arctan((Y2-Y1)/(X2-X1))
     /*再根据条件将象限角θ转换为方位角α:
     当X1-X2>0 时, Y1-Y2>0,α=θ;
     当X1-X2<0时 , Y1-Y2>0,α=θ+180° 
     当X1-X2<0 时, Y1-Y2<0,α=θ+180°
     当X1-X2>0 时, Y1-Y2<0,α=θ+360°*/
     double xita = 0;
     double FW = 0;
     xita = Math.Atan((SeconP.Y - FirstP.Y) / (SeconP.X - FirstP.X));
     if ((FirstP.X - SeconP.X > 0) && (FirstP.Y - SeconP.Y > 0))
     {
         FW = xita;
     }
     if ((FirstP.X - SeconP.X < 0))
     {
         FW = xita + Math.PI;
     }
     if ((FirstP.X - SeconP.X > 0) && (FirstP.Y - SeconP.Y < 0))
     {
         FW = xita + Math.PI * 2.0;
     }
     return FW;
 }
 public static double IIPointVD(Point_ylj FirstP, Point_ylj SeconP)
 {
     double HD;
     HD = Math.Abs(FirstP.Z - SeconP.Z);
     return HD;
 }
 public static double IIPointHD(Point_ylj FirstP, Point_ylj SeconP)
 {
     double HD;
     HD = Math.Sqrt((FirstP.X - SeconP.X) * (FirstP.X - SeconP.X) + (FirstP.Y - SeconP.Y) * (FirstP.Y - SeconP.Y));
     return HD;
 }
 //求两个点的,斜距,平距及垂直距离
 public static double IIPointSD(Point_ylj FirstP, Point_ylj SeconP)
 {
     double SD;
     SD = Math.Sqrt((FirstP.X - SeconP.X) * (FirstP.X - SeconP.X) + (FirstP.Y - SeconP.Y) * (FirstP.Y - SeconP.Y) + (FirstP.Z - SeconP.Z) * (FirstP.Z - SeconP.Z));
     return SD;
 }
 //一直测站,距离,水平角,高度角计算坐标点方法
 public static Point_ylj CalculationOfCoordinatePoints(Point_ylj StationPoint, double Dis, double Hhudu, double Vhudu)
 {
     double denrtaX = 0, denrtaY = 0, denrtaZ = 0;
     Point_ylj Point_P = new Point_ylj();
     denrtaX = (Dis * Math.Cos(Vhudu)) * Math.Cos(Hhudu);
     denrtaY = (Dis * Math.Cos(Vhudu)) * Math.Sin(Hhudu);
     denrtaZ = Dis * Math.Tan(Vhudu);
     //坐标
     Point_P.X = StationPoint.X + denrtaX;
     Point_P.Y = StationPoint.Y + denrtaY;
     Point_P.Z = StationPoint.Z + denrtaZ;
     return Point_P;
 }