【问题标题】:how to Draw A surface between 2 sinus cuves如何在两条正弦曲线之间绘制一个曲面
【发布时间】:2020-06-04 19:31:36
【问题描述】:

我很想画出两条正弦曲线之间的表面。两条窦曲线具有相同的时间基数,这意味着我的两条窦的第一个点的 x 也相同,第二个点也相同....

那我该怎么做呢?我的想法是在 2 个窦点之间画一堆线,但我没有在 qwt 中找到一个函数,可以让我在具有相同 x 和不同 y 的两个点之间画线。

如果你有更好的想法,我很想听听,如果有人已经这样做了,那么有一个想法就完美了

你可以在下面找到我想做的一些例子。

灰色部分正是我的目标。谢谢大家的帮助

【问题讨论】:

  • 如果您知道每条正弦曲线的函数,您可以尝试确定输出帧缓冲区中坐标为 x,y 的每个点是否位于两条曲线之间,如果条件为真。
  • 您可以创建一个多边形,首先沿着上面的线从左到右追踪点,然后沿着下面的线向后(从右到左)追踪。你现在有什么?
  • 大家好,感谢您的回复,所以我连接了我所有的点,它给了我一个封闭的区域,当我使用 setbrush 为我的区域颜色时,它不起作用。所以我首先使用了 setstyle 并选择了样式“line”,然后我使用了 setRawSamples,然后使用 QwtPainter::drawPolygon(painter, polyline) 绘制了我的多边形,并完成了我使用的。但没用

标签: c++ qt qwt


【解决方案1】:

你可以使用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();
}

【讨论】:

  • 好答案。但是我怎样才能水平地做到这一点?我的意思是,如何在每个 y 值的两个 x 值之间进行操作?谢谢。
  • @PauloCarvalho 这是另一个问题,所以我邀请您创建一个新帖子 :-)
猜你喜欢
  • 1970-01-01
  • 2021-08-16
  • 2019-01-26
  • 1970-01-01
  • 1970-01-01
  • 2017-02-18
  • 1970-01-01
  • 1970-01-01
  • 2019-08-15
相关资源
最近更新 更多