PDA

View Full Version : Get any point's Coordinates in a Curve



Schoumi
5th December 2011, 08:23
Hello,

I use a QwtPlotCurve with some points assign with setRawSamples. I want to get the X or Y cooridnates of a point in the curve using Y or X associated coordinate, but this point is not always a point that i use to create the curve.

Exemple:

i have two point to create the curve

pointA(0,0) and pointB(2,2) and i want to find the coordinate of the point in the curve coresponding to x = 1. in this case the point has 1,1 for coordinates.

is this is possible and how to do.
Thanks for your help.

FelixB
5th December 2011, 08:26
no, that is not possible. A QwtPlotCurve has a member to find the nearest point, but it can't interpolate. You have to code such a functionality by yourself, but that should be quite easy by applying some geometrical calculations.

hth,
Felix

Schoumi
5th December 2011, 10:05
Hum have you some link that explain how to calculate something like this.
With some points we have a line and it's simple to calculate a coordinate on the line, but with a large number of points it was not so easy or i'm wrong?

In fact my goal is to add a marker on an X coordinate and the Y coordinate move with the curve. Is it possible to do this without recalculating the Y coordinate each time? I didn't find a good way to do this without setting Y value each time. In some cases i need to find local extremum but in this cases i need to calculate this extremum but in case of interpolated curve, the extremum can not be a point use to create the curve, i'm right?

Uwe
6th December 2011, 06:04
Hum have you some link that explain how to calculate something like this.
With some points we have a line and it's simple to calculate a coordinate on the line, but with a large number of points it was not so easy or i'm wrong?

You are: each coordinate is between 2 curve points and this is always ( beside of splines ) a simple line. The number of curve points doesn't matter.

Uwe

Schoumi
6th December 2011, 08:03
hum ok, but in an interpolated curve, two points can be on each side of an extremum and obtain the extremum value could not be as easier as calculate a line equation between two point, because the result must not be on the curve, or i'm wrong again?

Thanks for your explanation

FelixB
6th December 2011, 08:39
Hi schuomi,

a QwtPlotCurve is not a "real" curve. It is a number of points that are connected by straight lines. So it is not possible that there is an extremum between two points.

If your curve uses interpolated data, you must access the "real" data storage to obtain the underlying values.

Felix

Schoumi
6th December 2011, 11:41
yep, in fact to get the extremum, i explore some points where i search for extremum and when the orientation of the curve seems change i say that the point is an extremum.

The data must be interpolated by me or Qwt do this for me? I think that the curv was always interpolated if it was needed but if Qwt don't do this. I have the real value and i do the right thing.

Added after 1 53 minutes:

I don't know if i express that i want clearly.

I want to create a plot with marker, a marker must be at an extremum or at an horizontal position on x Axis and the y position of this marker is on the curv. The curv is product by a series of data, sometimes i have lots of points some time few points. The curv will be interpolated in case of few points (if it's not the case actually, by default a curve is interpolated?)
What i need is to set the y position of the marker if i didn't need the extremum or the two position on the extremum value.
Qwt offer function to do that easyly? or like felixB said, i need to create function to get the y position?

I have wrote a function that search the closest point from the marker, and from this point search the x position of my marker with two point, one before and one after. when i have the intervalle that embrace my marker position i get their y position and create the line equation to get the y position of my marker. (y =ax+b). i'm on the right way or not? And for the extremum i have wrote a function that use this function and after locate my marker search the extremum by analyse point to point value, if by using to point, one go left of the marker and one go right. if one of these points change direction (the last point saved is lower(in case of top extremum) or upper(in case of bottom extremum)) i use it as extremum and set the marker as the new position.

Thanks for your time, this is my first projet with qwt and i don't understand sometime the logic of programming with it.

Schoumi
6th December 2011, 15:22
hum ok, with setCurveFitter, my functions don't work like I want because sample(position) return the point that i add to it and not the interpolated point, is there a way to get the interpolated points?
My method works only on linear interpolation.

Added after 51 minutes:

ok, i've tried another solution and use my solution with some modification

I use a part of the code of the first post of this topic http://www.qtcentre.org/threads/38965-Interpolation-points-of-a-fitted-curve with little modification to get the QPolygonF of the interpolated curve and affter i interpolated again this point to obtain all interpolated point, and after i search the line equation like i said before.

Edit:
Is it possible to fitCurve only one time? in this case the curve is fitted when i use setRawSample and when i want to get all interpolated points.

Uwe
7th December 2011, 07:13
Is it possible to fitCurve only one time? in this case the curve is fitted when i use setRawSample and when i want to get all interpolated points.

http://qwt.sourceforge.net/class_qwt_spline_curve_fitter.html#a14d64180d7777d 0cd9c2adf81e120140

Uwe