JKQtPlotter/examples/geo_bezier/README.md
2024-02-14 00:10:48 +01:00

1.5 KiB

Example (JKQTPlotter): Plotting Bezier Curves

This project shows the capabilities of JKQTPlotter to also draw arrows as geometric elements, using JKQTPGeoBezierCurve.

The source code of the main application can be found in geo_bezier.cpp. First a plot is generated. Then several types of bezier curves are added to the plot and their control points shown.

Here is an example for drawing a cubic bézier curve:

    JKQTPGeoBezierCurve* bezCubic=new JKQTPGeoBezierCurve(&plot);
    bezCubic->setCubic(QPointF(0.25,0.25), QPointF(0.8,2.5), QPointF(3.25,0.2), QPointF(3.75,2.75));
    bezCubic->setLineColor(QColor("maroon"));
    bezCubic->setHeadDecoratorSizeFactor(JKQTPArrow);
    bezCubic->setTailDecoratorSizeFactor(JKQTPArrow);
    plot.addGraph(bezCubic);

Finally we also add symbols for each control point and a poly-line connecting them:

    JKQTPGeoPolyLines* l2;
    plot.addGraph(l2=new JKQTPGeoPolyLines(&plot, bezCubic->getPoints()));
    l2->setLineColor(QColor("darkgrey"));
    l2->setLineWidth(1);
    JKQTPXYScatterGraph* scatCubic=new JKQTPXYScatterGraph(&plot);
    scatCubic->setXYColumns(plot.getDatastore()->addCopiedPoints(bezCubic->getPoints()));
    scatCubic->setSymbolColor(QColor("blue"));
    scatCubic->setSymbolType(JKQTPCircle);
    plot.addGraph(scatCubic);

Here is the resulting plot:

geo_bezier