Boxes


Geometric definition


A boxis a closed volume with 6 rectangular faces. It is the first object we see that has a height, a width and a length. The fact that all faces are rectangles implies that opposite faces are always parallel.

How to add


Rhinocommons


import Rhino 
import scriptcontext as sc

# Parameters needed to create the box:
my_plane = Rhino.Geometry.Plane(1, 1, 1, 0)
x_interval = Rhino.Geometry.Interval(0, 10)
y_interval = Rhino.Geometry.Interval(0, 10)
z_interval = Rhino.Geometry.Interval(0, 10)

# Will create a box from a plane, and 3 intervals: x_interval, y_interval, z_interval
my_box = Rhino.Geometry.Box(my_plane, x_interval, y_interval, z_interval)

sc.doc.Objects.AddBox(my_box)


import Rhino 
import scriptcontext as sc

# Parameters needed to create the box:
pts = [Rhino.Geometry.Point3d(0, 0, 0),
       Rhino.Geometry.Point3d(0, 0, 1),
       Rhino.Geometry.Point3d(0, 1, 2),
       Rhino.Geometry.Point3d(1, 2, 3),
       Rhino.Geometry.Point3d(2, 3, 4),
       Rhino.Geometry.Point3d(4, 4, 5)]
my_plane = Rhino.Geometry.Plane(1, 1, 1, 0)

# Will create a box aligned with a plane, and containing a list of points
my_box = Rhino.Geometry.Box(my_plane, pts)

sc.doc.Objects.AddPoints(pts)
sc.doc.Objects.AddBox(my_box)

Rhinoscriptsyntax


# Will create a box from 8 corner points
# Be careful, this is not exactly the same type of "box". It can be any kind of hexahedron !!
point_A = Rhino.Geometry.Point3d(0, 0, 0)
point_B = Rhino.Geometry.Point3d(1, 0, 0)
point_C = Rhino.Geometry.Point3d(1, 1, 0)
point_D = Rhino.Geometry.Point3d(0, 1, 0)
point_E = Rhino.Geometry.Point3d(0, 0, 1)
point_F = Rhino.Geometry.Point3d(1, 0, 1)
point_G = Rhino.Geometry.Point3d(1, 1, 1)
point_H = Rhino.Geometry.Point3d(0, 1, 1)

rs.AddBox([point_A, point_B, point_C, point_D, point_E, point_F, point_G, point_H])

Main methods and properties:


Methods


# Will check if a point is inside the box:
point_A = Rhino.Geometry.Point3d(0, 0, 0)
point_A_is_in_box = my_box.Contains(point_A)

print("point_A is in the box: ", point_A_is_in_box)

# Will retrieve the box's corners:
corner_pts = my_box.GetCorners()

# Will extend the box to include the point if it is noy yet in the box.
point_A = Rhino.Geometry.Point3d(20, 20, 20)
point_A_is_in_box = my_box.Contains(point_A)

if point_A_is_in_box == False:
    my_box.Union(point_A)

Properties


# Will return the volume of the box:
volume = my_box.Volume

# Will return the area of the box
area = my_box.Area

# Will retrieve or set the base plane of the box:
base_plane = my_box.Plane


🛠 Exercises


01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍

Solution:

01: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍 02: 🐍⬇️⬇️⬇️ Download the script here ⬇️⬇️⬇️🐍