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 static bool IsPointInLineOrExtend(Line line, XYZ point) { if (GeomUtil.IsEqual(point, line.GetEndPoint(0)) || GeomUtil.IsEqual(point, line.GetEndPoint(1))) { return(true); } if (GeomUtil.IsSameOrOppositeDirection(GeomUtil.SubXYZ(point, line.GetEndPoint(0)), GeomUtil.SubXYZ(point, line.GetEndPoint(1)))) { return(true); } return(false); }
public static PointComparePolygonResult PointComparePolygon(UV p, List <UV> polygon) { bool check1 = IsPointInPolygon(p, polygon); for (int i = 0; i < polygon.Count; i++) { if (GeomUtil.IsEqual(p, polygon[i])) { return(PointComparePolygonResult.Node); } UV vec1 = GeomUtil.SubXYZ(p, polygon[i]); UV vec2 = null; if (i != polygon.Count - 1) { if (GeomUtil.IsEqual(p, polygon[i + 1])) { continue; } vec2 = GeomUtil.SubXYZ(p, polygon[i + 1]); } else { if (GeomUtil.IsEqual(p, polygon[0])) { continue; } vec2 = GeomUtil.SubXYZ(p, polygon[0]); } if (GeomUtil.IsOppositeDirection(vec1, vec2)) { return(PointComparePolygonResult.Boundary); } } if (check1) { return(PointComparePolygonResult.Inside); } return(PointComparePolygonResult.Outside); }
public static ViewSection CreateWallSection(Document linkedDoc, Document doc, Polygon directPolygon, ElementId id, string viewName, double offset) { Element e = linkedDoc.GetElement(id); if (!(e is Wall)) { throw new Exception("Element is not a wall!"); } Wall wall = (Wall)e; Line line = (wall.Location as LocationCurve).Curve as Line; ViewFamilyType vft = new FilteredElementCollector(doc).OfClass(typeof(ViewFamilyType)).Cast <ViewFamilyType>().FirstOrDefault <ViewFamilyType>(x => ViewFamily.Section == x.ViewFamily); XYZ p1 = line.GetEndPoint(0), p2 = line.GetEndPoint(1); List <XYZ> ps = new List <XYZ> { p1, p2 }; ps.Sort(new ZYXComparer()); p1 = ps[0]; p2 = ps[1]; BoundingBoxXYZ bb = wall.get_BoundingBox(null); double minZ = bb.Min.Z, maxZ = bb.Max.Z; double l = GeomUtil.GetLength(GeomUtil.SubXYZ(p2, p1)); double h = maxZ - minZ; double w = wall.WallType.Width; XYZ tfMin = new XYZ(-l / 2 - offset, minZ - offset, -w - offset); XYZ tfMax = new XYZ(l / 2 + offset, maxZ + offset, w + offset); XYZ wallDir = GeomUtil.UnitVector(p2 - p1); XYZ upDir = XYZ.BasisZ; XYZ viewDir = GeomUtil.CrossMatrix(wallDir, upDir); XYZ midPoint = (p1 + p2) / 2; XYZ pMidPoint = GetProjectPoint(directPolygon.Plane, midPoint); XYZ pPnt = GeomUtil.OffsetPoint(pMidPoint, viewDir, w * 10); if (GeomUtil.IsBigger(GeomUtil.GetLength(pMidPoint, directPolygon.CentralXYZPoint), GeomUtil.GetLength(pPnt, directPolygon.CentralXYZPoint))) { wallDir = -wallDir; upDir = XYZ.BasisZ; viewDir = GeomUtil.CrossMatrix(wallDir, upDir); } else { } pPnt = GeomUtil.OffsetPoint(p1, wallDir, offset); XYZ min = null, max = null; if (GeomUtil.IsBigger(GeomUtil.GetLength(GeomUtil.SubXYZ(pPnt, midPoint)), GeomUtil.GetLength(GeomUtil.SubXYZ(p1, midPoint)))) { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, -wallDir, offset), viewDir, offset); } else { min = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p1, -wallDir, offset), -viewDir, offset); max = GeomUtil.OffsetPoint(GeomUtil.OffsetPoint(p2, wallDir, offset), viewDir, offset); } min = new XYZ(min.X, min.Y, minZ - offset); max = new XYZ(max.X, max.Y, maxZ + offset); Transform tf = Transform.Identity; tf.Origin = (p1 + p2) / 2; tf.BasisX = wallDir; tf.BasisY = XYZ.BasisZ; tf.BasisZ = GeomUtil.CrossMatrix(wallDir, upDir); BoundingBoxXYZ sectionBox = new BoundingBoxXYZ() { Transform = tf, Min = tfMin, Max = tfMax }; ViewSection vs = ViewSection.CreateSection(doc, vft.Id, sectionBox); tf = vs.get_BoundingBox(null).Transform.Inverse; max = tf.OfPoint(max); min = tf.OfPoint(min); double maxx = 0, maxy = 0, maxz = 0, minx = 0, miny = 0, minz = 0; if (max.Z > min.Z) { maxz = max.Z; minz = min.Z; } else { maxz = min.Z; minz = max.Z; } if (Math.Round(max.X, 4) == Math.Round(min.X, 4)) { maxx = max.X; minx = minz; } else if (max.X > min.X) { maxx = max.X; minx = min.X; } else { maxx = min.X; minx = max.X; } if (Math.Round(max.Y, 4) == Math.Round(min.Y, 4)) { maxy = max.Y; miny = minz; } else if (max.Y > min.Y) { maxy = max.Y; miny = min.Y; } else { maxy = min.Y; miny = max.Y; } BoundingBoxXYZ sectionView = new BoundingBoxXYZ(); sectionView.Max = new XYZ(maxx, maxy, maxz); sectionView.Min = new XYZ(minx, miny, minz); vs.get_Parameter(BuiltInParameter.VIEWER_VOLUME_OF_INTEREST_CROP).Set(ElementId.InvalidElementId); vs.get_Parameter(BuiltInParameter.VIEWER_BOUND_FAR_CLIPPING).Set(0); vs.CropBoxActive = true; vs.CropBoxVisible = true; doc.Regenerate(); vs.CropBox = sectionView; vs.Name = viewName; return(vs); }
public static XYZ GetDirection(Curve c) { return(GeomUtil.UnitVector(GeomUtil.SubXYZ(c.GetEndPoint(1), c.GetEndPoint(0)))); }