public static XYZ GetProjectPoint(Curve line, XYZ point) { if (IsPointInLineOrExtend(CheckGeometry.ConvertLine(line), point)) { return(point); } XYZ vecL = GeomUtil.SubXYZ(line.GetEndPoint(1), line.GetEndPoint(0)); XYZ vecP = GeomUtil.SubXYZ(point, line.GetEndPoint(0)); Plane p = Plane.CreateByOriginAndBasis(line.GetEndPoint(0), GeomUtil.UnitVector(vecL), GeomUtil.UnitVector(GeomUtil.CrossMatrix(vecL, vecP))); return(GetProjectPoint(p, point)); }
public void CreateModelPolygon() { Document doc = Wall.Document; CheckGeometry.CreateModelLinePolygon(doc, CentralHorizontalPolygon); CheckGeometry.CreateModelLinePolygon(doc, CentralVerticalLengthPolygon); CheckGeometry.CreateModelLinePolygon(doc, CentralVerticalWidthPolygon); CheckGeometry.CreateModelLinePolygon(doc, TopPolygon); CheckGeometry.CreateModelLinePolygon(doc, BottomPolygon); CheckGeometry.CreateModelLinePolygon(doc, FirstLengthPolygon); CheckGeometry.CreateModelLinePolygon(doc, SecondLengthPolygon); CheckGeometry.CreateModelLinePolygon(doc, FirstWidthPolygon); CheckGeometry.CreateModelLinePolygon(doc, SecondWidthPolygon); }
public void CreateModelPolygon() { Document doc = Column.Document; CheckGeometry.CreateModelLinePolygon(doc, CentralHorizontalPolygon); CheckGeometry.CreateModelLinePolygon(doc, CentralVerticalHeightPolygon); CheckGeometry.CreateModelLinePolygon(doc, CentralVerticalWidthPolygon); CheckGeometry.CreateModelLinePolygon(doc, TopPolygon); CheckGeometry.CreateModelLinePolygon(doc, BottomPolygon); CheckGeometry.CreateModelLinePolygon(doc, FirstHeightPolygon); CheckGeometry.CreateModelLinePolygon(doc, SecondHeightPolygon); CheckGeometry.CreateModelLinePolygon(doc, FirstWidthPolygon); CheckGeometry.CreateModelLinePolygon(doc, SecondWidthPolygon); }
int IComparer <Element> .Compare(Element x, Element y) { XYZ loc1 = null; XYZ loc2 = null; if (x is Wall) { WallGeometryInfo wgi = new WallGeometryInfo(x as Wall); loc1 = wgi.TopPolygon.CentralXYZPoint; } if (x is FamilyInstance) { ColumnGeometryInfo cgi = new ColumnGeometryInfo(x as FamilyInstance); loc1 = cgi.TopPolygon.CentralXYZPoint; } if (y is Wall) { WallGeometryInfo wgi = new WallGeometryInfo(y as Wall); loc2 = wgi.TopPolygon.CentralXYZPoint; } if (y is FamilyInstance) { ColumnGeometryInfo cgi = new ColumnGeometryInfo(y as FamilyInstance); loc2 = cgi.TopPolygon.CentralXYZPoint; } loc1 = new XYZ(loc1.X, loc1.Y, 0); loc2 = new XYZ(loc2.X, loc2.Y, 0); if (Plane != null) { loc1 = CheckGeometry.GetProjectPoint(Plane, loc1); loc2 = CheckGeometry.GetProjectPoint(Plane, loc2); } if (GeomUtil.IsEqual(loc1.X, loc2.X)) { if (GeomUtil.IsEqual(loc1.Y, loc2.Y)) { return(0); // Equal } return((loc1.Y > loc2.Y) ? 1 : -1); } return((loc1.X > loc2.X) ? 1 : -1); }
public MultiPolygon(PlanarFace f) { List <Polygon> pls = new List <Polygon>(); EdgeArrayArray eAA = f.EdgeLoops; foreach (EdgeArray eA in eAA) { List <Curve> cs = new List <Curve>(); foreach (Edge e in eA) { List <XYZ> points = e.Tessellate() as List <XYZ>; cs.Add(Line.CreateBound(points[0], points[1])); } pls.Add(new Polygon(cs)); if (eAA.Size == 1) { SurfacePolygon = pls[0]; OpeningPolygons = new List <Polygon>(); goto GetParameters; } } for (int i = 0; i < pls.Count; i++) { Plane plane = pls[i].Plane; for (int j = i + 1; j < pls.Count; j++) { Polygon tempPoly = CheckGeometry.GetProjectPolygon(plane, pls[j]); PolygonComparePolygonResult res = new PolygonComparePolygonResult(pls[i], tempPoly); if (res.IntersectType == PolygonComparePolygonIntersectType.AreaOverlap) { if (res.ListPolygon[0] == pls[i]) { SurfacePolygon = pls[j]; goto FinishLoops; } if (res.ListPolygon[0] == pls[j]) { SurfacePolygon = pls[i]; goto FinishLoops; } else { throw new Exception("Face must contain polygons inside polygon!"); } } } } FinishLoops: if (SurfacePolygon == null) { throw new Exception("Error when retrieve surface polygon!"); } Plane = SurfacePolygon.Plane; OpeningPolygons = new List <Polygon>(); foreach (Polygon pl in pls) { if (pl == SurfacePolygon) { continue; } Polygon tempPoly = CheckGeometry.GetProjectPolygon(Plane, pl); OpeningPolygons.Add(tempPoly); } GetParameters: GetParameters(); }
public void GetPolygonsDefineFace() { Document doc = Wall.Document; Curve c = DrivingCurve; XYZ vecX = CheckGeometry.GetDirection(c); XYZ vecZ = XYZ.BasisZ; XYZ vecY = vecZ.CrossProduct(vecX); List <XYZ> ps = new List <XYZ> { c.GetEndPoint(0), c.GetEndPoint(1) }; List <XYZ> cenLengthPoints = new List <XYZ> { GeomUtil.OffsetPoint(ps[0], vecZ, 0), GeomUtil.OffsetPoint(ps[1], vecZ, 0), GeomUtil.OffsetPoint(ps[0], vecZ, Height), GeomUtil.OffsetPoint(ps[1], vecZ, Height) }; cenLengthPoints.Sort(new ZYXComparer()); XYZ temp = cenLengthPoints[2]; cenLengthPoints[2] = cenLengthPoints[3]; cenLengthPoints[3] = temp; XYZ midPoint = (ps[0] + ps[1]) / 2; ps = new List <XYZ> { GeomUtil.OffsetPoint(midPoint, vecY, -Width / 2), GeomUtil.OffsetPoint(midPoint, vecY, Width / 2) }; List <XYZ> cenWidthPoints = new List <XYZ> { GeomUtil.OffsetPoint(ps[0], vecZ, 0), GeomUtil.OffsetPoint(ps[1], vecZ, 0), GeomUtil.OffsetPoint(ps[0], vecZ, Height), GeomUtil.OffsetPoint(ps[1], vecZ, Height) }; cenWidthPoints.Sort(new ZYXComparer()); temp = cenWidthPoints[2]; cenWidthPoints[2] = cenWidthPoints[3]; cenWidthPoints[3] = temp; ps = new List <XYZ> { (cenLengthPoints[0] + cenLengthPoints[3]) / 2, (cenLengthPoints[1] + cenLengthPoints[2]) / 2 }; List <XYZ> cenHozPoints = new List <XYZ> { GeomUtil.OffsetPoint(ps[0], vecY, -Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, -Width / 2), GeomUtil.OffsetPoint(ps[0], vecY, Width / 2), GeomUtil.OffsetPoint(ps[1], vecY, Width / 2) }; cenHozPoints.Sort(new ZYXComparer()); temp = cenHozPoints[2]; cenHozPoints[2] = cenHozPoints[3]; cenHozPoints[3] = temp; CentralVerticalLengthPolygon = new Polygon(cenLengthPoints); CentralVerticalWidthPolygon = new Polygon(cenWidthPoints); CentralHorizontalPolygon = new Polygon(cenHozPoints); vecX = GeomUtil.UnitVector(GeomUtil.IsBigger(vecX, -vecX) ? vecX : -vecX); vecY = GeomUtil.UnitVector(GeomUtil.IsBigger(vecY, -vecY) ? vecY : -vecY); vecZ = GeomUtil.UnitVector(GeomUtil.IsBigger(vecZ, -vecZ) ? vecZ : -vecZ); TopPolygon = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, Height / 2); BottomPolygon = GeomUtil.OffsetPolygon(CentralHorizontalPolygon, vecZ, -Height / 2); FirstLengthPolygon = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, -Width / 2); SecondLengthPolygon = GeomUtil.OffsetPolygon(CentralVerticalLengthPolygon, vecY, Width / 2); FirstWidthPolygon = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecX, -Length / 2); SecondWidthPolygon = GeomUtil.OffsetPolygon(CentralVerticalWidthPolygon, vecX, Length / 2); this.VecX = vecX; this.VecY = vecY; this.VecZ = vecZ; }
public void GetBoundingBox() { BoundingBoxXYZ bb = Beam.get_BoundingBox(null); CheckGeometry.CreateModelLine(Beam.Document, null, Line.CreateBound(bb.Max, bb.Min)); }
public static List <Curve> GetCurvesCut(Polygon mainPolygon, Polygon secPolygon) { PolygonComparePolygonResult res = new PolygonComparePolygonResult(mainPolygon, secPolygon); if (res.ListPolygon[0] != secPolygon) { throw new Exception("Secondary Polygon must inside Main Polygon!"); } bool isInside = true; List <Curve> cs = new List <Curve>(); foreach (Curve c in secPolygon.ListCurve) { LineComparePolygonResult lpRes = new LineComparePolygonResult(mainPolygon, CheckGeometry.ConvertLine(c)); if (lpRes.Type == LineComparePolygonType.Inside) { foreach (Curve c1 in mainPolygon.ListCurve) { LineCompareLineResult llres = new LineCompareLineResult(c, c1); if (llres.Type == LineCompareLineType.SameDirectionLineOverlap) { goto Here; } } cs.Add(c); } Here : continue; } isInside = false; foreach (Curve c in mainPolygon.ListCurve) { LineComparePolygonResult lpRes = new LineComparePolygonResult(secPolygon, CheckGeometry.ConvertLine(c)); if (lpRes.Type == LineComparePolygonType.Outside) { cs.Add(c); continue; } foreach (Curve c1 in secPolygon.ListCurve) { LineCompareLineResult llRes = new LineCompareLineResult(c, c1); if (llRes.Type == LineCompareLineType.SameDirectionLineOverlap) { isInside = false; if (llRes.ListOuterLine.Count == 0) { break; } foreach (Line l in llRes.ListOuterLine) { LineComparePolygonResult lpRes1 = new LineComparePolygonResult(secPolygon, l); if (lpRes1.Type != LineComparePolygonType.Inside) { cs.Add(l); } } break; } } } if (isInside) { throw new Exception("Secondary Polygon must be tangential with Main Polygon!"); } return(cs); }