2

我有一个由函数生成的图表,它会根据函数的值自动放大和缩小。我已经有了绘图工具,我可以以高分辨率显示任何 x、y、宽度、高度。

我试着捕捉到正确的位置:

x = target_x
y = target_y
width = target_width
height = target_height

但是太浮躁了。很难分辨放大/缩小的部分。

我也试过这样做:

orig_x = x //ditto for y, width, height, etc
for i=1 to 10
    x = i/10*new_x + i/10*orig_x
    wait 25ms

它更顺畅,但第一步仍然太跳跃。如果 orig_x 是 10 而 new_x 是 100 万,那么第一次跳跃太大了,接近 1,000,000%。然而,最后一次跳跃只有 10%。几何级数甚至更好,但如果我必须在缩放中间切换方向,步骤会很跳跃。

使用的最佳效果是什么?

4

2 回答 2

2

您想为每个步骤缩放/移动最后一个窗口的固定百分比。这意味着您的缩放将是一个指数曲线,并且您的转变将与您的缩放相关联。类似以下的内容应该是一种改进:

width_ratio = new_width / old_width
width_ratio_log = log(width_ratio)

x_diff = new_x - old_x
x_factor = x_diff / (width_ratio - 1)
-- warning: need to handle width_ratio near 1 the old way!

for i=1 to steps
    width_factor = exp(width_ratio_log * i / steps)
    width = old_width * width_factor
    x = old_x + x_factor * (width_factor - 1)

    -- similarly for y and height...
于 2010-10-27T18:02:22.427 回答
0

我可以试试

xDiff = new_x - orig_x
stepCount = 10

for i=1 to stepCount
    x = orig_x + i/stepCount * xDiff
    wait 25ms
于 2010-10-27T16:11:25.307 回答