Skip to content

Commit

Permalink
add DivideByWidthAndLength
Browse files Browse the repository at this point in the history
  • Loading branch information
chuongmep committed Aug 23, 2023
1 parent 89e9b67 commit 6cd016e
Show file tree
Hide file tree
Showing 4 changed files with 508 additions and 2 deletions.
4 changes: 2 additions & 2 deletions .nuke/build.schema.json
Original file line number Diff line number Diff line change
@@ -1,7 +1,7 @@
{
"$schema": "http://json-schema.org/draft-04/schema#",
"title": "Build Schema",
"$ref": "#/definitions/build",
"title": "Build Schema",
"definitions": {
"build": {
"type": "object",
Expand Down Expand Up @@ -106,4 +106,4 @@
}
}
}
}
}
34 changes: 34 additions & 0 deletions OpenMEPSandbox/Geometry/Abstract/BoundingBox.cs
Original file line number Diff line number Diff line change
Expand Up @@ -288,6 +288,40 @@ public static double Area(Autodesk.DesignScript.Geometry.BoundingBox boundingBox

return boundingBoxes;
}

/// <summary>
/// Divides a bounding box into smaller bounding boxes by width and length.
/// </summary>
/// <param name="boundingBox">The original bounding box to be divided.</param>
/// <param name="width">The number of divisions along the width.</param>
/// <param name="length">The number of divisions along the length.</param>
/// <returns name="boundingBox">A list of smaller bounding boxes resulting from the division.</returns>
/// /// <example>
/// ![](../OpenMEPPage/geometry/dyn/pic/BoundingBox.DivideByWidthAndLength.gif)
/// [BoundingBox.DivideByWidthAndLength.dyn](../OpenMEPPage/geometry/dyn/BoundingBox.DivideByWidthAndLength.dyn)
///</example>
public static List<Autodesk.DesignScript.Geometry.BoundingBox> DivideByWidthAndLength(
Autodesk.DesignScript.Geometry.BoundingBox boundingBox, double width, double length)
{
var minPoint = boundingBox.MinPoint;
var maxPoint = boundingBox.MaxPoint;
var x = (maxPoint.X - minPoint.X) / width;
var y = (maxPoint.Y - minPoint.Y) / length;
List<Autodesk.DesignScript.Geometry.BoundingBox> boundingBoxes =
new List<Autodesk.DesignScript.Geometry.BoundingBox>();
for (int i = 0; i < width; i++)
{
for (int j = 0; j < length; j++)
{
var min = Autodesk.DesignScript.Geometry.Point.ByCoordinates(minPoint.X + i * x, minPoint.Y + j * y,
minPoint.Z);
var max = Autodesk.DesignScript.Geometry.Point.ByCoordinates(minPoint.X + (i + 1) * x,
minPoint.Y + (j + 1) * y, maxPoint.Z);
boundingBoxes.Add(Autodesk.DesignScript.Geometry.BoundingBox.ByCorners(min, max));
}
}
return boundingBoxes;
}

/// <summary>
/// Scale the bounding box by value
Expand Down
Loading

0 comments on commit 6cd016e

Please sign in to comment.