我有3D线的阵列
-链接到图像-
https://i.ibb.co/syWB687/3D-lines.png
我想要的是包含连接线的线索引的组。
到目前为止,我得到的是以下输出:
所以这表明(第1行连接第2行,第2行连接到第1行,依此类推)
我的代码:
public void ArrangeLines()
{
Lines[i] = new Line3D(startpoint[i], endpoint[i],i); // array of lines
for (int i = 1; i < Lines.Length; i++)
{
System.Diagnostics.Debug.WriteLine("Lines indesx: {0} StartPoint X: {1}
Y: {2} Z: {3} EndPoint X: {4} Y: {5} Z: {6} ",
Lines[i].Index,
Lines[i].StartPoint.X,
Lines[i].StartPoint.Y,
Lines[i].StartPoint.Z,
Lines[i].EndPoint.X,
Lines[i].EndPoint.Y,
Lines[i].EndPoint.Z);
}
int group = 1;
for (int i = 1; i < Lines.Length; i++)
{
Point3D start1 = Lines[i].StartPoint;
Point3D end1 = Lines[i].EndPoint;
for (int ii = 1; ii < Lines.Length ; ii++)
{
Point3D start2 = Lines[ii].StartPoint;
Point3D end2 = Lines[ii].EndPoint;
if (start1.X == start2.X &&
start1.Y == start2.Y &&
start1.Z == start2.Z && i !=ii ||
start1.X == end2.X &&
start1.Y == end2.Y &&
start1.Z == end2.Z && i !=ii ||
end1.X == start2.X &&
end1.Y == start2.Y &&
end1.Z == start2.Z && i !=ii ||
end1.X == end2.X &&
end1.Y == end2.Y &&
end1.Z == end2.Z && i !=ii)
{
List<string> cLines = new List<string>();
cLines.Add(Lines[i].Index.ToString());
cLines.Add(Lines[ii].Index.ToString());
LineGrouped.Add(group.ToString(),cLines);
++group;
}
}
}
string[,] arry = new string[LineGrouped.Count,2];
for (int i = 0; i < LineGrouped.Count; i++)
{
var item = LineGrouped.ElementAt(i);
var itemKey = item.Key;
List<string> itemValue = item.Value;
string list = string.Join(",",itemValue.ToArray());
System.Diagnostics.Debug.WriteLine(
"key:{0} Value{1}",item.Key.ToString(),list);
arry[i,0] = itemValue[0];
arry[i,1] = itemValue[1];
}
}
我的自定义班级:
public class Point3D
{
public double X;
public double Y;
public double Z;
public Point3D(double x, double y, double z)
{
X = x;
Y = y;
Z = z;
}
public static bool operator == (Point3D point1, Point3D point2)
{
if (point1.X == point2.X && point1.Y == point2.Y && point1.Z == point2.Z)
{
return true;
}
else
{
return false;
}
}
public override int GetHashCode()
{
return (int)X * (int)Y * (int)Z ;
}
public static bool operator !=(Point3D point1, Point3D point2)
{
return !(point1==point2);
}
public override bool Equals(object obj)
{
Point3D p = obj as Point3D;
if ((object)p == null)
{
return false;
}
return base.Equals(obj);
}
}
public class Line3D
{
public Point3D StartPoint;
public Point3D EndPoint;
public int Index;
public Line3D(Point3D startpoint, Point3D endpoint, int index)
{
this.EndPoint = endpoint;
this.StartPoint = startpoint;
this.Index = index;
}
}
public class ConnectedLine
{
public Line3D Line1;
public Line3D Line2;
public Point3D StartPoint;
public Point3D EndPoint;
public ConnectedLine(Line3D line1,Line3D line2)
{
if (line1.StartPoint==line2.StartPoint)
{
this.StartPoint = line1.EndPoint;
this.EndPoint = line2.EndPoint;
this.Line1 = line1;
this.Line2 = line2;
}
else if (line1.EndPoint==line2.StartPoint)
{
this.StartPoint = line1.StartPoint;
this.EndPoint = line2.EndPoint;
this.Line1 = line1;
this.Line2 = line2;
}
else if (line1.StartPoint==line2.EndPoint)
{
this.StartPoint = line1.EndPoint;
this.EndPoint = line2.StartPoint;
this.Line1 = line1;
this.Line2 = line2;
}
else if (line1.EndPoint==line2.EndPoint)
{
this.StartPoint = line1.StartPoint;
this.EndPoint = line2.StartPoint;
this.Line1 = line1;
this.Line2 = line2;
}
}
}
答案 0 :(得分:0)
Here是您想要做的小提琴,包括交错的几何体。
算法中最大的问题是A-B之间的连接在B-A中重复。
注意:
x.GetHashCode() ^ y.GetHashCode() ^ z.GetHashCode()
Line3D
应该不知道它的索引。