弹簧质量系统的阻尼效果(或者是这个ElasticEase?) [英] Damping Effect of Spring-Mass System (or is this ElasticEase?)

查看:157
本文介绍了弹簧质量系统的阻尼效果(或者是这个ElasticEase?)的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我试图仿效code(因为它似乎是数学,而不是语言的几乎任何语言会做)的动画效果。本质上,它是一种质量弹簧系统的仿真。我一直在寻找在WPF / Silverlight中的 ElasticEase ,这似乎是pretty接近我正在寻找,但并不完全。

I'm trying to emulate an animation effect in code (almost any language would do as it appears to be math rather than language). Essentially, it is the emulation of a mass-spring system. I've been looking at WPF/Silverlight's ElasticEase and this appears to be pretty close to what I'm looking for, but not quite.

首先,这里就是我要找的 - 一个对象,行驶若干秒,创下了位置,并立即减速到ocsillate一定的秒数在涂敷阻尼的相同点休息。所以,想象这一点,让我们说我有一个600瓦特/ 900H帆布和我有开始从动画到900px在 TranslateTransform.Y 150像素的正方形。它需要4秒内达到150像素高度(每秒187.5px),在该阶段它immediated得到阻尼并且仅行进大约35px更0.4秒(每秒87.5px)到115px高度,然后反弹向下进行1秒〜163px高度(48像素和48像素每秒),然后反弹回升到146px(知识+和知识+每秒),并依此类推,直到ocillations它慢到最终的安息之地的150像素。该ocillation时间为16秒。

First of all, here's what I'm looking for - an object, travelling a certain number of seconds, hitting a location and immediately slowing down to ocsillate for a certain number of seconds to rest at the same point where damping was applied. So to visualize this, let's say I have a 600w/900h canvas and I have an square that begins to animate from 900px to 150px in a TranslateTransform.Y. It takes 4 seconds to reach 150px height (187.5px per second), at which stage it immediated gets damped and only travels about 35px more for 0.4 seconds (87.5px per second) to 115px height, then rebounds down for 1 second to 163px height (48px and 48px per second) and then rebounds back up to 146px (17px and 17px per second) and so on until the ocillations slow it to its final resting place of 150px. The ocillation period is 16 seconds.

我上述的例子是在这里左上方蓝色矩形:

The example I described above is the top left blue rectangle here:

下面是什么,我会提前知道 - 秒的像素间距和数量需要得到从A点到B点,为ocillation秒数。像大众的东西似乎并不重要。

Here's what I will know in advance - the pixel distance and number of seconds it takes to get from point A to point B, the number of seconds for ocillation. Things like mass don't seem to matter.

我试过 ElasticEase 和问题似乎是,我不能没有放松旅行4秒的对象,然后反弹接下来的16秒。在 .Springiness 也总是太多,即使我将其设置为像一个20真正的高数字。

I've tried ElasticEase and the issue seems to be that I can't get the object to travel with no easing for 4 seconds and then "bounce" for the next 16 seconds. The .Springiness is also always way too much, even if I set it to be a really high number like 20.

ILSpy展示的其作为功能:

ILSpy show's its function as:

protected override double EaseInCore(double normalizedTime)
        {
            double num = Math.Max(0.0, (double)this.Oscillations);
            double num2 = Math.Max(0.0, this.Springiness);
            double num3;
            if (DoubleUtil.IsZero(num2))
            {
                num3 = normalizedTime;
            }
            else
            {
                num3 = (Math.Exp(num2 * normalizedTime) - 1.0) / (Math.Exp(num2) - 1.0);
            }
            return num3 * Math.Sin((6.2831853071795862 * num + 1.5707963267948966) * normalizedTime);
        }

我已经包括2视频,并在投放箱一个压缩文件夹的Excel文件。我想这个问题将更多的是工作在进步,因为人们提出更多的澄清问题。

I've included 2 videos and and an Excel file in a zipped folder on DropBox. I guess this question will be more of a work-in-progress as folks ask more clarifying questions.

(声明:我不知道我说的是当它涉及到很多这方面的东西)

(DISCLAIMER: I don't know what I'm talking about when it comes to much of this stuff)

推荐答案

跳过物理,只是直奔方程。

Skip the physics and just go straight to the equation.

参数的:
这是什么,我会提前知道 - 在像素间距研究[D]和秒数[T0]它从A点到达B点,几秒钟振荡[T1]号还有,我会添加为自由参数:振荡,澳玛,在阻尼时间常数,将T的最大尺寸,和帧速率中,Rf,也就是说,在什么时候做一件要一个新的位置值。我想你不希望永远计算这个,所以我就做10秒,TTOTAL,但也有各种各样的合理的止损条件...

parameters: "Here's what I will know in advance - the pixel distance [D] and number of seconds [T0] it takes to get from point A to point B, the number of seconds for oscillation [T1]." Also, I'll add as free parameters: the maximum size of oscillation, Amax, the damping time constant, Tc, and a frame rate, Rf, that is, at what times does one want a new position value. I assume you don't want to calculate this forever, so I'll just do 10 seconds, Ttotal, but there are a variety of reasonable stop conditions...

code 的:
这里的code(在Python)。最主要的是方程,在发现DEF Y(T)

from numpy import pi, arange, sin, exp

Ystart, D = 900., 900.-150.  # all time units in seconds, distance in pixels, Rf in frames/second
T0, T1, Tc, Amax, Rf, Ttotal = 5., 2., 2., 90., 30., 10. 

A0 = Amax*(D/T0)*(4./(900-150))  # basically a momentum... scales the size of the oscillation with the speed 

def Y(t):
    if t<T0:  # linear part
        y = Ystart-(D/T0)*t
    else:  # decaying oscillations
        y = Ystart-D-A0*sin((2*pi/T1)*(t-T0))*exp(-abs(T0-t)/Tc)
    return y

y_result = []
for t in arange(0, Ttotal, 1./Rf):  # or one could do "for i in range(int(Ttotal*Rf))" to stick with ints    
    y = Y(t)
    y_result.append(y)

的想法是直线运动到该点,随后是衰减的振荡。振荡是由和衰减由 EXP 乘以规定。当然,改变参数获得任何距离,振荡大小等,你想要的。

The idea is linear motion up to the point, followed by a decaying oscillation. The oscillation is provided by the sin and the decay by multiplying it by the exp. Of course, change the parameters to get any distance, oscillation size, etc, that you want.

注释的:


  1. 大多数人的意见所提出的建议物理方法。我没有使用这些,因为如果一个指定某个特定的动作,实在是有点过这样做,它开始与物理学,去微分方程,再计算出运动和调整参数,以获得最后一件事。还不如干脆直接转到了最后一件事。除非,那就是,人们对他们想从工作的物理直觉。

  2. 常在的问题,像这一个希望保持连续转速(一阶导数),但你说马上减慢,所以我没有做,在这里。

  3. 请注意,振荡周期和幅度不会完全当施加阻尼符合规定,但是这可能是更详细的比你所关心的。

  4. 如果您需要前preSS这是一个方程,你可以这样做使用海维赛德功能,来打开和关闭的贡献。

在使这一过长的风险,我意识到我可以做出一个GIMP GIF,所以这是它看起来像:

At the risk of making this too long, I realized I could make a gif in GIMP, so this is what it looks like:

我可以张贴满code,使该地块如果有兴趣,但基本上我打电话Y中的每一个时间不同的D和T0值。如果我再这样做,我可能会增加阻尼(即降低TC),但它是一个有点麻烦,所以我把它当作是。

I can post the full code to make the plots if there's interest, but basically I'm just calling Y with different D and T0 values for each timestep. If I were to do this again, I could increase the damping (i.e., decrease Tc), but it's a bit of a hassle so I'm leaving it as is.

这篇关于弹簧质量系统的阻尼效果(或者是这个ElasticEase?)的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆