I want to use a scroll bar or track bar control in my application that allows my users to scale the y-axis values in a graph.
For example, maybe the graph is a sine wave with a peak of 1.0. By dragging the scrollbar, the user should be able to increase the peak value to 2.0, 200, or decrease it to 0.5, etc.
So, I want to use the scrollbar position to create a multiplication factor that I apply to every y-point on my curve.
I can’t quite figure out the math here. I’m concerned that the operation of the control will not be smooth or intuitive to the user. There’s something involving exponentials or logs here, isn’t there? Wouldn’t the middle of the scroll bar be labelled as 1.0, with values above stepping (in log spacing) up, and below the 1.0, stepping down?
I remember zero from my log/exponential math experience almost four decades ago.
My language is Delphi, but some code fragments in pseudo-code would be helpful.
TIA
PS Please feel free to add additional tags to this question to help it get seen by the most appropriate audience…
I think you’ve already answered most of the question. You know that you want to use a log scale. So you would have the tick marks, equally spaced, 0.01, 0.1, 1.0, 10.0, 100.0, say.
Rather than a scroll bar you should use a track bar. The values on the track bar are in log scale. So you want something like 0 to correspond to 0.01, 100 to correspond to 0.1, 200 to correspond to 1.0 and so on. This gives you a track bar with minimum of 0, maximum of 400 and an initial position of 200, i.e. 1.0.
Now it remains to map from track bar position to scale. You need
Scale(0)to equal 0.01,Scale(100)to equal 0.1 and so on. You do this using exponentiation to the power 10.Going the other way involves taking logarithms and rearranging.
Naturally if the figures and min/max values I have selected don’t suit you can easily enough rejig so that they do.