JKQtPlotter/examples/parametriccurve
jkriege2 b0df7a1fd7 NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static)
NEW/BREAKING: refactor CMake-Code, so static/dynamic switch is done via <code>BUILD_SHARED_LIBS</code>, which retires <code>JKQtPlotter_BUILD_STATIC_LIBS</code>, <code>JKQtPlotter_BUILD_SHARED_LIBS</code> and removes the capability to build static and shared libraries in one location (fixes issue #104)
NEW: prepareed library for CMake's <a href="https://cmake.org/cmake/help/latest/module/FetchContent.html">FetchContent</a>-API
NEW: the different sub-libraries JKQTPlotter, JKQTFastPlotter (DEPRECATED), JKQTMath, JKQTMathText can be activated/deactivated with CMake options JKQtPlotter_BUILD_LIB_JKQTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTFASTPLOTTER, JKQtPlotter_BUILD_LIB_JKQTMATHTEXT, JKQtPlotter_BUILD_LIB_JKQTMATH
2024-01-16 13:07:08 +01:00
..
CMakeLists.txt NEW/BREAKING: provide general targets JKQTPlotter5/6::JKQTPlotter5/6, JKQTPlotter5/6::JKQTMathText5/6, ... which are independent of the type of build (shared/static) 2024-01-16 13:07:08 +01:00
parametriccurve_and_lib.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00
parametriccurve.cpp updated many documentation images to auto-generated ones 2022-08-28 22:48:14 +02:00
parametriccurve.pro using CMake now to build examples 2019-06-20 22:24:47 +02:00
README.md fixed rename setPalette()->setColorPalette() in examples 2020-09-11 15:28:56 +02:00

Example (JKQTPlotter): Plotting Parametric Curves

This project (see ./examples/parametriccurve/) demonstrates how to draw parametric curves [x,y]=f(t), using JKQTPXYLineGraph and JKQTPXYParametrizedScatterGraph, i.e. from a set of coordinates [xi,yi], for which the vector-values function f(t) is evaluated explicitly. If you are alloking for an example of implicit drawing by only defining the function f(t) and having JKQTPlotter evaluate it automatically and adaptively, you'll have to use JKQTPXYFunctionLineGraph, which is explained in ./examples/evalcurve

The source code of the main application can be found in parametriccurve.cpp. First, the parametric curve (here a logarithic spiral) is sampled into two columns containing the x- and y-values along the curve. In addition the radial distance from x=y=0 is added into a third column:

    QVector<double> X, Y, R;
    const int Ndata=500; // number of plot points in each curve
    const double phiMax=4.0*M_PI;
    const double a=1;
    const double k=0.2;
    for (double phi=-phiMax; phi<=phiMax; phi+=phiMax/double(Ndata)) {
        const double x=a*exp(k*phi)*cos(phi);
        const double y=a*exp(k*phi)*sin(phi);
        X<<x;
        Y<<y;
        R<<sqrt(x*x+y*y);
    }
    // and copy it to the datastore
    size_t columnX=ds->addCopiedColumn(X, "x");
    size_t columnY=ds->addCopiedColumn(Y, "y");
    size_t columnR=ds->addCopiedColumn(R, "r");

Then simples graph just uses the columns X and Y to plot the curve:

    JKQTPXYLineGraph* graph1=new JKQTPXYLineGraph(&plot);
    graph1->setXColumn(columnX);
    graph1->setYColumn(columnY);
    graph1->setDrawLine(true);
    graph1->setSymbolType(JKQTPNoSymbol);
    graph1->setTitle("one-colored spiral");
    plot.addGraph(graph1);

If you use JKQTPXYParametrizedScatterGraph instead of JKQTPXYLineGraph, you can also modify the color of the line-segments, connecting the datapoints:

    JKQTPXYParametrizedScatterGraph* graph2=new JKQTPXYParametrizedScatterGraph(&plot2);
    graph2->setXColumn(columnX);
    graph2->setYColumn(columnY);
    graph2->setColorColumn(columnR);
    graph2->setColorPalette(ette(JKQTPMathImageMATLAB);
    graph2->setSymbolType(JKQTPNoSymbol);
    graph2->setDrawLine(true);
    graph2->setTitle("colored spiral");
    graph2->getColorBarRightAxis()->setAxisLabel("color scale radius $r(\\phi)$");
    plot2.addGraph(graph2);

The result looks like this:

parametriccurve

... and with the line-color set by the radius:

parametriccurve