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!