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);
|
}
|
}
|
}
|
}
|