PDA

View Full Version : Arrow indicating the direction to the QWTPOLARPLOT Symbol.



aprado
14th May 2013, 21:00
Hello i've implemented a QWTPOLARPLOT arrow symbol, i've used it in my project to plot polar coordiantes. I don't know if you want to incorporate in QWTPolar but here is the code if someone needs it:


void PhasorArrow::drawSymbols(QPainter *painter, const QPointF *points, int numPoints) const
{

int off = 0;
QPen pen1 = pen();
if ( pen1.width() > 1 )
{
pen1.setCapStyle( Qt::FlatCap );
off = 1;
}
painter->setPen( pen1 );

/* Calculating the angle */
float x1 = points[0].x();
float x2 = points[1].x();
float y1 = points[0].y();
float y2 = points[1].y();
const float ang_diff = M_PI/9;
const float magnitude = 15.0;
float angulo = atan2((y2-y1),(x2-x1)) + M_PI;



float right_x = x2+magnitude*cos(angulo - ang_diff);
float right_y = y2+magnitude*sin(angulo - ang_diff);

float left_x = x2+magnitude*cos(angulo + ang_diff);
float left_y = y2+magnitude*sin(angulo + ang_diff);

float miolo = (x2-x1)*(x2-x1)+(y2-y1)*(y2-y1);
float mag = sqrt(miolo);

if (mag > 25)
{
QwtPainter::drawLine( painter, right_x, right_y, x2, y2 );
QwtPainter::drawLine( painter, left_x, left_y, x2, y2 );
}



}

You need to extend QwtSymbol in order to do it
Cheers