Measurement Studio for VC++

cancel
Showing results for 
Search instead for 
Did you mean: 

The slope of a graph

I've been trying for a while to display a line annotation representing the slope of the plot around a certaing plot point. The idea is to have this line move along with the cursor while changing it's angle to fit the cuurent slope. The line length shouldn't change (can't use plot area coordinates) . Any Idea how to do it?
0 Kudos
Message 1 of 10
(3,553 Views)
If I'm understanding your question correctly, I think that you could do this by setting your annotation's Plot property to the plot that contains the line, setting the annotation's SnapMode property to CNiAnnotation::SnapPointsOnPlot, and then setting the annotation's PointIndex property to the index of the point that you want the annotation to point to. Then now matter how your plot changed, the annotation would always point to the same point index, regardless of the location. Please respond with more information if this does not solve what you're trying to do. Thanks.

- Elton
0 Kudos
Message 2 of 10
(3,553 Views)
Thank you for your, but this is not exactly what I meant. I'll try to explain...

The idea is to have an annotaion line moving with the cursor (not a problem). The line's length should not change but it's angle is supposed to fit the angle of the slope of the current cursor position. So, when ever you move the cursor the line should move along with it always fitting the cursor point slope angle.

The main problem is keeping the line length the same even though the scale and angle may change. It means that the coordinates of the line should be in screen values but the slope calculation must be made with plot values. Some conversion might be needed.
0 Kudos
Message 3 of 10
(3,553 Views)
I don't think that there's an easy way to do what you're looking for. I think the problem is that the annotation will let you set the coordinates of the caption, but does not let you get the coordinates of the arrow, which is what I think you would need to do what you're wanting. The annotation does let you get the point index, but then you would need some way of mapping the point to screen coordinates, which is not exposed by the graph. Sorry I don't have a more helpful answer.

- Elton
0 Kudos
Message 4 of 10
(3,553 Views)
thanks anyway
0 Kudos
Message 5 of 10
(3,553 Views)
An alternate approach to annotations would be to use a second plot. When the cursor changes, do a PlotXY on the second plot to generate a line along the first plot's slope at the point the cursor is at. The line on the second plot corresponding to point (x1,y1) would run from (x1-dx, y1-dy) to (x1+dx, y1+dy) where the slope, m, is dy/dx. In this case a little algebra gets you dx = sqrt(length^2/(4+4m^2)) and dy = m*dx where length is the desired length of the line in plot area coordinates. If your aspect ratio (y scale to x scale) isn't 1:1, then you can multiply the calculated dx and dy to correct for that and have the line always be the same length on the screen.

Tony
NI - Measurement Studio
0 Kudos
Message 6 of 10
(3,553 Views)
How can I find the aspect ratio between the axes?
0 Kudos
Message 7 of 10
(3,553 Views)
You should be able to get a close approximation to the aspect ratio by using the range of your x and y axes and the size of the window from GetClientRect or GetWindowRect (these are functions provided by CNiGraph's CWnd base class). The aspect ratio is
(yrange/ysize)/(xrange/xsize). I think multiplying your dx value by this should correct the line length. The ranges of your second plot needs to be the same as your first. Good luck!

Tony
NI - Measurement Studio
0 Kudos
Message 8 of 10
(3,553 Views)
Hi,

I tried it,
but the line size keeps changing.
When I change the Y axis scale length to fit the Xaxis scale length, the line size doesn't change.

Any Ideay what's wrong?

I attached a copy of the code
0 Kudos
Message 9 of 10
(3,553 Views)
DY should be calculated using the uncorrected DX.

double DX = sqrt((Length*Length)/(4+4*(Slope*Slope)));

double DY = Slope * DX;

DX = DX * Ratio;

Tony
NI - Measurement Studio
0 Kudos
Message 10 of 10
(3,553 Views)