cloudflight
2024-10-12 46e3091f9cdefc7e2ffbc69bcb9c39650b1c0587
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
109
110
111
112
113
114
115
116
117
118
119
120
121
122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
using Yw.WinFrmUI.Q3d;
using Yw.WinFrmUI.Q3d;
 
using Newtonsoft.Json;
using System;
using System.Collections.Generic;
using System.Drawing;
using System.IO;
using System.Linq;
using System.Numerics;
using System.Text;
using System.Text.RegularExpressions;
using System.Threading.Tasks;
using System.Windows.Forms;
using static Yw.WinFrmUI.Q3d.ObjectEnum;
using static System.Math;
 
namespace Yw.WinFrmUI.Q3d
{
    public partial class NetworkViewModel
    {
  
      
        public void BuildRelation()
        {
            //读取坐标
            int k1 = 0;//表示管线索引
            int k2 = 0;//表示节点索引
            Nodes.Sort((a, b) => string.Compare(a.ID, b.ID));
 
            //建立点线关系链表StartNode,先将管线以Node1(节点1的ID)排序,再将Nodes按ID排序,建立两个游标k1、k2,正向一次循环,建立链表关系
            //时间复杂度 O(n)
            Links.Sort((a, b) => string.Compare(a.Node1, b.Node1));
            k2 = 0;
            k1 = 0;
            while (k1 < Links.Count)
            {
                var p = Links[k1];
                var J = Nodes[k2];
                var k0 = k2;
                while (J.ID != p.Node1 && k2 < Nodes.Count)
                {
                    k2++;
                    if (k2 < Nodes.Count) J = Nodes[k2];
                }
                if (k2 == Nodes.Count)
                {
                    k2 = k0;
                    k1++;
                    p.Visible = false;
                    continue;
                    //throw new Exception($"未找到Link[{p.ID}]的起始节点[{p.Node1}]");
                }
                p.StartNode = J;
                p.Node1 = J.ID;
                if (J.MaxDiameter < p.Diameter) J.MaxDiameter = p.Diameter;
                J.Links.Add(p);
                k1++;
            }
 
            //建立点线关系链表StartNode,先将管线以Node2(节点1的ID)排序,再将Nodes按ID排序,建立两个游标k1、k2,正向一次循环,建立链表关系
            //时间复杂度 O(n)
            Links.Sort((a, b) => string.Compare(a.Node2, b.Node2));
            k2 = 0;
            k1 = 0;
            while (k1 < Links.Count)
            {
                var p = Links[k1];
                var J = Nodes[k2];
                var k0 = k2;
                while (J.ID != p.Node2 && k2 < Nodes.Count)
                {
                    k2++;
                    if (k2 < Nodes.Count) J = Nodes[k2];
                }
                if (k2 == Nodes.Count)
                {
                    k2 = k0;
                    k1++;
                    p.Visible = false;
 
                    continue;
                    //throw new Exception($"未找到Link[{p.ID}]的终止节点[{p.Node2}]");
                }
                p.EndNode = J;
                p.Node2 = J.ID;
                if (J.MaxDiameter < p.Diameter) J.MaxDiameter = p.Diameter;
                J.Links.Add(p);
                k1++;
            }
 
          
            if (dict_dataset == null)
            {
                dict_dataset = new Dictionary<string, Dataset>();
            }
            pumps.ForEach(p =>
            {
                foreach (var kp in p.Datasets)
                {
                    if (!dict_dataset.ContainsKey(kp.Value.Name))
                    {
                        dict_dataset.Add(kp.Value.Name, kp.Value);
                    }
                }
            });
            pumps.ForEach((pump) =>
            {
                if (dict_dataset.ContainsKey(pump.HeadCurve))
                {
                    Dataset ds = dict_dataset[pump.HeadCurve];
 
                    if (!pump.Datasets.ContainsKey("流量扬程曲线"))
                    {
                        pump.Datasets.Add("流量扬程曲线", ds);
                    }
                    else
                    {
                        pump.Datasets["流量扬程曲线"] = ds;
                    }
                    ds.pump = pump;
                }
 
                if (!pump.Datasets.ContainsKey("流量扬程曲线"))
                {
                    pump.Datasets.Add("流量扬程曲线", new Dataset(pump.ID + "_Head", pump));
                }
                if (pump.Datasets["流量扬程曲线"].Data.Count <= 0)
                {
                    pump.Datasets["流量扬程曲线"].Data.Add(new PointF((float)pump.额定流量, (float)pump.额定扬程));
                }
                pump.HeadCurve = pump.Datasets["流量扬程曲线"].Name;
            });
 
            //dict_dataset.Clear();
            //valveNodes.ForEach(v => Nodes.Remove(v)); ;
            Hash_ID = new HashSet<string>();
            Nodes.ForEach(o => Hash_ID.Add(o.ID));
            Links.ForEach(o => Hash_ID.Add(o.ID));
        }
 
   
     
 
    }
 
    public class Vector3D
    {
        public double X { get; set; }
        public double Y { get; set; }
        public double Z { get; set; }
 
        public Vector3D(double x, double y, double z)
        {
            X = x;
            Y = y;
            Z = z;
        }
 
        public static double CalculateAngle(Vector3D v1, Vector3D v2)
        {
            // 计算两个向量的点积
            double dotProduct = v1.X * v2.X + v1.Y * v2.Y + v1.Z * v2.Z;
 
            // 计算两个向量的模长
            double v1Magnitude = Math.Sqrt(v1.X * v1.X + v1.Y * v1.Y + v1.Z * v1.Z);
            double v2Magnitude = Math.Sqrt(v2.X * v2.X + v2.Y * v2.Y + v2.Z * v2.Z);
 
            // 计算夹角(弧度)
            double angleInRadians = Math.Acos(dotProduct / (v1Magnitude * v2Magnitude));
 
            // 将弧度转换为度数
            //double angleInDegrees = angleInRadians * (180 / Math.PI);
 
            return angleInRadians;
        }
 
        public double Length
        {
            get
            {
                return Math.Sqrt(X * X + Y * Y + Z * Z);
            }
        }
    }
}