Heyyyyyy,
I have a double pendulum simulation but sometimes it starts to spins too fast and then even disappears into space and time . I would want it to spin and then maybe go back to a random motion and not just keep going in circles. I've checked and it seems one of the causes is angular velocity (w1/ w2) being to high(9 maybe?).
I've tried to include a check that when it goes too fast it slows down but that causes it to slow down too rapidly all of a sudden. It's weird ?
Anyone know how to fix this problem, or at least implement a check to stop it from happening?
Double Pendulum spinning like crazy
Forum rules
Before you make a thread asking for help, read this.
Before you make a thread asking for help, read this.
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Double Pendulum spinning like crazy
- Attachments
-
- pending.love
- (2.38 KiB) Downloaded 199 times
Re: Double Pendulum spinning like crazy
Go away from Euler's method to Runge-Kutta method. It makes more carefully interpolation and the energy of system will be much closer to the constant.Gunroar:Cannon() wrote: ↑Tue Jun 08, 2021 9:51 pm Anyone know how to fix this problem, or at least implement a check to stop it from happening?
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: Double Pendulum spinning like crazy
But I'm not familiar with that method. It might break my whole system. Isn't there any shortcut or method to check this and if not what are thr benefits of the other method and implementations of it. Does it still use all the variables and only the formula changes?
Re: Double Pendulum spinning like crazy
I am not familiar too
It's just a function, that needs the acceleration formula (function) as one of input parameters.
On my first try I've made an error, but now I am much closer to make it in the right way.
It's just a function, that needs the acceleration formula (function) as one of input parameters.
On my first try I've made an error, but now I am much closer to make it in the right way.
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: Double Pendulum spinning like crazy
Could you show me what you've done so far? I've been looking for the other method's formula but I can't see the exact function for a double pendulum I want any where.
Re: Double Pendulum spinning like crazy
I've used this source:Gunroar:Cannon() wrote: ↑Fri Jun 11, 2021 11:02 am Could you show me what you've done so far? I've been looking for the other method's formula but I can't see the exact function for a double pendulum I want any where.
https://gafferongames.com/post/integration_basics/
Update:
First google solution: https://github.com/DavidColson/Double-P ... r/main.lua
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: Double Pendulum spinning like crazy
Hmmm, will that really make it better? Does it stop the infinite spinning but still allow it to spin fast? That other tab said euler method is good for games, but I'll try.
That first link you posted lead me to another link https://gafferongames.com/post/fix_your_timestep/(the last solution) which I used to fix the update so that the pendulum will always update correctly, I did:
But now the pendulums always start slow, then move normally, why do they start slow? Is it because dt is really small in first frame so it doesn't update(dt is at 0.007)?
That first link you posted lead me to another link https://gafferongames.com/post/fix_your_timestep/(the last solution) which I used to fix the update so that the pendulum will always update correctly, I did:
Code: Select all
love.load()
accumulator = 0
...
love.update(dt)
ac = 1/100--fixed delta at 0.01
accumulator = accumulator+dt
...
--still in update
while (accumulator>=ac) do
for _,pendulum in ipairs(allpendulums) do
pendulum.update(ac)
boolean collsion = circleVsRect(pendulum.x2, pendulum.y2,
pendulum.radius,
player.x, player.y, player.w, player.h)
if collsion then
killPlayer()
end
end
accumulator = accumulator-ac
end
Re: Double Pendulum spinning like crazy
You can set the same dt for all cycles in the same update:
Code: Select all
love.update(dt)
local dt_max = 0.005 -- (5 milliseconds)
local n = math.ceil(dt/dt_max)
for i = 1, n do
update (dt/n)
end
end
Last edited by darkfrei on Sat Jun 12, 2021 2:04 pm, edited 2 times in total.
- Gunroar:Cannon()
- Party member
- Posts: 1091
- Joined: Thu Dec 10, 2020 1:57 am
Re: Double Pendulum spinning like crazy
Wait, what? Can you explain a little bit how this works. Doesn't math.ceil return a whole integer so won't it always return zero?
Re: Double Pendulum spinning like crazy
Sorry, forgot that dt is in seconds, not in milliseconds.Gunroar:Cannon() wrote: ↑Sat Jun 12, 2021 1:43 pm Wait, what? Can you explain a little bit how this works. Doesn't math.ceil return a whole integer so won't it always return zero?
16.6 ms / 5 ms gives the 3.32, it will be ceil-rounded to 4.
So the dt by the simulation will be 4 times with new dt = 16.6/4 = 4.15 ms.
- Attachments
-
- pending-02.love
- (2.4 KiB) Downloaded 151 times
Last edited by darkfrei on Sun Jun 13, 2021 9:32 pm, edited 1 time in total.
Who is online
Users browsing this forum: No registered users and 1 guest