duheng
2024-03-26 bb006801e4d7fc281e8c1b43ab4b7b83da044ab6
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
using System;
using System.Collections.Generic;
using System.Drawing;
 
namespace IStation.WinFrmUI.Curve
{
    /// <summary>
    /// 几何辅助类
    /// </summary>
    public class GeomHelper
    {
        //判断是否是0点,用于判断函数是否成功返回
        public static bool IsZeroPoint(Model.CurvePoint pt)
        {
            if (pt.X < 0.01 && pt.Y < 0.01)
                return true;
            else
                return false;
        }
 
 
        //判断 是否在2个数之间
        public static bool IsMiddlePt(double pt1, double pt2, double p)
        {
            if (p > pt1 && p < pt2)
                return true;
 
            if (p < pt1 && p > pt2)
                return true;
 
            return false;
        }
 
        //求2点的距离
        public static double Distance(Model.CurvePoint pt1, Model.CurvePoint pt2)
        {
            return Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) + (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y));
        }
 
        //点到线的距离
        public static double Distance(Model.CurvePoint pt1, List<Model.CurvePoint> CurvePoints)
        {
            if (CurvePoints == null)
                return 10000;
 
            double min_dis = 10000;
            double dis = 0;
            foreach (Model.CurvePoint pt in CurvePoints)
            {
                dis = Distance(pt1, pt);
                if (dis < min_dis)
                    min_dis = dis;
            }
 
            return min_dis;
        }
 
        //根据2点 产生矩形
        public static Rectangle CreateRectangle(Point corner1, Point corner2)
        {
            int x = corner1.X < corner2.X ? corner1.X : corner2.X;
            int y = corner1.Y < corner2.Y ? corner1.Y : corner2.Y;
            int width = Math.Abs(corner1.X - corner2.X);
            int height = Math.Abs(corner1.Y - corner2.Y);
            return new Rectangle(x, y, width, height);
        }
        public static RectangleF CreateRectangle(PointF corner1, PointF corner2)
        {
            float x = corner1.X < corner2.X ? corner1.X : corner2.X;
            float y = corner1.Y < corner2.Y ? corner1.Y : corner2.Y;
            float width = Math.Abs(corner1.X - corner2.X);
            float height = Math.Abs(corner1.Y - corner2.Y);
            return new RectangleF(x, y, width, height);
        }
 
        public bool IsOverlap(RectangleF r1, RectangleF r2)
        {
            if (!(r1.Right < r2.Left) && !(r1.Bottom < r2.Top))
            {
                if (!(r2.Right < r1.Left))
                {
                    return !(r2.Bottom < r1.Top);
                }
 
                return false;
            }
 
            return false;
        }
 
    }
}