Creating Filled Stadiums #1193
Answered
by
mozman
johnthagen
asked this question in
Q&A
-
Is it possible to natively define a filled stadium object within DXF? Note this is similar to an ellipse: But the geometric shape is different. |
Beta Was this translation helpful? Give feedback.
Answered by
mozman
Nov 6, 2024
Replies: 1 comment 2 replies
-
A HATCH entity to get the filling, a LWPOLYLINE entity to get the border line if required. import ezdxf
from ezdxf.layouts import Modelspace
def add_stadium_as_lwpolyline(msp: Modelspace, a: float, r: float) -> None:
# format: x, y, bulge
# bulge value always at the start vertex of the arc
d = 2 * r
points = [
(0, 0, 0),
(0, a, 1), # semi-circle follows
(-d, a, 0),
(-d, 0, 1), # semi-circle follows
# close shape
]
msp.add_lwpolyline(points, format="xyb", close=True)
def add_stadium_as_hatch(msp: Modelspace, a: float, r: float) -> None:
d = 2 * r
hatch = msp.add_hatch(color=1)
edges = hatch.paths.add_edge_path()
edges.add_line((0, 0), (0, a))
edges.add_arc(center=(-r, a), radius=r, start_angle=0, end_angle=180)
edges.add_line((-d, a), (-d, 0))
edges.add_arc(center=(-r, 0), radius=r, start_angle=180, end_angle=0)
def main():
doc = ezdxf.new()
msp = doc.modelspace()
add_stadium_as_hatch(msp, 10, 5)
add_stadium_as_lwpolyline(msp, 10, 5)
doc.saveas("stadium.dxf")
if __name__ == "__main__":
main() |
Beta Was this translation helpful? Give feedback.
2 replies
Answer selected by
johnthagen
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
A HATCH entity to get the filling, a LWPOLYLINE entity to get the border line if required.