PDA

View Full Version : drawing clothoid segments



schmimona
30th July 2011, 12:19
Hi,

I am trying to create an application which the user can use to graphically draw clothoid (Euler spiral) segments, i.e. the user should be able to shape the curve only by using the mouse.

But I am at loss at to which drawing method I should use. I thought of drawing them as Bezier curves but the data is not compatible. How can I paint in Qt curves with specific data, such as curvatures and arc length?

Thanks in advance.

SixDegrees
30th July 2011, 12:59
You have to map your plotting onto the existing Qt (or OpenGL) graphics primitives. The only available mapping I can see is to individual points or line segments; in other words, you'll have to plot the curves yourself. I could be wrong; there may be a way to express these curves or approximate them using Bezier representation, but if there is it isn't apparent in the short time I spent looking at the math.

The math for calculating the plot doesn't seem terribly complicated, so doing this in "real time" isn't likely to cause any problems. If the processor starts to bog down, you could adopt a method using successive refinement, beginning with a fairly wide plotting interval and polishing at pixel resolution when the low-res version is done or the mouse stops moving.

schmimona
30th July 2011, 16:02
Is there an example code which I could run? For the curve plotting I mean.

SixDegrees
30th July 2011, 16:13
Is there an example code which I could run? For the curve plotting I mean.

I haven't looked. The math is described on Wikipedia and several other places.

schmimona
30th July 2011, 19:12
When you were saying plotting curves myself did you have some method in mind? Or were you referring to the QWT library?

SixDegrees
31st July 2011, 10:41
Either way. You can plot points (or, more likely, line segments) in QPainter, or you can embed a Qwt plot in your UI.

Cruz
31st July 2011, 12:03
Parameterize your clothoid curve such that you can obtain the x(t) and y(t) coordinates for a parameter t in [0:1] where 0 is the starting point and the 1 is the last point of your curve. Then you can simply draw your curve in the paint event of a widget like this:



void SimpleExampleWidget::paintEvent(QPaintEvent *)
{
QPainter painter(this);
painter.setPen(Qt::blue);

for (double t = 0; t <= 1; t = t+0.01)
painter.drawLine(QLineF(x(t), y(t), x(t+0.01), y(t+0.01));
}