PainterPath Elements and Bezier Splines
-
Would someone confirm that arcs, quadratic Bezier splines and cubic Bezier spline path drawing is done using Bezier splines. I tried:
path2.arcMoveTo(100.0, 100.0, 100.0, 100.0, 30.0); path2.arcTo(100.0, 100.0, 100.0, 100.0, 30.0, 50); path3.moveTo(193.306, 124.991); path3.cubicTo(186.045, 112.445, 173.487, 103.346, 158.691, 100.753);
and
path4.moveTo(300.0, 300.0); path4.quadTo(400.0, 400.0, 500.0, 300.0); path5.moveTo(300.0, 300.0); path5.cubicTo(366.667, 366.667,433.333, 366.667, 500.0, 300.0);
I got those values from examining the values stored in the Elements for each operation. The output for each group overlapped.
-
It should draw them all. FYI, about cubic bezier,
Suppose you add a point in QVector<QPointF> m_points; whenever you press the mouse button.
Then you can draw a cubic bezier curve in every 3rd click by
if(m_points.size()>1 && m_points.size()%3 == 1){
int i = m_points.size()-3;
m_path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2));
}
Then use QGraphicsPathItem::setPath(path); to set in pathItem or use painter->drawPath(m_path); to draw in paint device. For more details, check out the pathstroke example in Qt. I found it is quite decent example. -
It should draw them all. FYI, about cubic bezier,
Suppose you add a point in QVector<QPointF> m_points; whenever you press the mouse button.
Then you can draw a cubic bezier curve in every 3rd click by
if(m_points.size()>1 && m_points.size()%3 == 1){
int i = m_points.size()-3;
m_path.cubicTo(m_points.at(i), m_points.at(i+1), m_points.at(i+2));
}
Then use QGraphicsPathItem::setPath(path); to set in pathItem or use painter->drawPath(m_path); to draw in paint device. For more details, check out the pathstroke example in Qt. I found it is quite decent example.@samdol
Thanks for your response. My question was not about how to create paths or how to drawn them. I show that using results from examining the elements from a path, it appears that the arc and quad paths are actually drawn as cubic Bezier splines. See data below. My interest was in determining whether I could use the Element data to reconstruct the original segments of the path. I have concluded that the only segment was a line or a polyline, because arc. quadratic Bezier splines and cubic Bezier splines have the same Element signature. I recall that someone had made a query about uses Elements to reconstruct the path object. If one whats to use paths for interactive graphics, then being limited to lines or polylines and cubic Bezier splines is OK. A cubic Bezier spline only approximates a circular arc, but is generally close enough: Interactive graphics is more concerned with having an aesthetically pleasing look and not absolute mathematical correctness.I guess my real question is can more be inferred from the Element data than I have stated?
Path Element Data
No of Elements 16
path1.moveTo(100.0, 200.0);
path1.lineTo(300.0, 200.0);
path1.lineTo(325.0, 250.0);
path1.lineTo(400.0, 300.0);0 QPointF(100,200)
1 QPointF(300,200)
1 QPointF(325,250)
1 QPointF(400,300)path1.arcMoveTo(100.0, 100.0, 100.0, 100.0, 30.0); path1.arcTo(100.0, 100.0, 100.0, 100.0, 30.0, 50.0);
0 QPointF(193.306,124.991)
2 QPointF(186.045,112.445)
3 QPointF(173.487,103.346)
3 QPointF(158.691,100.753)path1.moveTo(300.0, 300.0); path1.quadTo(400.0, 400.0, 500.0, 300.0);
0 QPointF(300,300)
2 QPointF(366.667,366.667)
3 QPointF(433.333,366.667)
3 QPointF(500,300)path1.moveTo(600.0, 300.0); path1.cubicTo(700.0, 500.0, 800.0, 500.0, 900.0, 600.0);
0 QPointF(600,300)
2 QPointF(700,500)
3 QPointF(800,500)
3 QPointF(900,600) -
I believe that I have answered my question. In QPainterPath method angleAtPercent() it states: "Note that similarly to the other percent methods, the percentage measurement is not linear with regards to the length if curves are present in the path. When curves are present the percentage argument is mapped to the t parameter of the Bezier equations." And in intersected() it notes: "Bezier curves may be flattened to line segments due to numerical instability of doing bezier curve intersections."
Both statements leads me to believe that cubic Bezier splines are used for all curves. Am I worng?