PDA

View Full Version : qwtpolar plot clockwise



TonyInSoMD
9th March 2015, 16:58
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?

Uwe
9th March 2015, 19:27
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

TonyInSoMD
10th March 2015, 11:22
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.

Uwe
10th March 2015, 11:33
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

TonyInSoMD
10th March 2015, 13:37
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::paintEvent(QPaintEvent *event)
{
QMainWindow::paintEvent(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.