def gear(count: int, top_width: float, bottom_width: float, height: float, outside_radius: float, transform: Matrix44 = None) -> Path: """ Returns a `gear <https://en.wikipedia.org/wiki/Gear>`_ (cogwheel) shape as a :class:`Path` object, with the center at (0, 0, 0). The base geometry is created by function :func:`ezdxf.render.forms.gear`. .. warning:: This function does not create correct gears for mechanical engineering! Args: count: teeth count >= 3 top_width: teeth width at outside radius bottom_width: teeth width at base radius height: teeth height; base radius = outside radius - height outside_radius: outside radius transform: transformation Matrix applied to the gear shape """ vertices = forms.gear(count, top_width, bottom_width, height, outside_radius) if transform is not None: vertices = transform.transform_vertices(vertices) return converter.from_vertices(vertices, close=True)
def transform(self, m: Matrix44) -> 'Line': """ Transform the LINE entity by transformation matrix `m` inplace. """ start, end = m.transform_vertices([self.dxf.start, self.dxf.end]) self.dxf.start = start self.dxf.end = end transform_thickness_and_extrusion_without_ocs(self, m) return self
def transform(self, m: Matrix44) -> 'Face3d': """ Transform the 3DFACE entity by transformation matrix `m` inplace. """ dxf = self.dxf # 3DFACE is a real 3d entity dxf.vtx0, dxf.vtx1, dxf.vtx2, dxf.vtx3 = m.transform_vertices( (dxf.vtx0, dxf.vtx1, dxf.vtx2, dxf.vtx3)) return self
def transform(self, m: Matrix44) -> "Bezier": """General transformation interface, returns a new :class:`Bezier` curve. Args: m: 4x4 transformation matrix (:class:`ezdxf.math.Matrix44`) """ defpoints = tuple(m.transform_vertices(self.control_points)) return Bezier(defpoints)
def transform(self, m: Matrix44) -> None: """ Transform vertices by transformation matrix `m`. .. versionadded:: 0.13 """ values = array('d') for vertex in m.transform_vertices(self): values.extend(vertex) self.values = values
def line(self, x1: float, y1: float, x2: float, y2: float, m: Matrix44 = None) -> None: points = [(x1, y1), (x2, y2)] if m is not None: p1, p2 = m.transform_vertices(points) else: p1, p2 = Vec3.generate(points) self.backend.draw_line(p1, p2, self.properties)
def transform_paths(paths: Iterable[Path], m: Matrix44) -> List[Path]: """ Transform multiple :class:`Path` objects at once by transformation matrix `m`. Returns a list of the transformed :class:`Path` objects. Args: paths: iterable of :class:`Path` objects m: transformation matrix of type :class:`~ezdxf.math.Matrix44` """ def decompose(path: Path): vertices.append(path.start) commands.append(Command.START_PATH) for cmd in path: commands.extend(itertools.repeat(cmd.type, len(cmd))) vertices.extend(cmd) def rebuild(vertices): path = None collect = [] for vertex, cmd in zip(vertices, commands): if cmd == Command.START_PATH: if path is not None: transformed_paths.append(path) path = Path(vertex) elif cmd == Command.LINE_TO: path.line_to(vertex) elif cmd == Command.CURVE3_TO: collect.append(vertex) if len(collect) == 2: path.curve3_to(collect[0], collect[1]) collect.clear() elif cmd == Command.CURVE4_TO: collect.append(vertex) if len(collect) == 3: path.curve4_to(collect[0], collect[1], collect[2]) collect.clear() if path is not None: transformed_paths.append(path) vertices = [] commands = [] transformed_paths = [] for path in paths: decompose(path) if len(commands): rebuild(m.transform_vertices(vertices)) return transformed_paths
def transform(self, m: Matrix44) -> 'Bezier4P': """ General transformation interface, returns a new :class:`Bezier4p` curve and it is always a 3D curve. Args: m: 4x4 transformation matrix (:class:`ezdxf.math.Matrix44`) .. versionadded:: 0.14 """ if len(self._control_points[0]) == 2: defpoints = Vector.generate(self._control_points) else: defpoints = self._control_points defpoints = tuple(m.transform_vertices(defpoints)) return Bezier4P(defpoints)
def corner_vertices( left: float, bottom: float, right: float, top: float, m: Matrix44 = None, ) -> Iterable[Vec3]: corners = [ # closed polygon: fist vertex == last vertex (left, top), (right, top), (right, bottom), (left, bottom), (left, top), ] if m is None: return Vec3.generate(corners) else: return m.transform_vertices(corners)
def star(count: int, r1: float, r2: float, transform: Matrix44 = None) -> Path: """ Returns a `star shape <https://en.wikipedia.org/wiki/Star_polygon>`_ as a :class:`Path` object, with the center at (0, 0, 0). Argument `count` defines the count of star spikes, `r1` defines the radius of the "outer" vertices and `r2` defines the radius of the "inner" vertices, but this does not mean that `r1` has to be greater than `r2`. The star shape starts with the first vertex is on the x-axis! The base geometry is created by function :func:`ezdxf.render.forms.star`. Args: count: spike count >= 3 r1: radius 1 r2: radius 2 transform: transformation Matrix applied to the star """ vertices = forms.star(count, r1=r1, r2=r2) if transform is not None: vertices = transform.transform_vertices(vertices) return converter.from_vertices(vertices, close=True)
def ngon(count: int, length: float = None, radius: float = 1.0, transform: Matrix44 = None) -> Path: """ Returns a `regular polygon <https://en.wikipedia.org/wiki/Regular_polygon>`_ a :class:`Path` object, with the center at (0, 0, 0). The polygon size is determined by the edge `length` or the circum `radius` argument. If both are given `length` has higher priority. Default size is a `radius` of 1. The ngon starts with the first vertex is on the x-axis! The base geometry is created by function :func:`ezdxf.render.forms.ngon`. Args: count: count of polygon corners >= 3 length: length of polygon side radius: circum radius, default is 1 transform: transformation Matrix applied to the ngon """ vertices = forms.ngon(count, length=length, radius=radius) if transform is not None: vertices = transform.transform_vertices(vertices) return converter.from_vertices(vertices, close=True)
def synced_transformation(entity, chk, m: Matrix44): entity = entity.copy() entity.transform(m) chk = list(m.transform_vertices(chk)) return entity, chk
def _transform_path(path: Path, transform: Matrix44) -> Path: vertices = transform.transform_vertices( [Vector(x, y) for x, y in path.vertices]) return Path([(v.x, v.y) for v in vertices], path.codes)
def transform(self, m: Matrix44) -> None: """Transform vertices by transformation matrix `m`.""" values = array("d") for vertex in m.transform_vertices(self): values.extend(vertex) self.values = values