Ask Your Question

Revision history [back]

click to hide/show revision 1
initial version

Sagitta to arc angle start and span

In c++ with Qt we have QPainterPath path;

path.moveTo(startX, startY);
path.arcTo(x, y, width, height, startAngle, spanAngle);
painter.drawPath(path);

Computing startX, startY,endX,endY:

double theta = startAngle * M_PI / 180.0;  // deg->radians
double rx = width / 2.0;
double ry = height / 2.0;
double x0 = x + rx;
double y0 = y + ry;
double startX = x0 + rx * cos(theta);
double startY = y0 - ry * sin(theta);  // sign because Y grows to down

double thetaEnd = (startAngle + spanAngle) * M_PI / 180.0; 
double endX = x0 + rx * cos(thetaEnd);
double endY = y0 - ry * sin(thetaEnd);

We can restrict ellipses to circles, ellipses are too difficult, especially ellipses can be rotated if rx=ry=r sagitta = r - sqrt(r² – (chordLength/2)²) where chordLength = sqrt((endX-startX)²+(endY-startY)²)

Now, we have start and end point and sagitta, how to compute enclosing box (that is radius and center) and angle arc start and span?