/// <summary> /// Get Beam parameter Lines using to Create beam those lines is the center line of beam /// </summary> /// <param name="Collect"></param> /// <param name="H_Direction_Lines"></param> /// <param name="V_Direction_Lines"></param> /// <param name="H_Beams"></param> /// <param name="V_Beams"></param> public static List <LINE> GetBeamDrawLines(List <List <LINE> > Collect, List <LINE> H_Direction_Lines, List <LINE> V_Direction_Lines) { List <LINE> RESULT = new List <LINE>(); /// Collect Part foreach (List <LINE> co in Collect) { if (co.Count() <= 4) { LINE line1 = co[0]; LINE line2 = co[1]; XYZ p1 = null; XYZ p2 = null; double ll1 = GeometryResult.Get_Length(line1); double ll2 = GeometryResult.Get_Length(line2); if (ll1 > ll2) { if (line1.GetStartPoint().Y == line1.GetEndPoint().Y) { p1 = new XYZ(line1.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); p2 = new XYZ(line1.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); } else if (line1.GetStartPoint().X == line1.GetEndPoint().X) { p1 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetStartPoint().Y, 0); p2 = new XYZ((line1.GetStartPoint().X + line2.GetEndPoint().X) / 2, line1.GetEndPoint().Y, 0); } } else { if (line2.GetStartPoint().Y == line2.GetEndPoint().Y) { p1 = new XYZ(line2.GetStartPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); p2 = new XYZ(line2.GetEndPoint().X, (line1.GetStartPoint().Y + line2.GetEndPoint().Y) / 2, 0); } else if (line2.GetStartPoint().X == line2.GetEndPoint().X) { p1 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetStartPoint().Y, 0); p2 = new XYZ((line1.GetStartPoint().X + line1.GetEndPoint().X) / 2, line2.GetEndPoint().Y, 0); } } if (p1 != null) { RESULT.Add(new LINE(p1, p2)); } } } /// H-Beam Part List <LINE> sorted_H = H_Direction_Lines.OrderBy(e => e.GetStartPoint().Y).ToList(); List <LINE> H_Beams = new List <LINE>(); int[] is_pickup = new int[sorted_H.Count()]; for (int i = 0; i < sorted_H.Count(); i++) { if (is_pickup[i] == 1) { continue; } LINE baseLine = sorted_H[i]; for (int j = 0; j < sorted_H.Count(); j++) { if (j == i || is_pickup[j] == 1) { continue; } LINE cmpLine = sorted_H[j]; if (baseLine.GetSlope() == -cmpLine.GetSlope()) { cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()); } if (baseLine.GetStartPoint().X == cmpLine.GetStartPoint().X&& baseLine.GetEndPoint().X == cmpLine.GetEndPoint().X) { is_pickup[i] = 1; is_pickup[j] = 1; XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0); XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0); H_Beams.Add(new LINE(p1, p2)); RESULT.Add(new LINE(p1, p2)); break; } } } /// V-Beam Part List <LINE> V_Beams = new List <LINE>(); List <LINE> sorted_V = V_Direction_Lines.OrderBy(e => e.GetStartPoint().X).ToList(); is_pickup = new int[sorted_V.Count()]; for (int i = 0; i < sorted_V.Count(); i++) { if (is_pickup[i] == 1) { continue; } LINE baseLine = sorted_V[i]; for (int j = 0; j < sorted_V.Count(); j++) { if (j == i || is_pickup[j] == 1) { continue; } LINE cmpLine = sorted_V[j]; if (baseLine.GetSlope() == -cmpLine.GetSlope()) { cmpLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()); } if (baseLine.GetStartPoint().Y == cmpLine.GetStartPoint().Y&& baseLine.GetEndPoint().Y == cmpLine.GetEndPoint().Y) { is_pickup[i] = 1; is_pickup[j] = 1; XYZ p1 = new XYZ((baseLine.GetStartPoint().X + cmpLine.GetStartPoint().X) / 2, (baseLine.GetStartPoint().Y + cmpLine.GetStartPoint().Y) / 2, 0); XYZ p2 = new XYZ((baseLine.GetEndPoint().X + cmpLine.GetEndPoint().X) / 2, (baseLine.GetEndPoint().Y + cmpLine.GetEndPoint().Y) / 2, 0); V_Beams.Add(new LINE(p1, p2)); RESULT.Add(new LINE(p1, p2)); break; } } } return(RESULT); }
/// <summary> /// Classify Lines to "closed curve" or "H_dir_lines" or "V_dir_lines" or "else_dir_lines" /// </summary> /// <param name="LINES"></param> /// <param name="Collect"></param> /// <param name="H_Direction_Lines"></param> /// <param name="V_Direction_Lines"></param> /// <param name="Else_Direction_Lines"></param> public static void ClassifyLines(List <LINE> LINES, out List <List <LINE> > Collect, out List <LINE> H_Direction_Lines, out List <LINE> V_Direction_Lines, out List <LINE> Else_Direction_Lines) { Collect = new List <List <LINE> >(); int[] is_pickup = new int[LINES.Count]; for (int i = 0; i < LINES.Count; i++) { if (is_pickup[i] == 1) { continue; } LINE baseLine = LINES[i]; List <LINE> tmpData = new List <LINE>(); tmpData.Add(baseLine); int j = 0; while (j < LINES.Count) { LINE cmpLine = LINES[j]; if (is_pickup[j] == 1 || j == i) { j = j + 1; continue; } if (cmpLine.GetStartPoint().X == baseLine.GetEndPoint().X&& cmpLine.GetStartPoint().Y == baseLine.GetEndPoint().Y) { baseLine = cmpLine; tmpData.Add(baseLine); is_pickup[j] = 1; j = 0; } else if (cmpLine.GetEndPoint().X == baseLine.GetEndPoint().X&& cmpLine.GetEndPoint().Y == baseLine.GetEndPoint().Y) { baseLine = new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint()); tmpData.Add(baseLine); is_pickup[j] = 1; j = 0; } else if (tmpData[0].GetStartPoint().X == cmpLine.GetStartPoint().X&& tmpData[0].GetStartPoint().Y == cmpLine.GetStartPoint().Y) { tmpData.Insert(0, new LINE(cmpLine.GetEndPoint(), cmpLine.GetStartPoint())); is_pickup[j] = 1; j = 0; } else if (tmpData[0].GetStartPoint().X == cmpLine.GetEndPoint().X&& tmpData[0].GetStartPoint().Y == cmpLine.GetEndPoint().Y) { tmpData.Insert(0, cmpLine); is_pickup[j] = 1; j = 0; } else { j = j + 1; } } if (tmpData.Count != 1) { Collect.Add(tmpData); is_pickup[i] = 1; } } H_Direction_Lines = new List <LINE>(); V_Direction_Lines = new List <LINE>(); Else_Direction_Lines = new List <LINE>(); for (int ii = 0; ii < is_pickup.Count(); ii++) { if (is_pickup[ii] == 0) { LINE line = LINES[ii]; if (GeometryResult.Is_Horizontal(line)) { H_Direction_Lines.Add(line); } else if (GeometryResult.Is_Vertical(line)) { V_Direction_Lines.Add(line); } else { Else_Direction_Lines.Add(line); } } } }