Box

class compas.geometry.Box[source]

Bases: Shape

A box is defined by a frame and its dimensions along the frame’s x-, y- and z-axes.

The center of the box is positioned at the origin of the coordinate system defined by the frame. The box is axis-aligned to the frame.

A box is a three-dimensional geometric shape with 8 vertices, 12 edges and 6 faces. The edges of a box meet at its vertices at 90 degree angles. The faces of a box are planar. Faces which do not share an edge are parallel.

Parameters:
xsizefloat

The size of the box in the box frame’s x direction.

ysizefloat, optional

The size of the box in the box frame’s y direction. Defaults to the value of xsize.

zsizefloat, optional

The size of the box in the box frame’s z direction. Defaults to the value of xsize.

framecompas.geometry.Frame, optional

The frame of the box. Defaults to Frame.worldXY().

namestr, optional

The name of the shape.

Examples

>>> box = Box(1)
>>> box.xsize
1.0
>>> box.ysize
1.0
>>> box.zsize
1.0
>>> box.volume
1.0
>>> box.area
6.0
>>> box = Box(1, 2, 3)
>>> box.xsize
1.0
>>> box.ysize
2.0
>>> box.zsize
3.0
>>> box.volume
6.0
>>> box.area
22.0
Attributes:
areafloat, read-only

The surface area of the box.

depthfloat, read-only

The depth of the box in Y direction.

diagonalcompas.geometry.Line, read-only

Diagonal of the box.

dimensionslist[float], read-only

The dimensions of the box in the local frame.

framecompas.geometry.Frame

The box’s frame.

heightfloat, read-only

The height of the box in Z direction.

volumefloat, read-only

The volume of the box.

widthfloat, read-only

The width of the box in X direction.

xminfloat, read-only

Minimum value along local X axis.

xmaxfloat, read-only

Maximum value along local X axis.

xsizefloat

The size of the box in the box frame’s x direction.

yminfloat, read-only

Minimum value along local Y axis.

ymaxfloat, read-only

Maximum value along local Y axis.

ysizefloat

The size of the box in the box frame’s y direction.

zminfloat, read-only

Minimum value along local Z axis.

zmaxfloat, read-only

Maximum value along local Z axis.

zsizefloat

The size of the box in the box frame’s z direction.

Methods

contains_point

Verify if the box contains a given point.

contains_points

Verify if the box contains the given points.

corner

Return one of the eight corners of the box.

from_bounding_box

Construct a box from the result of a bounding box calculation.

from_corner_corner_height

Construct a box from the opposite corners of its base and its height.

from_diagonal

Construct a box from its main diagonal.

from_points

Construct a box from a set of points.

from_width_height_depth

Construct a box from its width, height and depth.

scale

Scale the box.

to_brep

Returns a BREP representation of the box.

to_mesh

Returns a mesh representation of the box.

to_vertices_and_faces

Returns a list of vertices and faces.

Inherited Methods

ToString

Converts the instance to a string.

compute_aabb

Compute the axis-aligned bounding box of the geometry.

compute_obb

Compute the oriented bounding box of the geometry.

copy

Make an independent copy of the data object.

from_json

Construct an object of this type from a JSON file.

from_jsonstring

Construct an object of this type from a JSON string.

rotate

Rotate the shape.

rotated

Returns a rotated copy of this geometry.

scaled

Returns a scaled copy of this geometry.

sha256

Compute a hash of the data for comparison during version control using the sha256 algorithm.

to_json

Convert an object to its native data representation and save it to a JSON file.

to_jsonstring

Convert an object to its native data representation and save it to a JSON string.

to_polyhedron

Convert the shape to a polyhedron.

transform

Transform the shape.

transformed

Returns a transformed copy of this geometry.

translate

Translate the shape.

translated

Returns a translated copy of this geometry.

validate_data

Validate the data against the object's data schema.