2

i would love to draw the surface between à two sinus curves. the two sinus curves have the same base of time it mean the x of first point of my two sinus are the same also the second point....

so how can i do that? my idea is to draw a bunchs of lines between the 2 sinus points but i didn't find a function in the qwt that allow me to draw lines between two point that have the same x and different y .

if you have a better idea i would love to listen to it and if some one have already done this it would be perfect to have an idea

you can find a little exemple of what i want to do bellow.

the grey part is exactly what I'am aiming for . thank all of you for your help

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241
  • If you know the function for each sine curve, you could try to determine for each point with coords x,y in the output frame buffer whether it is located between the two curves, and draw the pixel if the condition is true. – SirDarius Feb 20 '20 at 13:03
  • You could create a polygon that first traces points along the upper line left to right and then traces back (right to left) along the lower line. What do you have now? – Botje Feb 20 '20 at 13:08
  • hello guys thanks for your response so i connected all my points it gave me a close area and when i used setbrush for the color of my area it didn't work. so i used first setstyle and i choosed style "line" then i used setRawSamples then draw my polygone using QwtPainter::drawPolygon(painter, polyline ), and to finish i used . but didn't work – Omar Messari Feb 21 '20 at 08:16

1 Answers1

1

You can use QwtPlotIntervalCurve:

#include <QtWidgets>

#include <qwt_plot.h>
#include <qwt_plot_curve.h>
#include <qwt_plot_intervalcurve.h>

#include <cmath>

static double f(double x, double A, double W, double B){
    return A * std::sin(W * x) + B;
}

int main(int argc, char *argv[])
{
    QApplication a(argc, argv);

    const double deltax = .1;
    const int size = 100;
    QVector<QwtIntervalSample> rangeData(size);
    QVector<QPointF> lowData(size);
    QVector<QPointF> upperData(size);

    for(int i=0; i <size; ++i){
        double x = deltax * i;
        double ylow = f(x, 1, 4, -10);
        double yupper = f(x, 1, 2, 10);
        lowData[i] = QPointF(x, ylow);
        upperData[i] = QPointF(x, yupper);
        rangeData[i] = QwtIntervalSample(x, QwtInterval(ylow, yupper));
    }

    QwtPlot plot;

    QColor bg(Qt::gray);
    bg.setAlpha(150);

    QwtPlotCurve lowcurve;
    lowcurve.setRenderHint( QwtPlotItem::RenderAntialiased );
    lowcurve.setPen(QPen(Qt::gray, 5));
    lowcurve.setSamples(lowData);
    lowcurve.attach(&plot);

    QwtPlotCurve uppercurve;
    uppercurve.setRenderHint( QwtPlotItem::RenderAntialiased );
    uppercurve.setPen(QPen(Qt::gray, 5));
    uppercurve.setSamples(upperData);
    uppercurve.attach(&plot);

    QwtPlotIntervalCurve curve;
    curve.setRenderHint( QwtPlotItem::RenderAntialiased );
    curve.setPen(Qt::white);
    curve.setBrush(bg);
    curve.setStyle(QwtPlotIntervalCurve::Tube);
    curve.setSamples( rangeData );
    curve.attach(&plot);

    plot.resize(640, 480);
    plot.show();

    return a.exec();
}

enter image description here

eyllanesc
  • 235,170
  • 19
  • 170
  • 241