Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/shapes/circlePolygon.py
193745 views
1
#!/usr/bin/env python
2
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
3
# Copyright (C) 2010-2026 German Aerospace Center (DLR) and others.
4
# This program and the accompanying materials are made available under the
5
# terms of the Eclipse Public License 2.0 which is available at
6
# https://www.eclipse.org/legal/epl-2.0/
7
# This Source Code may also be made available under the following Secondary
8
# Licenses when the conditions for such availability set forth in the Eclipse
9
# Public License 2.0 are satisfied: GNU General Public License, version 2
10
# or later which is available at
11
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
12
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
13
14
# @file circlePolygon.py
15
# @author Daniel Krajzewicz
16
# @author Michael Behrisch
17
# @author Yun-Pang Floetteroed
18
# @date 2010-02-20
19
20
21
from __future__ import print_function
22
from __future__ import absolute_import
23
import os
24
import sys
25
import math
26
THIS_DIR = os.path.dirname(os.path.abspath(__file__))
27
sys.path.append(os.path.join(THIS_DIR, '..'))
28
import sumolib # noqa
29
30
31
def setCircle(idx, x, y, r, c, prefix, type, color, fill, layer, output):
32
angle = 2 * math.pi / c
33
shape = ""
34
for i in range(c):
35
shape += "%.2f,%.2f " % (math.cos(i * angle) * r + x,
36
math.sin(i * angle) * r + y)
37
if i == 0:
38
beginPoint = shape
39
shape += beginPoint
40
print(' <poly id="%s%s" type="%s" color="%s" fill="%i" layer="%s" shape="%s"/>' % (
41
prefix, idx, type, color, fill, layer, shape[:-1]),
42
file=output)
43
44
45
if __name__ == "__main__":
46
47
op = sumolib.options.ArgumentParser(description="Make a circle polygon")
48
49
op.add_option("files", nargs='+', category="input", type=op.file_list,
50
help="List of XML files to plot")
51
op.add_option("-r", "--radius", type=float, default=100,
52
help="default radius")
53
op.add_option("-p", "--prefix", default="poly",
54
help="id prefix")
55
op.add_option("-t", "--type", default="unknown",
56
help="type string")
57
op.add_option("--color", default="1,0,0",
58
help="color string")
59
op.add_option("-f", "--fill", action="store_true",
60
default=False, help="fill the polygons")
61
op.add_option("-l", "--layer", type=float, default=-1,
62
help="layer")
63
op.add_option("-x", "--corners", type=int, default=100,
64
help="default number of corners")
65
op.add_option("-o", "--output-file", category="output", type=op.file,
66
help="output file (default: standard output)")
67
68
try:
69
options = op.parse_args()
70
except (NotImplementedError, ValueError) as e:
71
print(e, file=sys.stderr)
72
sys.exit(1)
73
74
output = sys.stdout if options.output_file is None else open(options.output_file, 'w')
75
print("<additional>", file=output)
76
for idx, d in enumerate(options.files):
77
desc = d.split(",")
78
x = float(desc[0])
79
y = float(desc[1])
80
r = float(desc[2]) if len(desc) > 2 else options.radius
81
c = int(desc[3]) if len(desc) > 3 else options.corners
82
83
setCircle(idx, x, y, r, c, options.prefix, options.type, options.color, options.fill, options.layer, output)
84
print("</additional>", file=output)
85
86