math - Scrolling Displacement Overshoot - Mathematical Issue -
so i'm trying do, make nice scroll bar, using kinetic model. issue dampening on over-shoot. behavior want show when overshoot (go past max/minimum), dampening positioning.
the specific behavior want this: say, maximumum overshoot 50 pixels. here's table representing how i'd work. (this best way, can think of, present it).
displacement | position | percent of position | displays @ | overshot on ------------------------------------------------- 25 | 12.5 | 50% 100 | 25 | 100% 200 | 37.5 | 200% 400 | 43.75 | 400% ... ... ... note: decimals round down can display it.
i'm pretty sure can calculate recursively (but don't want that). think mathematical relationship obvious, although i'm not sure how it. i may thinking of wrong way,so please consider disregarding chart. important thing user can't move window past max overshoot value (in case, 50 pixels).
here's segment of code running positioning setting...
function kineticmodel:setposition(newposition) -- set's position of kinetic model. using this, it'll calculate velocity. local currenttime = tick() local elapsedtime = currenttime - self.timestamp local localvelocity = ((self.position - self.lastposition) * 5) / elapsedtime timestamp = currenttime self:setvelocity((0.2 * self.velocity) + (0.8 * localvelocity)) -- 20% previous velocity maintained, 80% of new velocity used. if newposition > self.maximum print("[kineticmodel] - past max manual") local displacement = math.abs(newposition - self.maximum) -- dampen position can't go over. self.position = self.maximum + (displacement / self.maxbounce) -- doesn't work. :( elseif newposition < self.minimum print("[kineticmodel] - past min manual") local displacement = math.abs(newposition - self.minimum) -- same displacement here else self.position = newposition end self.lastposition = self.position self.onpositionchange(self.position) print("[kineticmodel] - set velocity @ "..self.velocity.."; local velocity @ "..localvelocity) end
the main issue trying find mathematical way find displacement should display at. i'll implementing displacement filter out position before it's set @ every point, if there's potential problem that, please tell me.
thanks. :d
edit: title, tag
this answer ignores dynamic aspects velocities , dampening , on. i'll concentrate on converting overshoot value might arbitrarily large displacement value bounded maximal value.
a simple formula
one simple formula properties asking following: let x ≥ 0
overshoot , 0 ≤ y ≤ 50
resulting displacement. can relate them using formula this:
y = 50*x/(x + 75)
the fraction x/(x+75)
come arbitrarily close 1 large x
without ever reaching it, displacement never exceed 50. can tweak 75
in formula control speed converges. 75 get:
x y 25 12.5 50 20.0 100 28.6 200 36.4 400 42.1
more flexibility
to gain more control on shape of curve, use different formula contains plynomials in x
in both numerator , denominator. i'd if have strict requirements curve passing through specific points, or other reason why simple approach outlined above not sufficient.
matching speed
the simple formula cause jerk in way content moves, since speed not match of non-overshot document. match speeds, can use 1 degree of freedom control slope. easiest way use same unit input , output, e.g. pixels. you'd aim slope of 1 @ origin.
y = 50*x(x + 50) = x/(x/50 + 1)
this give following values:
x y 25 16.7 50 25.0 100 33.3 200 40.0 400 44.4
illustration
here plot of 2 functions mentioned, data points table. not exact match, should reasonably close. note first row of table, wasn't sure colum choose x
value, there 2 data points y=12.5
.
Comments
Post a Comment