Ich erzeuge Koordinaten für Winkel in svg. Mal brauche ich die Schenkel, mal die Winkelbögen, meistens beides. Ich erzeuge diese mit der Funktion:
Code: Alles auswählen
def winkel_koo(center_x, center_y, radius, winkel, startwinkel, color = "None", symbol = "", schenkel = 0, scheitel = False, id = 0):
rad_start = math.radians(startwinkel)
rad = math.radians(winkel)
koordinaten = dict(center_x = center_x, center_y = center_y, )
# das sind die Schenkel:
if schenkel > 0:
x1 = center_x - schenkel * math.cos(rad_start)
y1 = center_y - schenkel * math.sin(rad_start)
x2 = center_x - schenkel * math.cos(rad+rad_start)
y2 = center_y - schenkel * math.sin(rad+rad_start)
if scheitel == True:
x3 = center_x + schenkel * math.cos(rad_start)
y3 = center_y + schenkel * math.sin(rad_start)
x4 = center_x + schenkel * math.cos(rad+rad_start)
y4 = center_y + schenkel * math.sin(rad+rad_start)
schenkel_koo = dict(schenkel_1_x = x3, schenkel_1_y = y3, schenkel_2_x = x4, schenkel_2_y = y4)
else:
schenkel_koo = dict(schenkel_1_x = x1, schenkel_1_y = y1, schenkel_2_x = x2, schenkel_2_y = y2)
koordinaten.update(schenkel_koo)
# das ist der Bogen mit Text:
if color:
start_x = center_x - radius * math.cos(rad_start)
start_y = center_y - radius * math.sin(rad_start)
end_x = center_x - radius * math.cos(rad+rad_start)
end_y = center_y - radius * math.sin(rad+rad_start)
if winkel <=180:
largeArcFlag = 0
else:
largeArcFlag = 1
text_x = center_x - radius*3/4 * math.cos(rad/2+rad_start)
text_y = center_y - radius/2 * math.sin(rad/2+rad_start)
bogen_koo = dict(bogen_radius = radius, sweep_flag = 1, color = color, symbol = symbol,
start_bogen_x = start_x, start_bogen_y = start_y, end_bogen_x = end_x, end_bogen_y = end_y, largeArcFlag = largeArcFlag,
text_x = text_x, text_y = text_y, )
koordinaten.update(bogen_koo)
return koordinaten
Code: Alles auswählen
{'center_x': 200, 'center_y': 100, 'schenkel_1_x': 248.2962913144534, 'schenkel_1_y': 87.05904774487395, 'schenkel_2_x': 248.2962913144534, 'schenkel_2_y': 112.94095225512602, 'bogen_radius': 40, 'sweep_flag': 1, 'color': 'lightskyblue', 'symbol': 'β', 'start_bogen_x': 238.63703305156272, 'start_bogen_y': 89.64723819589916, 'end_bogen_x': 238.63703305156275, 'end_bogen_y': 110.35276180410081, 'largeArcFlag': 0, 'text_x': 230.0, 'text_y': 100.0}