Search code examples
c++qtqmlqtquick2qwt

How to get Y coordinate of plot curve depending on its X coordinate (QWT)?


There's a code based on QML and QWT, kind of a graph maker with additional possibilities. One of the technical requirements is to get Y coordinate of a plot curve depending on some X coordinate.

There's an inaccurate way to do it - get the QPoint of QwtPlotCurve closest sample to some X coordinate.

int sampleIndex = curve->closestPoint(plotCanvas->mapFromGlobal(event->pos()));
QPointF sample = curve->sample(sampleIndex);

The most problem is that QwtPlotCurve can provide only samples coordinates, but I need to be able to get coordinates between samples as well. For example:

[Explanation (image)]

How to get Y curve coordinate if I know any X coordinate, not only sample?


Solution

  • If you are able to determine at least two points on each lines, then there is a mathematical solution to the problem. The complete explanation is here Line–line intersection