Results 1 to 2 of 2

Thread: Angles in QPainterPath::arcTo

  1. #1
    Join Date
    Mar 2010
    Posts
    2
    Thanks
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Angles in QPainterPath::arcTo

    I'm trying to draw the piece of an ellipse between two points on the ellipse. I plug in what I think makes sense for the start angle and span length in QPainterPath::arcTo, but the results are not what I expect. Here's what I mean:

    Qt Code:
    1. #include <QtGui>
    2. #include <cmath>
    3. #include <algorithm>
    4. #include <iostream>
    5.  
    6.  
    7. using namespace std;
    8.  
    9.  
    10. static const bool PATH_NOT_ELLIPSE = true;
    11. static const double PI = 3.14159265359;
    12. static const double A = 300.0;
    13. static const double B = 200.0;
    14. static const double XSTART = 200.0;
    15. static const double YSTART = B/A*sqrt( A*A - XSTART*XSTART );
    16. static const double XEND = 100.0;
    17. static const double YEND = B/A*sqrt( A*A - XEND*XEND );
    18.  
    19.  
    20. int main( int argc, char* argv[] )
    21. {
    22. QApplication app( argc, argv );
    23.  
    24. // Scene with axes
    25. QGraphicsScene* scene = new QGraphicsScene( -10.0, -400.0, 410.0, 410.0 );
    26. QGraphicsLineItem* xAxis = new QGraphicsLineItem( 0.0, 0.0, 375.0, 0.0 );
    27. QGraphicsLineItem* yAxis = new QGraphicsLineItem( 0.0, -375.0, 0.0, 0.0 );
    28. xAxis->setPen( QPen( Qt::red ) );
    29. yAxis->setPen( QPen( Qt::red ) );
    30. scene->addItem( xAxis );
    31. scene->addItem( yAxis );
    32.  
    33. // Piece of an ellipse
    34. double angleS = atan2( YSTART, XSTART );
    35. double angleE = atan2( YEND, XEND );
    36. if ( angleS < 0.0 ) angleS += 2.0*PI;
    37. if ( angleE < 0.0 ) angleE += 2.0*PI;
    38. double startAngle = min( angleS, angleE );
    39. double sweepLength = abs( angleS - angleE );
    40. if ( PATH_NOT_ELLIPSE )
    41. {
    42. path.arcTo( -A, -B, 2.0*A, 2.0*B, startAngle*180.0/PI,
    43. sweepLength*180.0/PI );
    44. = new QGraphicsPathItem( path );
    45. scene->addItem( ellipse );
    46. }
    47. else
    48. {
    49. = new QGraphicsEllipseItem( -A, -B, 2.0*A, 2.0*B );
    50. ellipse->setStartAngle( startAngle*180.0/PI*16 );
    51. ellipse->setSpanAngle( sweepLength*180.0/PI*16 );
    52. scene->addItem( ellipse );
    53. }
    54.  
    55. // Lines at the angles derived above
    56. = new QGraphicsLineItem( 0.0, 0.0, 400.0*cos( angleS ),
    57. -400.0*sin( angleS ) );
    58. lineS->setPen( QPen( Qt::darkYellow ) );
    59. scene->addItem( lineS );
    60. = new QGraphicsLineItem( 0.0, 0.0, 400.0*cos( angleE ),
    61. -400.0*sin( angleE ) );
    62. lineE->setPen( QPen( Qt::darkYellow ) );
    63. scene->addItem( lineE );
    64.  
    65. // Markers for intended start and end points of arc
    66. = new QGraphicsEllipseItem( XSTART - 5.0, -( YSTART + 5.0 ), 10.0,
    67. 10.0 );
    68. startPoint->setPen( QPen( Qt::darkGreen ) );
    69. scene->addItem( startPoint );
    70. = new QGraphicsEllipseItem( XEND - 5.0, -( YEND + 5.0 ), 10.0, 10.0 );
    71. endPoint->setPen( QPen( Qt::darkGreen ) );
    72. scene->addItem( endPoint );
    73.  
    74. QGraphicsView* view = new QGraphicsView( scene );
    75. view->show();
    76.  
    77. return app.exec();
    78. }
    To copy to clipboard, switch view to plain text mode 

    The points between which I want the segment are the greenish circles; the angles I used are represented by the dark yellow lines (which intersect the circles, of course), and the black line is what Qt gave me. Every example I can find used increments of 90 degrees, and for those cases, everything just works. Does anybody know how the angles are supposed to be defined? I've been using Qt 4.5.3 under Cygwin, if that matters. Thanks!

  2. #2
    Join Date
    Jan 2013
    Location
    Taiwan
    Posts
    1
    Qt products
    Qt4
    Platforms
    Unix/X11 Windows

    Default Re: Angles in QPainterPath::arcTo

    Does anyone reply?
    We're confused the definition of the angle, too!!

Similar Threads

  1. QPainterPath and QPolygon
    By Muz in forum Qt Programming
    Replies: 0
    Last Post: 18th September 2009, 07:16
  2. Reusing a QPainterPath
    By Micawber in forum Qt Programming
    Replies: 2
    Last Post: 19th March 2009, 19:49
  3. QPainterPath::arcTo accuracy
    By robertson1 in forum Qt Programming
    Replies: 0
    Last Post: 18th July 2008, 12:13
  4. QPainterPath.arcTo
    By grellsworth in forum Qt Programming
    Replies: 1
    Last Post: 18th March 2008, 17:36
  5. QPainterPath outlining
    By viridis in forum Qt Programming
    Replies: 2
    Last Post: 14th March 2008, 19:32

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.