コード例 #1
0
def build(angle, dx, dy, dz, axis, start, end, count):
    ellipse = Ellipse.new(dxfattribs={
        'start_param': start,
        'end_param': end,
    })
    vertices = list(ellipse.vertices(ellipse.params(count)))
    m = Matrix44.chain(Matrix44.axis_rotate(axis=axis, angle=angle),
                       Matrix44.translate(dx=dx, dy=dy, dz=dz))
    return synced_transformation(ellipse, vertices, m)
コード例 #2
0
ファイル: test_708_path.py プロジェクト: kloppen/ezdxf
def test_from_ellipse():
    from ezdxf.entities import Ellipse
    from ezdxf.math import ConstructionEllipse
    e = ConstructionEllipse(center=(3, 0), major_axis=(1, 0), ratio=0.5,
                            start_param=0, end_param=math.pi)
    ellipse = Ellipse.new()
    ellipse.apply_construction_tool(e)
    path = Path.from_ellipse(ellipse)
    assert path.start == (4, 0)
    assert path.end == (2, 0)
コード例 #3
0
def _virtual_edge_path(path: EdgePath, dxfattribs: Dict, ocs: OCS,
                       elevation: float) -> List["DXFGraphic"]:
    from ezdxf.entities import Line, Arc, Ellipse, Spline

    def pnt_to_wcs(v):
        return ocs.to_wcs(Vec3(v).replace(z=elevation))

    def dir_to_wcs(v):
        return ocs.to_wcs(v)

    edges: List["DXFGraphic"] = []
    for edge in path.edges:
        attribs = dict(dxfattribs)
        if isinstance(edge, LineEdge):
            attribs["start"] = pnt_to_wcs(edge.start)
            attribs["end"] = pnt_to_wcs(edge.end)
            edges.append(Line.new(dxfattribs=attribs))
        elif isinstance(edge, ArcEdge):
            attribs["center"] = edge.center
            attribs["radius"] = edge.radius
            attribs["elevation"] = elevation
            # Arcs angles are always stored in counter clockwise orientation
            # around the extrusion vector!
            attribs["start_angle"] = edge.start_angle
            attribs["end_angle"] = edge.end_angle
            attribs["extrusion"] = ocs.uz
            edges.append(Arc.new(dxfattribs=attribs))
        elif isinstance(edge, EllipseEdge):
            attribs["center"] = pnt_to_wcs(edge.center)
            attribs["major_axis"] = dir_to_wcs(edge.major_axis)
            attribs["ratio"] = edge.ratio
            # Ellipse angles are always stored in counter clockwise orientation
            # around the extrusion vector!
            attribs["start_param"] = edge.start_param
            attribs["end_param"] = edge.end_param
            attribs["extrusion"] = ocs.uz
            edges.append(Ellipse.new(dxfattribs=attribs))
        elif isinstance(edge, SplineEdge):
            spline = Spline.new(dxfattribs=attribs)
            spline.dxf.degree = edge.degree
            spline.knots = edge.knot_values
            spline.control_points = [
                pnt_to_wcs(v) for v in edge.control_points
            ]
            if edge.weights:
                spline.weights = edge.weights
            if edge.fit_points:
                spline.fit_points = [pnt_to_wcs(v) for v in edge.fit_points]
            if edge.start_tangent is not None:
                spline.dxf.start_tangent = dir_to_wcs(edge.start_tangent)
            if edge.end_tangent is not None:
                spline.dxf.end_tangent = dir_to_wcs(edge.end_tangent)
            edges.append(spline)
    return edges
コード例 #4
0
 def build():
     ellipse = Ellipse.new(dxfattribs={
         'start_param': start,
         'end_param': end,
     })
     vertices = list(ellipse.vertices(ellipse.params(vertex_count)))
     m = Matrix44.chain(
         Matrix44.axis_rotate(axis=Vec3.random(), angle=random.uniform(0, math.tau)),
         Matrix44.translate(dx=random.uniform(-2, 2), dy=random.uniform(-2, 2), dz=random.uniform(-2, 2)),
     )
     return synced_transformation(ellipse, vertices, m)
コード例 #5
0
def ellipse1():
    return Ellipse.new(dxfattribs={
        "center": (
            298998.9237372455,
            105908.98587737791,
            0.0218015606544459,
        ),
        "major_axis": (-2.005925505480262, 9.590684825374422e-13, 0.0),
        "ratio":
        0.6052078628034204,
        "start_param":
        7.898e-13,
        "end_param":
        7.878142582740111e-13,
        "extrusion": (0.0, -0.0, 1.0),
    }, )
コード例 #6
0
ファイル: test_226_spline.py プロジェクト: tbwhsb88/ezdxf
def test_from_ellipse():
    from ezdxf.entities import Ellipse
    spline = Spline.from_arc(Ellipse.new(dxfattribs={
        'center': (1, 1),
        'major_axis': (2, 0),
        'ratio': 0.5,
        'start_param': 0.5,  # radians
        'end_param': 3,
        'layer': 'ellipse',
    }))
    assert spline.dxf.layer == 'ellipse'
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(len(spline.control_points), spline.dxf.degree + 1)
コード例 #7
0
def ellipse(major_axis=(1, 0),
            ratio: float = 0.5,
            start: float = 0,
            end: float = math.tau,
            count: int = 8):
    major_axis = Vector(major_axis).replace(z=0)
    ellipse_ = Ellipse.new(dxfattribs={
        'center': (0, 0, 0),
        'major_axis': major_axis,
        'ratio': min(max(ratio, 1e-6), 1),
        'start_param': start,
        'end_param': end
    },
                           doc=doc)
    control_vertices = list(ellipse_.vertices(ellipse_.params(count)))
    axis_vertices = list(
        ellipse_.vertices([0, math.pi / 2, math.pi, math.pi * 1.5]))
    return ellipse_, control_vertices, axis_vertices
コード例 #8
0
def test_upright_ellipse():
    ellipse = Ellipse.new(
        dxfattribs={
            "center": (5, 5, 5),
            "major_axis": (5, 0, 0),
            "ratio": 0.5,
            "start_param": 0.5,
            "end_param": 1.5,
            "extrusion": (0, 0, -1),
        })
    p0 = path.make_path(ellipse)
    assert p0.has_curves is True

    upright(ellipse)
    assert ellipse.dxf.extrusion.isclose(Z_AXIS)
    p1 = path.make_path(ellipse)
    # has reversed vertex order of source entity:
    assert path.have_close_control_vertices(p0, p1.reversed())
コード例 #9
0
ファイル: test_226_spline.py プロジェクト: Rahulghuge94/ezdxf
def test_from_ellipse():
    from ezdxf.entities import Ellipse

    spline = Spline.from_arc(
        Ellipse.new(
            dxfattribs={
                "center": (1, 1),
                "major_axis": (2, 0),
                "ratio": 0.5,
                "start_param": 0.5,  # radians
                "end_param": 3,
                "layer": "ellipse",
            }))
    assert spline.dxf.layer == "ellipse"
    assert spline.dxf.degree == 2
    assert len(spline.control_points) > 2
    assert len(spline.weights) > 2
    assert len(spline.fit_points) == 0
    assert len(spline.knots) == required_knot_values(
        len(spline.control_points), spline.dxf.degree + 1)
コード例 #10
0
def ellipse(
    major_axis=(1, 0),
    ratio: float = 0.5,
    start: float = 0,
    end: float = math.tau,
    count: int = 8,
):
    major_axis = Vec3(major_axis).replace(z=0)
    ellipse_ = Ellipse.new(
        dxfattribs={
            "center": (0, 0, 0),
            "major_axis": major_axis,
            "ratio": min(max(ratio, 1e-6), 1),
            "start_param": start,
            "end_param": end,
        },
        doc=doc,
    )
    control_vertices = list(ellipse_.vertices(ellipse_.params(count)))
    axis_vertices = list(
        ellipse_.vertices([0, math.pi / 2, math.pi, math.pi * 1.5]))
    return ellipse_, control_vertices, axis_vertices