def world_to_local_coords(frame, xyz): """Convert global coordinates to local coordinates. Parameters ---------- frame : :class:`Frame` or [point, xaxis, yaxis] The local coordinate system. xyz : array-like The global coordinates of the points to convert. Returns ------- list of list of float The coordinates of the given points in the local coordinate system. Examples -------- >>> import numpy as np >>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9]) >>> xyz = [Point(2, 3, 5)] >>> Point(*world_to_local_coords(f, xyz)[0]) Point(3.726, 4.088, 1.550) """ from compas.geometry.primitives import Frame T = matrix_change_basis(Frame.worldXY(), frame) return transform_points(xyz, T)
def local_to_world_coords(frame, xyz): """Convert local coordinates to global coordinates. Parameters ---------- frame : :class:`Frame` or [point, xaxis, yaxis] The local coordinate system. xyz : list of `Points` or list of list of float The global coordinates of the points to convert. Returns ------- list of list of float The coordinates of the given points in the local coordinate system. Examples -------- >>> import numpy as np >>> f = Frame([0, 1, 0], [3, 4, 1], [1, 5, 9]) >>> xyz = [Point(3.726, 4.088, 1.550)] >>> Point(*local_to_world_coords(f, xyz)[0]) Point(2.000, 3.000, 5.000) """ from compas.geometry.primitives import Frame # noqa: F811 T = matrix_change_basis(frame, Frame.worldXY()) return transform_points(xyz, T)
def from_width_height_depth(cls, width, height, depth): """Construct a box from its width, height and depth. Parameters ---------- width : float Width of the box. height : float Height of the box. depth : float Depth of the box. Returns ------- Box The resulting box. Notes ----- The bottom left corner of the box is positioned at the origin of the coordinates system. The box is axis-aligned. Examples -------- >>> from compas.geometry import Box >>> box = Box.from_width_height_depth(1.0, 2.0, 3.0) """ width = float(width) height = float(height) depth = float(depth) if width == 0.0: raise Exception('Width cannot be zero.') if height == 0.0: raise Exception('Height cannot be zero.') if depth == 0.0: raise Exception('Depth cannot be zero.') return cls(Frame.worldXY(), width, depth, height)
def from_data(cls, data): """Construct a box from its data representation. Parameters ---------- data : :obj:`dict` The data dictionary. Returns ------- Box The constructed box. Examples -------- >>> data = {'frame': Frame.worldXY().data, 'xsize': 1.0, 'ysize': 1.0, 'zsize': 1.0} >>> box = Box.from_data(data) """ box = cls(Frame.worldXY(), 1, 1, 1) box.data = data return box