File: triangulate_paths.py

package info (click to toggle)
ezdxf 1.4.1-1
  • links: PTS, VCS
  • area: main
  • in suites: forky, sid, trixie
  • size: 104,528 kB
  • sloc: python: 182,341; makefile: 116; lisp: 20; ansic: 4
file content (38 lines) | stat: -rw-r--r-- 1,059 bytes parent folder | download
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
#  Copyright (c) 2022, Manfred Moitzi
#  License: MIT License

from pathlib import Path
import ezdxf
from ezdxf import path, zoom
from ezdxf.math import Matrix44

CWD = Path("~/Desktop/Outbox").expanduser()
if not CWD.exists():
    CWD = Path(".")

# ------------------------------------------------------------------------------
# This example shows how triangulate arbitrary path objects, a doughnut in this
# special case.
#
# docs: https://ezdxf.mozman.at/docs/path.html#ezdxf.path.triangulate
# ------------------------------------------------------------------------------


def main():
    doc = ezdxf.new()
    msp = doc.modelspace()

    circle0 = path.unit_circle(segments=8)
    circle1 = circle0.transform(Matrix44.scale(3))

    colors = [1, 2, 3, 4, 5, 6, 7]
    count = len(colors)
    for index, points in enumerate(path.triangulate([circle1, circle0])):
        msp.add_solid(points, dxfattribs={"color": colors[index % count]})

    zoom.extents(msp)
    doc.saveas(CWD / "triangulated_doughnut.dxf")


if __name__ == "__main__":
    main()