我应该使用什么算法来平滑地缩放图形或地图?

发布于 2024-09-29 13:35:32 字数 509 浏览 1 评论 0原文

我有一个由函数生成的图表,它会根据函数的值自动放大和缩小。我已经有了绘图工具,可以以高分辨率显示任何 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%。几何级数更好,但如果我必须在变焦过程中切换方向,那么步骤会很跳跃。

使用什么效果最好?

I have a graph, generated by a function, and it zooms itself in and out automatically, depending on the value of the function. I already have the graphing tools and I can display any x,y,width,height at high resolution.

I tried just snapping to the right spot:

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

But it's too jumpy. It's hard to tell what part was zoomed in/out.

I also tried doing this:

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

It's smoother but the first step is still too jumpy. If orig_x is 10 and new_x is 1 million then the first jump is too big, near 1,000,000%. Last jump is just 10%, however. A geometric progression is even better but if I have to switch directions mid-zoom the steps are jumpy.

What would be the best effect to use?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(2

你在我安 2024-10-06 13:35:32

您希望为每个步骤缩放/移动最后一个窗口的固定百分比。这意味着您的变焦将呈指数曲线,并且您的移动将与变焦相关联。像下面这样的东西应该是一个改进:

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...

You want to zoom/shift a fixed percentage of the last window for each step. That means your zoom will be an exponential curve, and your shift will be tied to your zoom. Something like the following should be an improvement:

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...
疯狂的代价 2024-10-06 13:35:32

我可以尝试

xDiff = new_x - orig_x
stepCount = 10

for i=1 to stepCount
    x = orig_x + i/stepCount * xDiff
    wait 25ms

I may try

xDiff = new_x - orig_x
stepCount = 10

for i=1 to stepCount
    x = orig_x + i/stepCount * xDiff
    wait 25ms
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文