private List <Segment2D> RoomBoundaryToSegment2D(UIDocument document, List <XYZ> boundaryVertices, string definition, double measurementUnitFactor) { List <Segment2D> segmentsList = new List <Segment2D>(); int segmentIterator = 0; for (int i = 0; i < boundaryVertices.Count - 1; i++) { XYZ currentStartVertex = boundaryVertices.ElementAt(i); XYZ currentEndVertex = boundaryVertices.ElementAt(i + 1); Vector2D newSegmentsStart = GeometryFactory.CreateVector2D(ConvertFeetToMeters(replaceCommaWithDot(currentStartVertex.X)), ConvertFeetToMeters(replaceCommaWithDot(currentStartVertex.Y)), measurementUnitFactor); Vector2D newSegmentsEnd = GeometryFactory.CreateVector2D(ConvertFeetToMeters(replaceCommaWithDot(currentEndVertex.X)), ConvertFeetToMeters(replaceCommaWithDot(currentEndVertex.Y)), measurementUnitFactor); if (newSegmentsStart.IsEqualTo(newSegmentsEnd)) { continue; } segmentsList.Add(GeometryFactory.CreateSegment2D(new Vector2D[] { newSegmentsStart, newSegmentsEnd }, definition + "_" + segmentIterator)); segmentIterator++; GeometryFactory.SetMaxMinCoordinates(newSegmentsStart); GeometryFactory.SetMaxMinCoordinates(newSegmentsEnd); } return(segmentsList); }
private List <Segment2D> CutOutDoor(Segment2D currentDoor, List <Segment2D> allWalls) { var listArray = new List <List <Segment2D> >(); var newWallList = new List <Segment2D>(); var wallsToRemove = new List <Segment2D>(); Vector2D[] doorVertices = currentDoor.GetVertices(); Vector2D doorVectorStart = doorVertices[0]; Vector2D doorVectorEnd = doorVertices[1]; Vector2D doorVector = doorVectorEnd.Difference(doorVectorStart).GetAsNormalized(); foreach (Segment2D currentWall in allWalls) { Vector2D[] wallVertices = currentWall.GetVertices(); Vector2D wallVectorStart = wallVertices[0]; Vector2D wallVectorEnd = wallVertices[1]; Vector2D wallVector = wallVectorEnd.Difference(wallVectorStart).GetAsNormalized(); if (wallVectorStart.IsEqualTo(wallVectorEnd)) { wallsToRemove.Add(currentWall); continue; } else if (GeoAdditionals.SegmentsLieOnTopOfEachOther(currentDoor, currentWall)) { double cos = wallVector.Dot(doorVector) / (wallVector.normalize() * doorVector.normalize()); if (cos < 0) { doorVectorStart = doorVertices[1]; doorVectorEnd = doorVertices[0]; } if (!wallVectorStart.IsEqualTo(doorVectorStart)) { Segment2D wallToDoor = GeometryFactory.CreateSegment2D(new Vector2D[] { wallVectorStart, doorVectorStart }, currentWall.Name); newWallList.Add(wallToDoor); } if (!doorVectorEnd.IsEqualTo(wallVectorEnd)) { Segment2D wallFromDoor = GeometryFactory.CreateSegment2D(new Vector2D[] { doorVectorEnd, wallVectorEnd }, currentWall.Name); newWallList.Add(wallFromDoor); } wallsToRemove.Add(currentWall); continue; } else { continue; } } foreach (Segment2D wallToRemove in wallsToRemove) { allWalls.Remove(wallToRemove); } allWalls.AddRange(newWallList); return(allWalls); }
public static List <Segment2D> DividePolygon2DintoSegment2D(Polygon2D polygon) { List <Segment2D> segments = new List <Segment2D>(); int segmentIterator = 0; for (int i = 0; i < polygon.GetVertices().Length - 1; i++) { Vector2D startPoint = polygon.GetVertices().ElementAt(i); Vector2D endPoint = polygon.GetVertices().ElementAt(i + 1); if (startPoint.IsEqualTo(endPoint)) { continue; } segments.Add(GeometryFactory.CreateSegment2D(new Vector2D[] { startPoint, endPoint }, polygon.Name + "_" + segmentIterator.ToString())); segmentIterator++; } return(segments); }
public List <Geometry2D> CreateDoorSegments(UIDocument currentDocument, List <FamilyInstance> doors) { List <Geometry2D> convertedDoors = new List <Geometry2D>(); foreach (FamilyInstance currentDoor in doors) { string doorName = currentDoor.Name; Wall pacedWall = currentDoor.Host as Wall; Curve pacedWallCurve = (pacedWall.Location as LocationCurve).Curve; Vector2D wallStartPoint = GeometryFactory.CreateVector2D(ConvertFeetToMeters(pacedWallCurve.GetEndPoint(0).X), ConvertFeetToMeters(pacedWallCurve.GetEndPoint(0).Y), MEASUREMENTUNITFACTOR); Vector2D wallEndPoint = GeometryFactory.CreateVector2D(ConvertFeetToMeters(pacedWallCurve.GetEndPoint(1).X), ConvertFeetToMeters(pacedWallCurve.GetEndPoint(1).Y), MEASUREMENTUNITFACTOR); Vector2D wallDirection = wallEndPoint.Difference(wallStartPoint).GetAsNormalized(); double doorThickness = ConvertFeetToMeters(pacedWall.WallType.Width); double doorWidth = ConvertFeetToMeters(currentDoor.Symbol.get_Parameter(BuiltInParameter.DOOR_WIDTH).AsDouble()); if (doorWidth == 0) { string familyName = currentDoor.Symbol.FamilyName; if (familyName.Contains(DOUBLE_SWING_CONTENT1) || familyName.Contains(DOUBLE_SWING_CONTENT2) || familyName.Contains(DOUBLE_SWING_CONTENT3)) { doorWidth = DEFAULT_DOUBLE_DOOR_WIDTH; } else { doorWidth = DEFAULT_SINGLE_DOOR_WIDTH; } } LocationPoint doorLocationPoint = currentDoor.Location as LocationPoint; XYZ doorLocation = doorLocationPoint.Point; Vector2D doorLocation2D = GeometryFactory.CreateVector2D(ConvertFeetToMeters(doorLocation.X), ConvertFeetToMeters(doorLocation.Y), MEASUREMENTUNITFACTOR); Vector2D doorMidSegmentStart = doorLocation2D.Add(wallDirection.Multiply(doorWidth / 2)); Vector2D doorMidSegmentEnd = doorLocation2D.Add(wallDirection.Negate().Multiply(doorWidth / 2)); Vector2D doorPacingDirection = wallDirection.Rotate(Math.PI / 2); Vector2D firstWallConnectingStart = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2)); Vector2D firstWallConnectingEnd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); Segment2D firstWallConnectingSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { firstWallConnectingStart, firstWallConnectingEnd }, doorName); convertedDoors.Add(firstWallConnectingSegment); Vector2D secondWallConnectingStart = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2)); Vector2D secondWallConnectingEnd = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); Segment2D secondWallConnectingSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { secondWallConnectingStart, secondWallConnectingEnd }, doorName); convertedDoors.Add(secondWallConnectingSegment); Vector2D leftDoorSegmentStart = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2)); Vector2D leftDoorSegmentEnd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2)); Segment2D leftDoorSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { leftDoorSegmentStart, leftDoorSegmentEnd }, doorName); Vector2D rightDoorSegmentStart = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); Vector2D rightDoorSegmentEnd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); Segment2D rightDoorSegment = GeometryFactory.CreateSegment2D(new Vector2D[] { rightDoorSegmentStart, rightDoorSegmentEnd }, doorName); if (currentDoor.FromRoom == null || currentDoor.ToRoom == null) { List <Vector2D> doorAreaPoints = new List <Vector2D>(); if (pacedWall.Flipped) { leftDoorSegment.Name = null; Vector2D pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(doorThickness / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(DEFAULT_AREA_RADIUS / 2)); doorAreaPoints.Add(pointToAdd); } else { rightDoorSegment.Name = null; Vector2D pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Multiply(doorThickness / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentStart.Add(doorPacingDirection.Negate().Multiply(DEFAULT_AREA_RADIUS / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Negate().Multiply(DEFAULT_AREA_RADIUS / 2)); doorAreaPoints.Add(pointToAdd); pointToAdd = doorMidSegmentEnd.Add(doorPacingDirection.Multiply(doorThickness / 2)); doorAreaPoints.Add(pointToAdd); } Polygon2D exitDoor = GeometryFactory.CreatePolygon2D(doorAreaPoints.ToArray(), doorName); convertedDoors.Add(exitDoor); } else { leftDoorSegment.Name = null; rightDoorSegment.Name = null; } convertedDoors.Add(leftDoorSegment); convertedDoors.Add(rightDoorSegment); } return(convertedDoors); }