QPainterPath line to curve
-
I have drawn a straight line using QPainterPath.
[code]
QPainter painter(this);
QPainterPath path;
path.moveTo(QPointF(B_Point));
path.lineTo(QPointF(D_Point));
painter.drawPath(m_BiscepLoopPath);
[/code]
BD is a straightline. Now I have to modify this line to a curve so that BD length become 100 pixel. Stright line BD length is only 50. so the line has bend startpoint B and endpoint D remains same but it should match the length to be 100.Please help me how can I do it.? Thanks Sujan
-
Hi,
Will "quadTo":http://qt-project.org/doc/qt-5.0/qtgui/qpainterpath.html#quadTo help you? But don't know how to make the curve exactly 100 pixels.
-
basically it's the following:
@
QPointF c;
//calculate c
QPainter painter(this);
QPainterPath path;
path.moveTo(QPointF(B_Point));
path.quadTo(c,QPointF(D_Point));
painter.drawPath(path);
@
The hard part is doing the math to "calculate the arc length":http://en.wikipedia.org/wiki/Curve_length and the control point.
See "this":http://stackoverflow.com/questions/15445260/javascript-canvas-curve-with-fixed-length for example. -
how can we control the length of the curve drawn.
-
I have a length of 100 my curve should be a length of 100. how can we give this as input and find the control point.