PDA

View Full Version : draw a curve on qt



ramy
19th December 2014, 15:05
Hi,

I'm trying to draw an helix on a qt dialog or widget but it's not working!

here are the parametric equations of an helix in 2d.

x=30*cos(2*pi*t)
y=t;

that's what i have written so far in the paintEvent function
but the curve does not appear;

void MainWindow::paintEvent(QPaintEvent *){
QPainter paint(this);
for(qreal i=0;i<2*M_PI;i=i+0.1){
y=+300*cos(i); // I know that i did not use the same values that i have written above, i don't care about the values as long
QPoint T(y,i); // as i can draw a random helix!
polygon.push_back(T);
}
paint.drawPolygon(polygon);

}



PS: i don't want to use a graph. Actually i'm trying to draw a spring i need it for a project i'm working on

Thanks For your help :)

anda_skoa
19th December 2014, 15:22
Have you checked that the values you are generating are within the visible range?

0 <= x <= width()
0 <= y <= height()

Cheers,
_

ramy
19th December 2014, 15:44
Thanks anda_skoa, but i have found the problem!

d_stranz
19th December 2014, 16:58
but i have found the problem!

The purpose of this forum is not just to ask questions, but to also give your solution when you get something working. Telling the world that "I solved it" isn't very helpful to the rest of the forum readers who don't know what you did wrong.