tangxu
2023-11-12 8e7279907bb106a103d764d87a9ecf6ea200c93b
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
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using System.Runtime.Serialization;
using System.Security.Permissions;
 
namespace Hydro.Model
{
    public partial class Point
    {       
        //距离
        public double Distance(Point pt)
        {
            return Math.Sqrt((pt.X - this.X) * (pt.X - this.X)
                +
                (pt.Y - this.Y) * (pt.Y - this.Y)
                   +
                (pt.Z - this.Z) * (pt.Z - this.Z)
                );
        }
 
        public static double GetDistance(Point pt1, Point pt2)
        {
            return Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) + 
                (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y) +
                (pt1.Z - pt2.Z) * (pt1.Z - pt2.Z));
        }
        public static double GetDistance(Point2d pt1, Point2d pt2)
        {
            return Math.Sqrt((pt1.X - pt2.X) * (pt1.X - pt2.X) +
                (pt1.Y - pt2.Y) * (pt1.Y - pt2.Y)  );
        }
 
        //判断是否是0点,用于判断函数是否成功返回
        public static bool IsZeroPt(Point pt)
        {
            if (Math.Abs(pt.X) < 0.00001 && Math.Abs(pt.Y) < 0.00001 && Math.Abs(pt.Z) < 0.00001)
                return true;
            else
                return false;
        }
        public bool IsZeroPt()
        {
            if ((Math.Abs(x) < 0.00001) && (Math.Abs(y) < 0.00001) && (Math.Abs(z) < 0.00001))
                return true;
            else
                return false;
        }
 
        /// <summary>
        /// 偏置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <returns></returns>
        public Point Offset(double x, double y)
        {
            return new Point(this.x + x, this.y + y);
        }
 
        /// <summary>
        /// 偏置
        /// </summary>
        /// <param name="x"></param>
        /// <param name="y"></param>
        /// <param name="z"></param>
        /// <returns></returns>
        public Point Offset(double x, double y, double z)
        {
            return new Point(this.x + x, this.y + y, this.z + z);
        }
 
 
        //判断 是否在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;
        }
 
 
        //点到线的距离
        public static double GetDistance(Point pt1, List<Point> CurvePoints)
        {
            if (CurvePoints == null)
                return 10000;
 
            double min_dis = double.MaxValue;
            double dis = 0;
            foreach (Point pt in CurvePoints)
            {
                dis = GetDistance(pt1, pt);
                if (dis < min_dis)
                    min_dis = dis;
            }
 
            return min_dis;
        }
 
 
    }
}