Box
- class compas.geometry.Box(frame, xsize, ysize, zsize, **kwargs)[source]
Bases:
compas.geometry.shapes._shape.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
frame (
compas.geometry.Frame
) – The frame of the box.xsize (float) – The size of the box in the box frame’s x direction.
ysize (float) – The size of the box in the box frame’s y direction.
zsize (float) – The size of the box in the box frame’s z direction.
- Attributes
frame (compas.geometry.Frame) – The local coordinate system of the box.
xsize (float) – The size of the box in the local X direction.
ysize (float) – The size of the box in the local Y direction.
zsize (float) – The size of the box in the local Z direction.
width (read-only) (float) – Alias for
xsize
.depth (read-only) (float) – Alias for
ysize
.height (read-only) (float) – Alias for
zsize
.diagonal (read-only) (tuple of compas.geometry.Point) – The start and end point of the main diagonal of the box.
dimensions (read-only) (list of float) – List of sizes in local coordinate directions.
area (read-only) (float) – The surface area of the box.
volume (read-only) (float) – The volume of the box.
vertices (read-only) (list of list) – The XYZ coordinates of the corners of the box. With respect to the local Z axis, the vertices of the bottom face are listed first in clockwise direction, starting at the bottom left corner. The vertices of the top face are listed in counterclockwise direction.
faces (read-only) (list of list) – The vertices of the faces of the box. The cycle directions of the faces are such that face normals point outwards.
Examples
>>> box = Box(Frame.worldXY(), 1.0, 2.0, 3.0)
Methods
contains
(point)Verify if the box contains a given point.
copy
([cls])Make an independent copy of the data object.
from_bounding_box
(bbox)Construct a box from the result of a bounding box calculation.
from_corner_corner_height
(corner1, corner2, ...)Construct a box from the opposite corners of its base and its height.
from_data
(data)Construct a box from its data representation.
from_diagonal
(diagonal)Construct a box from its main diagonal.
from_json
(filepath)Construct an object from serialized data contained in a JSON file.
from_jsonstring
(string)Construct an object from serialized data contained in a JSON string.
from_width_height_depth
(width, height, depth)Construct a box from its width, height and depth.
to_data
()Convert an object to its native data representation.
to_json
(filepath[, pretty])Serialize the data representation of an object to a JSON file.
to_jsonstring
([pretty])Serialize the data representation of an object to a JSON string.
to_vertices_and_faces
([triangulated])Returns a list of vertices and faces.
transform
(transformation)Transform the box.
transformed
(transformation)Returns a transformed copy of this geometry.
Validate the object's data against its data schema (self.DATASCHEMA).
Validate the object's data against its json schema (self.JSONSCHEMA).