1 Attachment(s)
Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
I'm trying to draw rays on a phasor coordinate plane and I have no idea what function to use or any example code that I could follow, in the Qwt Polar Documentation I found a drawRays method but the arguments are way too confusing. I'm using a QwtPhasorGrid. Could someone who has done this before help me, preferably with code examples? Thanks!
Here's my code:
Attachment 7292
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
There is no QwtPhasorGrid and the code you have posted shows nothing - so what do you want to display how ?
Uwe
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
Well, I'm trying to draw rays on a polar coordinate plane, the code in my first post will display a polar coordinate grid but I don't know how to plot a ray from the origin given the degrees and magnitude of the line. I was kind of forced to use something that someone didn't finish and he is now gone.
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
Quote:
Originally Posted by
bwnicewo
Well, I'm trying to draw rays on a polar coordinate plane, the code in my first post will display a polar coordinate grid but I don't know how to plot a ray from the origin given the degrees and magnitude of the line.
The grid lines are rendered according to the ticks of the scales. If you want to to modify the grid ( having lines at different angles ) you have to modify the scale for the azimuth ( QwtPolar::AxisAzimuth ) - or configure the autoscaler that is responsible for calculating this scale. Check the QwtPolarPlot::setAxisXY methods.
You can change the pen, that is used for drawing the grid lines by QwtPolarGrid::setMajorGridPen/setMinorGridPen - if this is what you mean by magnitude.
In general drawing something to a plot widget is done by configuring and attaching Qwt plot item - or implementing your own type of plot items.
Uwe
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
Yeah, I wanted to attach an item to the plot, but I'm worried that I'll have to impliment my own plot item for just drawing a simple line from the origin, I would think there should just be a function to draw a line like drawLine or something that takes the length of the line and angle of the line.
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
You can't simply draw to a widget - this is not how Qt works. On most platforms you can't event paint outside paint events at all. You also need to take care of the plot -> widget transformation, that is changing on different type of layout events or when zooming in/out. But having a class around a couple of lines of render code ( this is what your is plot item about) is nothing to be afraid of.
QwtPlotMarker has a mode for drawing such a line - but I simply forgot to add a similar feature to QwtPolarMarker.
Uwe
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)
What I have now to post the data is this:
d_grid = new QwtPolarGrid();
d_grid->setPen(QPen(Qt::white));
for ( int scaleId = 0; scaleId < QwtPolar::ScaleCount; scaleId++ )
{
d_grid->showGrid(scaleId);
d_grid->showMinorGrid(scaleId);
QPen minorPen(Qt::gray);
#if 0
minorPen.setStyle(Qt::DotLine);
#endif
d_grid->setMinorGridPen(scaleId, minorPen);
}
d_grid->setAxisPen(QwtPolar::AxisAzimuth, QPen(Qt::black));
d_grid->showAxis(QwtPolar::AxisAzimuth, true);
d_grid->showAxis(QwtPolar::AxisLeft, false);
d_grid->showAxis(QwtPolar::AxisRight, false);
d_grid->showAxis(QwtPolar::AxisTop, false);
d_grid->showAxis(QwtPolar::AxisBottom, false);
d_grid->showGrid(QwtPolar::Azimuth, true);
d_grid->showGrid(QwtPolar::Radius, true);
d_grid->attach(this);
// curves
m_curve = new QwtPolarCurve();
m_curve->setPen(QPen(Qt::red));
m_curve->setData(SinData(0,10));
m_curve->setPen(QPen(Qt::red));
m_curve->attach(this);
replot();
SinData is a class to return a QwtData pointer to setData, the arguments are an angle offset and amplitude of the line respectively. I'm attaching it to a QwtPolarPlot, the problem is I'm not seeing anything on the grid.
This wasn't my code, someone else wrote it.
Re: Phasor Plotting with QwtPolar (drawing rays on a polar coordinate grid)