def get_transformation(self) -> Matrix44: """Returns the transformation matrix to transform the source entity located with the minimum extension corner of its bounding box in (0, 0, 0) to the final location including the required rotation. """ x, y, z = self.position rt = self.rotation_type if rt == RotationType.WHD: # width, height, depth return Matrix44.translate(x, y, z) if rt == RotationType.HWD: # height, width, depth return Matrix44.z_rotate(PI_2) @ Matrix44.translate( x + self.height, y, z) if rt == RotationType.HDW: # height, depth, width return Matrix44.xyz_rotate(PI_2, 0, PI_2) @ Matrix44.translate( x + self.height, y + self.depth, z) if rt == RotationType.DHW: # depth, height, width return Matrix44.y_rotate(-PI_2) @ Matrix44.translate( x + self.depth, y, z) if rt == RotationType.DWH: # depth, width, height return Matrix44.xyz_rotate(0, PI_2, PI_2) @ Matrix44.translate( x, y, z) if rt == RotationType.WDH: # width, depth, height return Matrix44.x_rotate(PI_2) @ Matrix44.translate( x, y + self.depth, z) raise TypeError(rt)
def rotate_y(self, angle: float) -> "DXFGraphic": """Rotate entity inplace about y-axis, returns `self` (floating interface). Args: angle: rotation angle in radians """ return self.transform(Matrix44.y_rotate(angle))
def rotate_y(self, angle: float): """ Rotate mesh around y-axis about `angle` inplace. Args: angle: rotation angle in radians """ self.vertices = list( Matrix44.y_rotate(angle).transform_vertices(self.vertices)) return self
def create_base_block(block: 'BlockLayout', arrow_length=4): def add_axis(attribs: Dict, m: Matrix44 = None): start = -X_AXIS * arrow_length / 2 end = X_AXIS * arrow_length / 2 leg1 = Vec3.from_deg_angle(180 - leg_angle) * leg_length leg2 = Vec3.from_deg_angle(180 + leg_angle) * leg_length lines = [ block.add_line(start, end, dxfattribs=attribs), block.add_line(end, end + leg1, dxfattribs=attribs), block.add_line(end, end + leg2, dxfattribs=attribs), ] if m is not None: for line in lines: line.transform(m) leg_length = arrow_length / 10 leg_angle = 15 deg_90 = math.radians(90) # red x-axis add_axis(attribs={'color': 1, 'layer': BLK_CONTENT}) # green y-axis add_axis(attribs={ 'color': 3, 'layer': BLK_CONTENT }, m=Matrix44.z_rotate(deg_90)) # blue z-axis add_axis(attribs={ 'color': 5, 'layer': BLK_CONTENT }, m=Matrix44.y_rotate(-deg_90)) x = -arrow_length * 0.45 y = arrow_length / 20 line_spacing = 1.50 height = arrow_length / 20 block.add_attdef('ROTATION', (x, y), dxfattribs={ 'style': ATTRIBS, 'height': height }) y += height * line_spacing block.add_attdef('SCALE', (x, y), dxfattribs={ 'style': ATTRIBS, 'height': height }) y += height * line_spacing block.add_attdef('EXTRUSION', (x, y), dxfattribs={ 'style': ATTRIBS, 'height': height })
def matrix(self): return Matrix44.y_rotate(math.radians(-90))