QPainter drawArc question
-
Hi. I'm trying to use QPainter drawArc(const QRectF & rectangle, int startAngle, int spanAngle) for arc drawing.
And have a problem with it.
I have a coordinates of 3 arc points A, B, C.
A - arc start point
B - arc end point
C - arc center with known radius (10).Question. How to calculate rectangle, startAngle and spanAngle for this arc?
Look Arc Image
-
NOT TESTED, JUST MATH (and i hope it is correct ^^)
eg.: Ax - x coordinate of A point, atan === ArcTan, abs === AbsoluteValue
Rect Top Left Point: (Ax,By)
Rect Bottom Right Point: (Cx+R,Cy+R)
...or minus im not sure about the coordinate system inside drawing but i think youll get the point i hope
Remember 0 Degree is at 3 o'clock so:
Angle to B point:
atan( abs(By-Cy) / abs(Bx-Cx) ) * 16 (it should be in 1/16th Degree thats why *16)
Angle to A Point:
(-90 - atan( abs(Cx-Ax) / abs(Ay-Cy))) * 16 (90 couse 0 is at 3 o'clock, "-" because clockwise)