The Autodesk.Revit.DB.Rectangle
class represents a rectangle in Revit. It can be used to define the bounds of a 2D plan view or a 3D view in Revit.
The Autodesk.Revit.DB.Rectangle
class has the following properties:
Min
- A XYZ
object that represents the minimum point of the rectangle.Max
- A XYZ
object that represents the maximum point of the rectangle.The Autodesk.Revit.DB.Rectangle
class has the following constructors:
Rectangle(XYZ min, XYZ max)
- Creates a new rectangle with the specified minimum and maximum points.The Autodesk.Revit.DB.Rectangle
class has the following methods:
Contains(XYZ point)
- Determines if a point is within the bounds of the rectangle.Intersects(Rectangle other)
- Determines if the rectangle intersects with another rectangle.Translate(XYZ vector)
- Translates the rectangle by the specified vector.Min
and Max
properties must be set to valid XYZ
objects that represent the corners of the rectangle.Contains
and Intersects
methods are useful for determining if a point or another rectangle is within the bounds of the rectangle.Translate
method can be used to move the rectangle by a specified vector.Here is an example that demonstrates how to create a rectangle and use the Contains
and Intersects
methods:
// Create a new rectangle
var r1 = new Autodesk.Revit.DB.Rectangle(new XYZ(0, 0, 0), new XYZ(10, 10, 0));
// Check if a point is inside the rectangle
var p1 = new XYZ(5, 5, 0);
bool containsPoint = r1.Contains(p1);
// Check if another rectangle intersects with the first rectangle
var r2 = new Autodesk.Revit.DB.Rectangle(new XYZ(8, 8, 0), new XYZ(12, 12, 0));
bool intersects = r1.Intersects(r2);
In this example, we create a rectangle with corners at (0, 0, 0) and (10, 10, 0). We then create a point at (5, 5, 0) and use the Contains
method to determine if it is within the bounds of the rectangle. Finally, we create another rectangle with corners at (8, 8, 0) and (12, 12, 0) and use the Intersects
method to determine if it intersects with the first rectangle.