如何使用滚动条平滑地缩放图形或图像
我想在我的应用程序中使用滚动条或跟踪栏控件,以允许我的用户缩放图表中的 y 轴值。
例如,该图可能是峰值为 1.0 的正弦波。通过拖动滚动条,用户应该能够将峰值增加到 2.0、200,或减少到 0.5 等。
因此,我想使用滚动条位置创建一个应用于每个 y 点的乘法因子在我的曲线上。
我不太明白这里的数学原理。我担心该控件的操作对用户来说不流畅或不直观。这里涉及指数或对数,不是吗?滚动条的中间不是会被标记为 1.0,其中值高于向上步进(以对数间距计),低于 1.0 则向下步进吗?
我记得大约四十年前我的对数/指数数学经验中的零。
我的语言是 Delphi,但伪代码中的一些代码片段会有所帮助。
TIA
PS 请随时为此问题添加其他标签,以帮助最合适的受众看到它......
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...
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我想你已经回答了大部分问题。您知道您想要使用对数刻度。因此,您将得到等距的刻度线,例如 0.01、0.1、1.0、10.0、100.0。
您应该使用轨迹栏,而不是滚动条。轨迹栏上的值采用对数刻度。所以你想要像 0 对应 0.01、100 对应 0.1、200 对应 1.0 等等。这将为您提供一个最小值为 0、最大值为 400 且初始位置为 200(即 1.0)的轨迹栏。
现在仍然需要从轨迹栏位置映射到比例。您需要
Scale(0)
等于 0.01,Scale(100)
等于 0.1,依此类推。您可以使用 10 次方求幂来完成此操作。另一种方法则涉及取对数并重新排列。
当然,如果我选择的数字和最小/最大值不适合,您可以轻松地进行调整,以便它们适合。
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.