public static void Rdm(object o, object pictureBox1, Point p2) {//判断店面关系————夹角和 object obj = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); if ((obj is Lineshape) && (obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '3') { double sum = 0; for (int i = 0; i < (obj as Lineshape).CoorList.Count() - 1; i++) { //求夹角和 if (Fwj((o as Basepoint), (obj as Lineshape).CoorList[i + 1]) == 999999999999999 || Fwj((o as Basepoint), (obj as Lineshape).CoorList[i]) == 999999999999999) { //点在面的边线或端点上 MessageBox.Show("点在面上", "关系显示"); return; } double jiajiao = Fwj((o as Basepoint), (obj as Lineshape).CoorList[i + 1]) - Fwj((o as Basepoint), (obj as Lineshape).CoorList[i]); if (jiajiao > Math.PI) { jiajiao = jiajiao - 2 * Math.PI; } else if (jiajiao < -Math.PI) { jiajiao = jiajiao + 2 * Math.PI; } sum += jiajiao; } double jiajiao2; jiajiao2 = Fwj((o as Basepoint), (obj as Lineshape).CoorList[(obj as Lineshape).CoorList.Count() - 1]) - Fwj((o as Basepoint), (obj as Lineshape).CoorList[0]); if (jiajiao2 > Math.PI) { jiajiao2 = jiajiao2 - 2 * Math.PI; } else if (jiajiao2 < -Math.PI) { jiajiao2 = jiajiao2 + 2 * Math.PI; } sum -= jiajiao2; if (Math.Abs(sum) <= 2 * Math.PI + 0.001 && Math.Abs(sum) >= 2 * Math.PI - 0.001) { MessageBox.Show("点在面内" + (Math.Abs(sum) * 180 / 3.1415926535).ToString(), "关系显示"); } else if (Math.Abs(sum) <= 0.001) { MessageBox.Show("点在面外" + (Math.Abs(sum) * 180 / 3.1415926535).ToString(), "关系显示"); } } else { MessageBox.Show("请先选择一点再选择一直线面", "提示"); } }
public static void Rdx(object o, object pictureBox1, Point p2) {//点与线关系判断 object obj = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); if ((obj is Lineshape) && (obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '1') { List <float> temp = new List <float>(); for (int i = 0; i < (obj as Lineshape).CoorList.Count() - 1; i++) { if (((o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i + 1].Map_Y) || ((o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i].Map_Y) || ((o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i].Map_Y) || ((o as Basepoint).Map_X <= (obj as Lineshape).CoorList[i].Map_X && (o as Basepoint).Map_X >= (obj as Lineshape).CoorList[i + 1].Map_X && (o as Basepoint).Map_Y <= (obj as Lineshape).CoorList[i + 1].Map_Y && (o as Basepoint).Map_Y >= (obj as Lineshape).CoorList[i].Map_Y)) {//是否在最小外接矩形内 temp.Add(DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i].Map_X, (obj as Lineshape).CoorList[i].Map_Y, (obj as Lineshape).CoorList[i + 1].Map_X, (obj as Lineshape).CoorList[i + 1].Map_Y)); } else {//求最短距离 temp.Add(Math.Min(DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i].Map_X, (obj as Lineshape).CoorList[i].Map_Y), DouglasPeuker.Distance((o as Basepoint).Map_X, (o as Basepoint).Map_Y, (obj as Lineshape).CoorList[i + 1].Map_X, (obj as Lineshape).CoorList[i + 1].Map_Y))); } } if (temp.ToArray().Min() == 0) { MessageBox.Show("在直线上", "关系显示:"); } else { MessageBox.Show("相离,二者间的最小距离为:" + temp.ToArray().Min(), "关系显示:"); } } else {//不是所要的目标 MessageBox.Show("请先选择一个实体点或注记点,然后选择一条直线段", "提示"); } }
private void pictureBox1_Click(object sender, EventArgs e) { try { //距离量测 if (bool_cul == true) { if (bool_dis == true) { p = pictureBox1.PointToClient(MousePosition); bool_dis = false; } else { Point p2 = pictureBox1.PointToClient(MousePosition); object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height); if (obj == null) { float d = DouglasPeuker.Distance(p2.X, p2.Y, p.X, p.Y); MessageBox.Show("未选中目标,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else { if (obj is Realpoint) { Point temp_p; temp_p = Funcs.CoorTransform((obj as Realpoint).Map_X, (obj as Realpoint).Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y); MessageBox.Show("选中实体点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else if (obj is Notepoint) { Point temp_p; temp_p = Funcs.CoorTransform((obj as Notepoint).Map_X, (obj as Notepoint).Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p.X, temp_p.Y); MessageBox.Show("选中注记点,鼠标两点地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else if (obj is Lineshape) { if ((obj as Lineshape).ID[0] == 'l' && (obj as Lineshape).ID[1] == '1' && (obj as Lineshape).CoorList.Count == 2) { if ((p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[0].Map_Y && p.Y >= (obj as Lineshape).CoorList[1].Map_Y) || (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y) || (p.X >= (obj as Lineshape).CoorList[0].Map_X && p.X <= (obj as Lineshape).CoorList[1].Map_X && p.Y >= (obj as Lineshape).CoorList[1].Map_Y && p.Y <= (obj as Lineshape).CoorList[0].Map_Y) || (p.X <= (obj as Lineshape).CoorList[0].Map_X && p.X >= (obj as Lineshape).CoorList[1].Map_X && p.Y <= (obj as Lineshape).CoorList[1].Map_Y && p.Y >= (obj as Lineshape).CoorList[0].Map_Y)) { Point temp_p1, temp_p2; temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height); temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height); float d = DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y, temp_p2.X, temp_p2.Y); MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } else { Point temp_p1, temp_p2; temp_p1 = Funcs.CoorTransform((obj as Lineshape).CoorList[0].Map_X, (obj as Lineshape).CoorList[0].Map_Y, pictureBox1.Width, pictureBox1.Height); temp_p2 = Funcs.CoorTransform((obj as Lineshape).CoorList[1].Map_X, (obj as Lineshape).CoorList[1].Map_Y, pictureBox1.Width, pictureBox1.Height); float d = Math.Min(DouglasPeuker.Distance(p.X, p.Y, temp_p1.X, temp_p1.Y), DouglasPeuker.Distance(p.X, p.Y, temp_p2.X, temp_p2.Y)); MessageBox.Show("选中直线,点到地理距离为:" + (d / MyGlo.scale).ToString("F4"), "距离显示:"); NoActive(); } } else { MessageBox.Show("暂不支持曲线/面和多点线/面,请选择两点直线段,如果想求点到多段线的最小距离可以使用点线关系工具", "提示"); NoActive(); } } } } } //点点关系,写的看不下去,可使用basepoint简化 if (bool_dd == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdd(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择两点"); NoActive(); } } //点线关系 if (bool_dx == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdx(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择一点和一条直线"); NoActive(); } } //点面关系 if (bool_dm == true) { Point p2 = pictureBox1.PointToClient(MousePosition); if (o == null) { o = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); } else if (o is Realpoint || o is Notepoint) { Funcs.Rdm(o, pictureBox1, p2); NoActive(); } else { MessageBox.Show("请选择一点和一直线面"); NoActive(); } } //删除对象 if (bool_del == true) { Point p2 = pictureBox1.PointToClient(MousePosition); object obj = Funcs.choice(p2.X, p2.Y, pictureBox1.Width, pictureBox1.Height); Funcs.Del(obj, pictureBox1); NoActive(); this.Cursor = Cursors.Default; } //符号绘制 if (fuhao1 == true) { Graphics g = pictureBox1.CreateGraphics(); Funcs.Daoxiandian(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height); NoActive(); } if (fuhao2 == true) { Graphics g = pictureBox1.CreateGraphics(); Funcs.Jiaotang(g, pictureBox1.PointToClient(MousePosition).X, pictureBox1.PointToClient(MousePosition).Y, pictureBox1.Width, pictureBox1.Height); NoActive(); } } catch { MessageBox.Show("未知错误"); } }
public static void Rdd(object o, object pictureBox1, Point p2) {//点与点关系判断 object obj = Funcs.choice(p2.X, p2.Y, (pictureBox1 as PictureBox).Width, (pictureBox1 as PictureBox).Height); if (o is Realpoint) { if (obj is Realpoint) { float d = DouglasPeuker.Distance((o as Realpoint).Map_X, (o as Realpoint).Map_Y, (obj as Realpoint).Map_X, (obj as Realpoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is Notepoint) { float d = DouglasPeuker.Distance((o as Realpoint).Map_X, (o as Realpoint).Map_Y, (obj as Notepoint).Map_X, (obj as Notepoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is null || obj is Lineshape) { MessageBox.Show("只能判断实体点和注记点的关系", "关系显示:"); } } else if (o is Notepoint) { if (obj is Realpoint) { float d = DouglasPeuker.Distance((o as Notepoint).Map_X, (o as Notepoint).Map_Y, (obj as Realpoint).Map_X, (obj as Realpoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is Notepoint) { float d = DouglasPeuker.Distance((o as Notepoint).Map_X, (o as Notepoint).Map_Y, (obj as Notepoint).Map_X, (obj as Notepoint).Map_Y); if (d == 0) { MessageBox.Show("目标重合"); } else { MessageBox.Show("相离,选中目标点的地理距离为:" + d.ToString("F4"), "关系显示:"); } } else if (obj is null) { MessageBox.Show("只能判断实体点和注记点的关系", "关系显示:"); } } }