2d collision, Chaotic Ball
I am trying to write code for chaotic ball. I know it can be written using equation of motion, but wanted to create simulation for it. This is my code right now and it is terrible. I can't seem to make it collide with top part of the circle, there are energy leaks and ball sometimes exits out the sphere. Any recommendation for how to improve it? I want to learn more about real time simulations.
note:
dt
is fixed to 0.001 so that shouldn't be a problem.
19 Replies
This is just an idea but you can probably just calculate the distance between the ball center and the center of the big circle and trigger a collision whenever the distance would become greater than the large radius minus the small radius
Then there would be no edge case checking for the top Vs the bottom
thanks. that's better way for triggering, but trigger was never really the issue. I had both cases together, but split them up in the process of trying to get it right.
Is it more an issue of calculating the resulting motion vector?
Or the direction
motion vector
I will do some math and get back to you
You could try mirroring the motion vector over the normal to the point of collision
It's not that simple but it might work
i attempted this
Is that what your current code does
yes
I made mistake somewhere, so it doesn't work on the right side. Couldn't find issue there either
Are you also getting the X intersection? It looks like you only have intersect y
my logic is that if y is out of bounds, x will be too
I would have thought the normal calculation needed the vector from the intersection point
Right now you are using the X position of the ball which is probably different
what can i do to fix that? nudge the ball towards center until it is inside bounds?
You just need to get both coordinates for the intersection point
This could be helpful for the math
https://math.stackexchange.com/a/311956
Mathematics Stack Exchange
Get location of vector/circle intersection?
I'm a coding guru, and I'm good with math - but only math that I know. Which isn't even at calculus level yet. So I'm hoping I can get some help here for my algorithm.
Say I have a circle. I know ...
Then the normal calculation would be the same and you still just reflect over it
that is much neater solution
anyways its late for me. will try implementing tomorrow. thanks a bunch
No problem, good luck
hey @exokem . thanks for help. here is solution i came up with today.
instead of fiddling around with vectors, i decided to find an angle of resulting velocity and then convert polar coordinate to traditional form. With some fiddling around, this works great.