# Thread: Qwt Plot Curve and Marker Precision with Doubles

1. Beginner
Join Date
Oct 2016
Posts
5
Qt products
Platforms

## Qwt Plot Curve and Marker Precision with Doubles

Hi,

I am working on a plot where the X axis is a 24 hour clock. Each 1.0 on the X axis equates to 1 second. But I also work with milliseconds, e.g 12.3. Basically, I am trying to place markers on the curve with millisecond precision, however after several zoom levels the markers diverge from the curve coordinates.

A sample of my code is:

for (int i = 0; i < curve->dataSize(); i++)
{
if (12.3 < curve->sample(i).x())
{
xDist = std::abs(curve->sample(i).x() - 12.3);
yDist = std::abs(curve->sample(i).y() - curve->sample(i + 1).y();
yValue = (yDist * xDist) + curve->sample(i).y();
break;
}
}

If there are syntax/spelling mistakes it is probably because I had to type this on my phone. However, this code partly does what I want. As at the highest level it looks perfect, but when I zoom in to values on my y axis with 3 or more decimal places the marker no longer follows the curve, instead hovering around the curve.

Therefore, I am looking for some advice on this. Is there a better/more precise way to find the y value of a curve based on its x axis value? Or is there some way to limit the level of zoom I can apply to a plot? I would prefer the former solution but am happy for any help.

2. Uwe
Expert
Join Date
Feb 2006
Location
Munich, Germany
Posts
3,293
Thanked 876 Times in 824 Posts
Qt products
Platforms

## Re: Qwt Plot Curve and Marker Precision with Doubles

Originally Posted by Krippy
Basically, I am trying to place markers on the curve with millisecond precision, however after several zoom levels the markers diverge from the curve coordinates.
Better overload one of the QwtPlotCurve::draw methods and do your interpolation in paint device coordinates. QPainter::drawLine does all you need.

Uwe