Sorry your browser is not supported!

You are using an outdated browser that does not support modern web technologies, in order to use this site please update to a new browser.

Browsers supported include Chrome, FireFox, Safari, Opera, Internet Explorer 10+ or Microsoft Edge.

DarkBASIC Professional Discussion / Elastic collisions.

Author
Message
MegaCodeOne
12
Years of Service
User Offline
Joined: 16th Jan 2014
Location:
Posted: 15th Feb 2014 03:08
Physics in collisions.
« on: February 13, 2014, 04:52:30 PM »


Below is a formula I came up with for elastic collisions.
I'm not using the momentum formula you can find on the net.
Instead I just did some simple math to try in come up with something that looks right.
Of course the final velocities will have to be in opposite directions.
Can you have a look at it and tell me what you think?
I don't think the masses will change of course unless they cars they would crash.
The speeds seem to adjust accordingly.

Thanks
ScottieB

*****************

Mass_1 = 5
Mass_2 = 2

Vel_1 = 2
Vel_2 = 3

Combined_Velocities = Vel_1 + Vel_2 = 5

Force_1 = Mass_1 * Vel_1 = 10
Force_2 = Mass_2 * Vel_2 = 6

Combined_Forces = Force_1 + Force_2 = 16

Percentage_1 = Force_1 / Combined_Forces = 0.625
Percentage_2 = Force_2 / Combined_Forces = 0.375

New_Vel_1 = Percentage_1 * Combined_Velocities = 3.125
New_Vel_2 = Percentage_2 * Combined_Velocities = 1.875

If Force_1 > Force_2 Then Vel_1 = New_Vel_2:Vel_2 = New_Vel_1
If Force_2 > Force_1 Then Vel_2 = New_Vel_2:Vel_1 = New_Vel_1

******************
Derek Darkly
14
Years of Service
User Offline
Joined: 22nd Sep 2011
Location: Whats Our Vector, Victor?
Posted: 15th Feb 2014 15:50
I don't know how to use this... would you mind posting a working snippet with primitives for us math dummies?

Phaelax
DBPro Master
23
Years of Service
User Offline
Joined: 16th Apr 2003
Location: Metropia
Posted: 15th Feb 2014 19:17
So what's your question exactly? They're your equations and as you said you're not using the classical formula so we can't really say much on how yours should look. I'd say write up a quick demo using your equations and see if they look ok in action.

But when two bodies collide, I think you just add the two velocity vectors together to get the new direction. I'm not quite sure how you would factor in different masses though.

MegaCodeOne
12
Years of Service
User Offline
Joined: 16th Jan 2014
Location:
Posted: 16th Feb 2014 16:36
Ok, I'll try to code up a sample this weekend.
Because someone wants to see the math while
someone would like me to give it a try.
Be back later with an example.

ScottieB
MegaCodeOne
12
Years of Service
User Offline
Joined: 16th Jan 2014
Location:
Posted: 16th Feb 2014 18:03
Here's the code below for a test program.
I only find one thing wrong with it so far
can someone help me figure it out?
Where the program decides to switch velocities
where either one force is greater than the other
the smaller taking the faster and the bigger taking the slower
How about when forces are like?
It seems we just need a way to always tell which one will take
which property and how about if the are equal?
How do we determine which should get which and when better?????
ScottieB


**************************************

Set Display Mode 800,600,32,0

Print "Enter the mass of object_1:"
Input Mass_1#
Print "Enter the mass of object_2:"
Input Mass_2#
Print "Enter the velocity of object_1:"
Input Vel_1#
Print "Enter the velocity of object_2:"
Input Vel_2#

Combined_Velocities# = Vel_1# + Vel_2#

Force_1# = Mass_1# * Vel_1#
Force_2# = Mass_2# * Vel_2#

Combined_Forces# = Force_1# + Force_2#

Percentage_1# = Force_1# / Combined_Forces#
Percentage_2# = Force_2# / Combined_Forces#

New_Vel_1# = Percentage_1# * Combined_Velocities#
New_Vel_2# = Percentage_2# * Combined_Velocities#

X1# = 0
Y1# = 300

X2# = 800
Y2# = 300

Current_Time# = Timer()

Do

Cls

Box X1# - Mass_1# / 2,Y1# - Mass_1# / 2,X1# + Mass_1# / 2,Y1# + Mass_1# / 2
Box X2# - Mass_2# / 2,Y2# - Mass_2# / 2,X2# + Mass_2# / 2,Y2# + Mass_2# / 2

Sync

Last_Time# = Current_Time#
Current_Time# = Timer()
Elapsed_Time# = (Current_Time# - Last_Time#) / 1000

X1# = X1# + Vel_1# * Elapsed_Time#
X2# = X2# - Vel_2# * Elapsed_Time#

// Box collision
If X1# - Mass_1# / 2 < (X2# - Mass_2# / 2) + Mass_2# And Y1# - Mass_1# / 2 < (Y2# - Mass_2# / 2) + Mass_2# And X2# - Mass_1# / 2 < (X1# - Mass_1# / 2) + Mass_1# And Y2# - Mass_2# / 2 < (Y1# - Mass_1# / 2) + Mass_1# Then Box_Collision = 1

If Box_Collision = 1 And Force_1# > Force_2# Then Vel_1# = -New_Vel_2#:Vel_2# = -New_Vel_1#
If Box_Collision = 1 And Force_2# > Force_1# Then Vel_2# = -New_Vel_2#:Vel_1# = -New_Vel_1#

Loop
MegaCodeOne
12
Years of Service
User Offline
Joined: 16th Jan 2014
Location:
Posted: 16th Feb 2014 18:33
Just Add this at the bottom for equal too.

If Box_Collision = 1 And Force_1# = Force_2# Then Vel_1# = -New_Vel_1#:Vel_2# = -New_Vel_1#
MegaCodeOne
12
Years of Service
User Offline
Joined: 16th Jan 2014
Location:
Posted: 16th Feb 2014 19:56
Sorry, For the above.
I was confusing myself.
Here is a better copy.
Box Collision simplified
and works for three states.
Force_1 > Force_2
Force_2 > Force_1
And
Force_1 = Force_2
I cleaned it up a bit.
It's working a lot better.

Login to post a reply

Server time is: 2026-07-06 07:51:56
Your offset time is: 2026-07-06 07:51:56