Results 1 to 5 of 5

Thread: qwtpolar plot clockwise

  1. #1
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Default qwtpolar plot clockwise

    I need a polar plot that runs 0 - 360 clockwise instead of counter-clockwise. If I set the azimuth scale to 360 to 0 instead of 0 to 360 I get the desired result except I have 360 on my zero line instead of zero. Is there a way to make it run clockwise and read 0 on the origin?

  2. #2
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 879 Times in 827 Posts

    Default Re: qwtpolar plot clockwise

    Have a look at the spectrogram example - here you can rotate and mirror the plot using buttons on the toolbar ( at least the version in trunk has it ).

    Uwe

  3. The following user says thank you to Uwe for this useful post:

    TonyInSoMD (19th March 2015)

  4. #3
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Default Re: qwtpolar plot clockwise

    I'm doing this using a 0 degree to 360 degree azimuth scale. I also need 0 to be on the north of the plot.
    OK, I tried using the mirror example, using:

    m_pPolarPlot->setScale(QwtPolar::Azimuth,360,0,10);
    m_pPolarPlot->setAzimuthOrigin(M_PI_2);

    At the origin it shows 360 instead of 0. I need it to show 0 instead of 360.
    If I eliminate the second line, it still shows 360 at the origin.
    If I do it using radians instead of degrees it works fine, but I need it to work in a 0 to 360 degree format.

    I tried to add a screenshot, but the firewall (I think it's because of the firewall) won't let me. Our IT department has a habit of making it impossible to do anything on the net. I'm lucky I can even open this website.


    Added after 45 minutes:


    I made a mistake, it does the same thing using radians as it does using degrees.
    Last edited by TonyInSoMD; 10th March 2015 at 11:22.

  5. #4
    Join Date
    Feb 2006
    Location
    Munich, Germany
    Posts
    3,325
    Qt products
    Qt3 Qt4 Qt/Embedded
    Platforms
    MacOS X Unix/X11 Windows
    Thanked 879 Times in 827 Posts

    Default Re: qwtpolar plot clockwise

    Quote Originally Posted by TonyInSoMD View Post
    If I do it using radians instead of degrees it works fine, but I need it to work in a 0 to 360 degree format.
    You always have two coordinates systems - plot coordinates and coordinates of the "paint device". In case of a linear scale the second coordinate system is in widget coordinates, in case of the azimuth it is always 0 -> 2 * PI .
    As you can't set the origin of a coordinate system in its own coordinates, the azimuth has to be given in radians.

    So the azimuth origin is simply the angle ( in radians ), where your plot coordinate system ( whatever it is ) starts.

    Uwe

  6. #5
    Join Date
    Mar 2014
    Location
    USA
    Posts
    85
    Qt products
    Qt5
    Platforms
    Windows
    Thanks
    17
    Thanked 2 Times in 2 Posts

    Default Re: qwtpolar plot clockwise

    If you noticed I posted immediately after your quote that I was wrong, it did NOT work in radians.

    Here's a copy of my code. All it shows is the plot and some very simple data. What am I doing wrong and where?


    ui.setupUi(this);
    m_pPainter = new QPainter(this);
    m_pPainter->setRenderHint(QPainter::Antialiasing,true);
    m_pPainter->setClipRect(m_rect_PaintRect);
    m_pPolarPlot = new QwtPolarPlot(ui.m_frame_Graph);
    m_pPolarPlot->setScale(QwtPolar::Azimuth,360,0,10);
    m_pPolarPlot->setScale(QwtPolar::Radius,-40,40,10);
    m_pPolarPlot->setAzimuthOrigin(M_PI_2);
    m_grid_PolarPlot.showGrid(QwtPolar::Azimuth,true);
    m_grid_PolarPlot.showGrid(QwtPolar::Radius,true);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisAzimuth,tr ue);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisBottom,tru e);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisLeft,true) ;
    m_grid_PolarPlot.showAxis(QwtPolar::AxisRight,true );
    m_grid_PolarPlot.showAxis(QwtPolar::AxisTop,true);
    m_grid_PolarPlot.attach(m_pPolarPlot);
    QVector< QwtPointPolar > PolarPoints;
    PlotCurve = new QwtPolarCurve();
    int nSeriesSize = 10;
    for(int nPoint = 0; nPoint < nSeriesSize; nPoint++)
    {
    PolarPoints.append(QwtPointPolar(nPoint,nPoint * 3));
    }
    PlotCurve->setPen(QPen(Qt::green));
    PlotCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QBrush(Qt::blue),QPen (Qt::blue),QSize(2,2)));
    PlotCurve->setData(new CPolarData(PolarPoints,nSeriesSize));
    PlotCurve->attach(m_pPolarPlot);
    m_pPanner = new QwtPolarPanner(m_pPolarPlot->canvas());
    m_pPanner->setEnabled(true);
    m_pMagnifier = new QwtPolarMagnifier(m_pPolarPlot->canvas());
    m_pMagnifier->setEnabled(true);

    With this code I get 360 at the north, 90 at the east, 180 at the south, and 270 at the west. It graphs in a clockwise direction. Everything is great except I need it to be 0 instead of 360.

    I'm pretty stupid, the previously given answer made absolutely no sense to me. I couldn't figure out what was being said. That's why I included my test code.

    I got to thinking about it, if this isn't enough I can also post the .h and the CPolarData class which has the data structure. The CPolarData is just an implementation of QwtSeriesData<QwtPointPolar> and all it contains is the 2 variable data structure for the data.



    // CPolarData.h file

    #ifndef CPOLARDATA_H
    #define CPOLARDATA_H

    #include <qwt_series_data.h>

    class CPolarData : public QwtSeriesData<QwtPointPolar>
    {

    public:
    CPolarData();
    CPolarData( const QVector< QwtPointPolar > &vector_DataPoints, const size_t &nSeriesSize );
    ~CPolarData();

    virtual QwtPointPolar sample( size_t nSeriesIndex ) const;
    virtual size_t size () const;
    virtual QRectF boundingRect() const;
    void SetDataPoints(QVector< QwtPointPolar > vector_DataPoints);

    private:
    QVector< QwtPointPolar > m_vector_DataPoints;
    size_t m_nSeriesSize;

    };

    #endif // CPOLARDATA_H


    // CPolarData.cpp file

    #include "cpolardata.h"

    CPolarData::CPolarData()
    {
    }

    CPolarData::CPolarData( const QVector< QwtPointPolar > &vector_DataPoints, const size_t &nSeriesSize )
    : QwtSeriesData<QwtPointPolar>()
    {
    m_vector_DataPoints = vector_DataPoints;
    m_nSeriesSize = nSeriesSize;
    }

    CPolarData::~CPolarData()
    {

    }

    QwtPointPolar CPolarData:: sample(size_t nSeriesIndex) const
    {
    return m_vector_DataPoints[nSeriesIndex];
    }

    void CPolarData::SetDataPoints(QVector< QwtPointPolar > vector_DataPoints)
    {
    m_vector_DataPoints = vector_DataPoints;
    }

    size_t CPolarData::size() const
    {
    return m_nSeriesSize;
    }

    QRectF CPolarData::boundingRect() const
    {
    return qwtBoundingRect( *this );
    }


    // CPolFilePolarGraph.h file

    #ifndef CPOLFILEPOLARGRAPH_H
    #define CPOLFILEPOLARGRAPH_H

    #include <QMainWindow>
    #include "ui_cpolfilepolargraph.h"
    #include "qwt_polar_plot.h"
    #include "qwt_polar_grid.h"
    #include "cpolardata.h"
    #include "qwt_polar_curve.h"
    #include <qwt_polar_panner.h>
    #include <qwt_polar_magnifier.h>

    class CPolFilePolarGraph : public QMainWindow
    {
    Q_OBJECT

    public:
    CPolFilePolarGraph(QWidget *parent = 0);
    ~CPolFilePolarGraph();

    protected:
    virtual void paintEvent(QPaintEvent *event);

    private:
    Ui::CPolFilePolarGraph ui;
    QwtPolarPlot *m_pPolarPlot;
    QRect m_rect_PaintRect;
    QPainter *m_pPainter;
    QwtPolarGrid m_grid_PolarPlot;
    CPolarData m_PolarData;
    QwtPolarCurve *PlotCurve;
    QwtPolarPanner *m_pPanner;
    QwtPolarMagnifier *m_pMagnifier;
    };

    #endif // CPOLFILEPOLARGRAPH_H



    // CPolFilePolarGraph.cpp file

    #include "cpolfilepolargraph.h"
    #include "qwt_series_data.h"
    #include "qwt_symbol.h"
    #include "qwt_scale_div.h"


    CPolFilePolarGraph::CPolFilePolarGraph(QWidget *parent)
    : QMainWindow(parent)
    {
    ui.setupUi(this);
    m_pPainter = new QPainter(this);
    m_pPainter->setRenderHint(QPainter::Antialiasing,true);
    m_pPainter->setClipRect(m_rect_PaintRect);
    m_pPolarPlot = new QwtPolarPlot(ui.m_frame_Graph);
    m_pPolarPlot->setScale(QwtPolar::Azimuth,360,0,10);
    m_pPolarPlot->setScale(QwtPolar::Radius,-40,40,10);
    m_pPolarPlot->setAzimuthOrigin(M_PI_2);
    m_grid_PolarPlot.showGrid(QwtPolar::Azimuth,true);
    m_grid_PolarPlot.showGrid(QwtPolar::Radius,true);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisAzimuth,tr ue);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisBottom,tru e);
    m_grid_PolarPlot.showAxis(QwtPolar::AxisLeft,true) ;
    m_grid_PolarPlot.showAxis(QwtPolar::AxisRight,true );
    m_grid_PolarPlot.showAxis(QwtPolar::AxisTop,true);
    m_grid_PolarPlot.attach(m_pPolarPlot);
    QVector< QwtPointPolar > PolarPoints;
    PlotCurve = new QwtPolarCurve();
    int nSeriesSize = 10;
    for(int nPoint = 0; nPoint < nSeriesSize; nPoint++)
    {
    PolarPoints.append(QwtPointPolar(nPoint,nPoint * 3));
    }
    PlotCurve->setPen(QPen(Qt::green));
    PlotCurve->setSymbol(new QwtSymbol(QwtSymbol::Ellipse,QBrush(Qt::blue),QPen (Qt::blue),QSize(2,2)));
    PlotCurve->setData(new CPolarData(PolarPoints,nSeriesSize));
    PlotCurve->attach(m_pPolarPlot);
    m_pPanner = new QwtPolarPanner(m_pPolarPlot->canvas());
    m_pPanner->setEnabled(true);
    m_pMagnifier = new QwtPolarMagnifier(m_pPolarPlot->canvas());
    m_pMagnifier->setEnabled(true);
    }

    CPolFilePolarGraph::~CPolFilePolarGraph()
    {

    }

    void CPolFilePolarGraph:aintEvent(QPaintEvent *event)
    {
    QMainWindow:aintEvent(event);
    m_rect_PaintRect = ui.m_frame_Graph->rect();
    m_pPainter->setClipRect(m_rect_PaintRect);
    m_pPolarPlot->setGeometry(m_rect_PaintRect);
    m_pPolarPlot->update();
    }


    This is my code in its entirety. You can plug it in and it runs. The only reason I didn't just attach the files is the firewall won't let me.
    Last edited by TonyInSoMD; 10th March 2015 at 14:59. Reason: Here's the entire project

Similar Threads

  1. How to draw a line anywhere on qwtpolar plot
    By vishaal_sss in forum Qwt
    Replies: 0
    Last Post: 23rd December 2014, 07:23
  2. SVG background on a Qwtpolar Plot
    By john_k in forum Qwt
    Replies: 1
    Last Post: 30th November 2014, 09:47
  3. Replies: 9
    Last Post: 3rd November 2014, 20:44
  4. Replies: 2
    Last Post: 18th December 2011, 23:34
  5. QwtPolar: Plot using a 2-dimensional array
    By hgstoehr in forum Newbie
    Replies: 0
    Last Post: 14th December 2011, 21:39

Tags for this Thread

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  
Qt is a trademark of The Qt Company.