For clockwise / counter-clockwise drawing question solved.
But arcs still incorrect. I think problem when calculating angles. Because angles may be + or -.
My program reading coordinates form TXT file (file generated by other software from DXF format, where 0 degree at 12 o'clock).
Part of my code (Python3):
def arcAngles(self, a, b, c):
startAngle = 16*atan2(a.y() - c.y(), a.x() - c.x())*180 / pi
endAngle = 16*atan2(b.y() - c.y(), b.x() - c.x())*180 / pi
spanAngle = abs(endAngle) - abs(startAngle)
#Clocksiwe
if self.direction == -1:
if spanAngle > 0:
spanAngle = -spanAngle
print("START: " + str(startAngle / 16) + "\nEND: " + str(endAngle / 16) + "\nSPAN: " + str(spanAngle / 16))
angles = {'start': startAngle, 'end': endAngle, 'span': spanAngle}
return angles
def arcAngles(self, a, b, c):
startAngle = 16*atan2(a.y() - c.y(), a.x() - c.x())*180 / pi
endAngle = 16*atan2(b.y() - c.y(), b.x() - c.x())*180 / pi
spanAngle = abs(endAngle) - abs(startAngle)
#Clocksiwe
if self.direction == -1:
if spanAngle > 0:
spanAngle = -spanAngle
print("START: " + str(startAngle / 16) + "\nEND: " + str(endAngle / 16) + "\nSPAN: " + str(spanAngle / 16))
angles = {'start': startAngle, 'end': endAngle, 'span': spanAngle}
return angles
To copy to clipboard, switch view to plain text mode
Result:
=====1st Arc====
START: -90.0
END: 180.0
SPAN: -90.0
LastPoint: PyQt5.QtCore.QPointF(13.178, 82.461)
EndPoint: PyQt5.QtCore.QPointF(2.278, 93.361)
=====2nd Arc====
START: 180.0
END: 90.0
SPAN: -90.0
LastPoint: PyQt5.QtCore.QPointF(2.278, 151.361)
EndPoint: PyQt5.QtCore.QPointF(13.178, 162.261)
=====3rd Arc====
START: 90.0
END: 0.0
SPAN: -90.0
LastPoint: PyQt5.QtCore.QPointF(143.178, 162.261)
EndPoint: PyQt5.QtCore.QPointF(154.078, 151.361)
Drawing result:
1.png
I tried to solve this by manipulation with offset (90 degree), but still not solved.
Substracting offset from angles:
offset = 90*16
if startAngle < 0:
startAngle -= -offset
else:
startAngle -= offset
if endAngle < 0:
endAngle -= -offset
else:
endAngle -= offset
offset = 90*16
if startAngle < 0:
startAngle -= -offset
else:
startAngle -= offset
if endAngle < 0:
endAngle -= -offset
else:
endAngle -= offset
To copy to clipboard, switch view to plain text mode
When substract offset from angles i see:
11.png
Add offset to angles:
offset = 90*16
if startAngle < 0:
startAngle += -offset
else:
startAngle += offset
if endAngle < 0:
endAngle += -offset
else:
endAngle += offset
offset = 90*16
if startAngle < 0:
startAngle += -offset
else:
startAngle += offset
if endAngle < 0:
endAngle += -offset
else:
endAngle += offset
To copy to clipboard, switch view to plain text mode
When adding offset to angles i see:
22.png
Bookmarks