Results 1 to 7 of 7

Thread: QPainter drawArc question

Threaded View

Previous Post Previous Post   Next Post Next Post
  1. #7
    Join Date
    Dec 2015
    Posts
    12
    Qt products
    PyQt3 PyQt4
    Platforms
    Unix/X11 Windows

    Default Re: QPainter drawArc question

    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):
    Qt Code:
    1. def arcAngles(self, a, b, c):
    2. startAngle = 16*atan2(a.y() - c.y(), a.x() - c.x())*180 / pi
    3. endAngle = 16*atan2(b.y() - c.y(), b.x() - c.x())*180 / pi
    4.  
    5. spanAngle = abs(endAngle) - abs(startAngle)
    6.  
    7. #Clocksiwe
    8. if self.direction == -1:
    9. if spanAngle > 0:
    10. spanAngle = -spanAngle
    11.  
    12. print("START: " + str(startAngle / 16) + "\nEND: " + str(endAngle / 16) + "\nSPAN: " + str(spanAngle / 16))
    13. angles = {'start': startAngle, 'end': endAngle, 'span': spanAngle}
    14.  
    15. 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:
    Qt Code:
    1. offset = 90*16
    2.  
    3. if startAngle < 0:
    4. startAngle -= -offset
    5. else:
    6. startAngle -= offset
    7.  
    8. if endAngle < 0:
    9. endAngle -= -offset
    10. else:
    11. 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:
    Qt Code:
    1. offset = 90*16
    2.  
    3. if startAngle < 0:
    4. startAngle += -offset
    5. else:
    6. startAngle += offset
    7.  
    8. if endAngle < 0:
    9. endAngle += -offset
    10. else:
    11. endAngle += offset
    To copy to clipboard, switch view to plain text mode 

    When adding offset to angles i see:

    22.png
    Last edited by kloopa; 12th January 2016 at 09:58.

Similar Threads

  1. Center point and drawArc
    By seniorc in forum Newbie
    Replies: 1
    Last Post: 24th March 2014, 21:19
  2. Replies: 2
    Last Post: 22nd February 2010, 21:39
  3. QPainter - drawRoundedRect Question
    By ChrisReath in forum Qt Programming
    Replies: 2
    Last Post: 14th May 2008, 14:14
  4. QPainter Question
    By atb in forum Qt Programming
    Replies: 3
    Last Post: 18th March 2008, 11:28
  5. Converting MFC CDC::Arc(..) to QPainter->drawArc
    By maverick_pol in forum Qt Programming
    Replies: 8
    Last Post: 26th September 2007, 08:57

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Digia, Qt and their respective logos are trademarks of Digia Plc in Finland and/or other countries worldwide.