You are not logged in or registered. Please login or register to use the full functionality of this board...
SIGN IN Join Our Community For FREE


Freeze Tag
09-01-2017, 09:42 AM
Post: #51
 (Print Post)
RE: Freeze Tag
ok back to work on the bounce algo.

bplus brought to my attention a flaw in the algo that i was unaware of.
Quote:
If 2 balls of equal mass and speed collide head on (180 degrees) wouldn't both be stunned to stillness?
and sure enough vorbarian's algo has the flaw as well as my algo since it is a rework of his.

i don't know why exactly yet or what the solution could be other then what bplus suggests.
Quote:
I like to let them bounce off each other into the opposite direction at the same speed as before the bounce.
so thank you bplus.
Find all posts by this user
Like Post
09-01-2017, 12:29 PM (This post was last modified: 09-01-2017 01:45 PM by bplus.)
Post: #52
 (Print Post)
RE: Freeze Tag
If 2 balls of equal mass and speed collide head on (180 degrees) wouldn't both be stunned to stillness?

I don't think that is a flaw. It is proper physics accounting of momentums and vector math.

Have you seen a demo or Newton's Cradle?

In pool, it works too if the cue ball has 0 forward or backward spin and hits an object ball dead center, it will stop still and all momentum transferred to object ball.

But when 2 balls collide, where does all that momentum go? It just cancels out, that's what mass will do, I guess.

B += _
Find all posts by this user
Like Post
09-01-2017, 11:40 PM (This post was last modified: 09-01-2017 11:40 PM by owen.)
Post: #53
 (Print Post)
RE: Freeze Tag
the flaw i was referring to in vobarian's code was when i set two of the balls with the same mass and pointed them in each others direction to collide head on and everything was working correct till i changed the starting point of one of the balls. now i just looked at why it was causing a problem and realized my error. never mind. vobarian's code is fine.

no i haven't tested or looked at the other physic engines yet. my goal is to rework vobarian's code to something simpler.

about what happens on a pool table. the two balls should come to a dead stop. i don't know about that. but definitely i have seen plenty of times the que ball stopping and the other takes off.
Find all posts by this user
Like Post
09-02-2017, 12:09 PM
Post: #54
 (Print Post)
RE: Freeze Tag
Still curious where all that momentum goes? 
Momentum is a force or energy. 
Energy equations must be balanced.
So do you think this is where heat / noise comes from?
Every though the balls are stationary, they are vibrating at higher frequency?

B += _
Find all posts by this user
Like Post
09-02-2017, 02:36 PM (This post was last modified: 09-02-2017 02:55 PM by owen.)
Post: #55
 (Print Post)
RE: Freeze Tag
i like the way you think bplus.
considering the idea of molecular or atomic frequency...
i'll keep that thought in mind.

after looking at a few things... they say that momentum and kinetic energy are two different beasts and kinetic energy will only be conserved in some situations.

i'm just learning this stuff myself.
today i watched some of these vids:
https://youtu.be/NzgIGd0MbR4
https://youtu.be/Y0NYXy5p5_0

side note:
i have managed to rework it in terms of hippasus. (the square root of 2)
hippasus_x and hippasus_y will be pos/neg 1.4142...
there will be 4 possibilities
hx,hy or -hx,hy or -hx,-hy or hx,-hy
ball 2 relative to ball 1
(0-90) or (90-180) or (180-270) or (270-360)
Code Snippet: [Select]
Sub bounce(ball_1 As Integer, ball_2 As Integer)
    Dim As Double b1xv,b1yv,b2xv,b2yv
    Dim As Double b1xnv,b1ynv,b2xnv,b2ynv
    Dim As Double b1nx,b1ny,b2nx,b2ny
    Dim As Double ball_1_a,ball_2_a
    Dim As Double speedin,speedout,s1,s2
    Dim As Double hippasus_x,hippasus_y
    
    speedin=b(ball_1).s+b(ball_2).s
    b1xv=cos(b(ball_1).d*pi/180)*b(ball_1).s
    b1yv=sin(b(ball_1).d*pi/180)*b(ball_1).s
    b2xv=cos(b(ball_2).d*pi/180)*b(ball_2).s
    b2yv=sin(b(ball_2).d*pi/180)*b(ball_2).s
    ball_1_a=(pi*b(ball_1).r)^2
    ball_2_a=(pi*b(ball_2).r)^2
    If ball_1=0 Then ball_1_a*=3
    If ball_2=0 Then ball_2_a*=3
    hippasus_x=hippasus*(b(ball_2).x-b(ball_1).x)/Abs(b(ball_2).x-b(ball_1).x)
    hippasus_y=hippasus*(b(ball_2).y-b(ball_1).y)/Abs(b(ball_2).y-b(ball_1).y)
    
    b1xnv=(((((hippasus_x*b1xv+hippasus_y*b1yv) * (ball_1_a - ball_2_a) + 2 * ball_2_a * (hippasus_x*b2xv+hippasus_y*b2yv))) / (ball_1_a + ball_2_a))*hippasus_x+(hippasus_y*-1*b1xv+hippasus_x*b1yv)*hippasus_y*-1)
    b1ynv=(((((hippasus_x*b1xv+hippasus_y*b1yv) * (ball_1_a - ball_2_a) + 2 * ball_2_a * (hippasus_x*b2xv+hippasus_y*b2yv))) / (ball_1_a + ball_2_a))*hippasus_y+(hippasus_y*-1*b1xv+hippasus_x*b1yv)*hippasus_x)
    b2xnv=(((((hippasus_x*b2xv+hippasus_y*b2yv) * (ball_2_a - ball_1_a) + 2 * ball_1_a * (hippasus_x*b1xv+hippasus_y*b1yv))) / (ball_1_a + ball_2_a))*hippasus_x+(hippasus_y*-1*b2xv+hippasus_x*b2yv)*hippasus_y*-1)
    b2ynv=(((((hippasus_x*b2xv+hippasus_y*b2yv) * (ball_2_a - ball_1_a) + 2 * ball_1_a * (hippasus_x*b1xv+hippasus_y*b1yv))) / (ball_1_a + ball_2_a))*hippasus_y+(hippasus_y*-1*b2xv+hippasus_x*b2yv)*hippasus_x)



    b1nx=b(ball_1).x+b1xnv
    b1ny=b(ball_1).y+b1ynv
    b2nx=b(ball_2).x+b2xnv
    b2ny=b(ball_2).y+b2ynv
    b(ball_1).d=abtp(b(ball_1).x,b(ball_1).y,b1nx,b1ny)
    b(ball_2).d=abtp(b(ball_2).x,b(ball_2).y,b2nx,b2ny)
    s1=Sqr(b1xnv^2+b1ynv^2)
    s2=Sqr(b2xnv^2+b2ynv^2)
    speedout=s1+s2
    b(ball_1).s=s1/speedout*speedin*.987
    b(ball_2).s=s2/speedout*speedin*.987
    'If ball_1<>0 Or ball_2<>0 Then
    'b(ball_1).s-=.1
    'b(ball_2).s-=.1
    'EndIf
    If b(ball_1).s<.0001 Then b(ball_1).s=.0001
    If b(ball_2).s<.0001 Then b(ball_2).s=.0001
    
End Sub
Find all posts by this user
Like Post
09-02-2017, 07:08 PM
Post: #56
 (Print Post)
RE: Freeze Tag
note: the algo is still ridden with a divide by zero errors.
but now that i have in such terms perhaps i can see the big picture and address this issue.

first, is the test of two balls head on collision on x axis. they y values will cause a divide by zero error.
(b(ball_2).y-b(ball_1).y)/Abs(b(ball_2).y-b(ball_1).y)
0/abs(0)

Code Snippet: [Select]
    hippasus_x=hippasus*(b(ball_2).x-b(ball_1).x)/Abs(b(ball_2).x-b(ball_1).x)
    hippasus_y=hippasus*(b(ball_2).y-b(ball_1).y)/Abs(b(ball_2).y-b(ball_1).y)
Find all posts by this user
Like Post
09-02-2017, 08:47 PM
Post: #57
 (Print Post)
RE: Freeze Tag
cool. no more error with one simple change. the balls bounce off each other in head on collisions with equal mass.

all i changed was the first divide by zero error
Code Snippet: [Select]
    Select Case b(ball_2).x-b(ball_1).x
        Case 0
            hippasus_x=0
        Case Is > 0
            hippasus_x=hippasus
        Case Is < 0
            hippasus_x=hippasus*-1
    End Select
    Select Case b(ball_2).y-b(ball_1).y
        Case 0
            hippasus_y=0
        Case Is > 0
            hippasus_y=hippasus
        Case Is < 0
            hippasus_y=hippasus*-1
    End Select
there are other potential divide by zero errors but it seems to work.
Find all posts by this user
Like Post
09-03-2017, 12:24 AM
Post: #58
 (Print Post)
RE: Freeze Tag
#10 is up loaded
added multiburst ammo

note: possible memory leak.
sometimes when you catch all the balls of one color, it gets stuck on that color instead of switching to the next available color of balls to catch. let me know if you experience this too. thanks
Find all posts by this user
Like Post
09-04-2017, 12:42 PM
Post: #59
 (Print Post)
RE: Freeze Tag
the thing about hippasus (a few posts back) was due to a lot of beer. (i was investigating head on collision stuff)
update #11 is up.
the bounce routine looks like this:
Code Snippet: [Select]
Sub bounce(ball_1 As Integer, ball_2 As Integer)
    Dim As Double b1xv,b1yv,b2xv,b2yv
    Dim As Double b1xnv,b1ynv,b2xnv,b2ynv
    Dim As Double b1nx,b1ny,b2nx,b2ny
    Dim As Double ball_1_a,ball_2_a
    Dim As Double speedin,speedout,s1,s2
    Dim As Double norm,normx,normy
    
    speedin=b(ball_1).s+b(ball_2).s
    b1xv=cos(b(ball_1).d*pi/180)*b(ball_1).s
    b1yv=sin(b(ball_1).d*pi/180)*b(ball_1).s
    b2xv=cos(b(ball_2).d*pi/180)*b(ball_2).s
    b2yv=sin(b(ball_2).d*pi/180)*b(ball_2).s
    ball_1_a=(pi*b(ball_1).r)^2
    ball_2_a=(pi*b(ball_2).r)^2
    If ball_1=0 Then ball_1_a*=2
    If ball_2=0 Then ball_2_a*=2
    
    norm=abtp(b(ball_2).x,b(ball_2).y,b(ball_1).x,b(ball_1).y)
    normx=Cos(norm*pi/180)
    normy=Sin(norm*pi/180)
    'set one ball to nearest non overlap position
    b(ball_1).x=b(ball_2).x+(b(ball_2).r+b(ball_1).r)*normx
    b(ball_1).y=b(ball_2).y+(b(ball_2).r+b(ball_1).r)*normy
    norm=abtp(b(ball_2).x,b(ball_2).y,b(ball_1).x,b(ball_1).y)
    'readjust norm x and y
    normx=Cos(norm*pi/180)
    normy=Sin(norm*pi/180)
    b1xnv=(((((normx*b1xv+normy*b1yv) * (ball_1_a - ball_2_a) + 2 * ball_2_a * (normx*b2xv+normy*b2yv))) / (ball_1_a + ball_2_a))*normx+(normy*-1*b1xv+normx*b1yv)*normy*-1)
    b1ynv=(((((normx*b1xv+normy*b1yv) * (ball_1_a - ball_2_a) + 2 * ball_2_a * (normx*b2xv+normy*b2yv))) / (ball_1_a + ball_2_a))*normy+(normy*-1*b1xv+normx*b1yv)*normx)
    b2xnv=(((((normx*b2xv+normy*b2yv) * (ball_2_a - ball_1_a) + 2 * ball_1_a * (normx*b1xv+normy*b1yv))) / (ball_1_a + ball_2_a))*normx+(normy*-1*b2xv+normx*b2yv)*normy*-1)
    b2ynv=(((((normx*b2xv+normy*b2yv) * (ball_2_a - ball_1_a) + 2 * ball_1_a * (normx*b1xv+normy*b1yv))) / (ball_1_a + ball_2_a))*normy+(normy*-1*b2xv+normx*b2yv)*normx)
    b1nx=b(ball_1).x+b1xnv
    b1ny=b(ball_1).y+b1ynv
    b2nx=b(ball_2).x+b2xnv
    b2ny=b(ball_2).y+b2ynv
    
    b(ball_1).d=abtp(b(ball_1).x,b(ball_1).y,b1nx,b1ny)
    b(ball_2).d=abtp(b(ball_2).x,b(ball_2).y,b2nx,b2ny)
    s1=Sqr(b1xnv^2+b1ynv^2)
    s2=Sqr(b2xnv^2+b2ynv^2)
    speedout=s1+s2
    b(ball_1).s=s1*speedin/speedout'*.987
    b(ball_2).s=s2*speedin/speedout'*.987
    If b(ball_1).s<.0000001 Then b(ball_1).s=.0000001
    If b(ball_2).s<.0000001 Then b(ball_2).s=.0000001
    
End Sub
Find all posts by this user
Like Post
09-05-2017, 07:35 PM
Post: #60
 (Print Post)
RE: Freeze Tag
update #12
added auto pilot.
sit back and relax while the auto pilot takes over.
if you think he needs a bit of help perhaps you can light off a few rounds.
Find all posts by this user
Like Post



Forum Jump:


User(s) browsing this thread: 1 Guest(s)




QB64 Member Project - Splatter
QB64 Member Project - Score 4
QB64 Member Project - Kings Vallery version two
QB64 Member Project - Qubic
QB64 Member Project - Amazon
QB64 Member Project - Point Blank
QB64 Member Project - Input
QB64 Member Project - Dakapo
QB64 Member Project - OpenGL Triangles
QB64 Member Project - Martin Fractals version one
QB64 Member Project - Bowditch curve
QB64 Member Project - Kings Court
QB64 Member Project - Kobolts Monopoly
QB64 Member Project - Exit
QB64 Member Project - Algeria Weather
QB64 Member Project - Isolation
QB64 Member Project - Touche
QB64 Member Project - Quarto
QB64 Member Project - Rotating Background
QB64 Member Project - Spiro Roses
QB64 Member Project - Overboard
QB64 Member Project - Full Color LED Sign
QB64 Member Project - Swirl
QB64 Member Project - Sabotage
QB64 Member Project - Othello
QB64 Member Project - STxAxTIC 3D World
QB64 Member Project - Basic Dithering
QB64 Member Project - Pivot version two
QB64 Member Project - Line Thickness
QB64 Member Project - Kings Valley verion one
QB64 Member Project - Martin Fractals version two
QB64 Member Project - Martin Fractals version three
QB64 Member Project - Pivet version one
QB64 Member Project - Connect Four
QB64 Member Project - 9 Board
QB64 Member Project - MAPTRIANGLE
QB64 Member Project - Spinning Color Wheel
QB64 Member Project - Red Scrolling LED Sign
QB64 Member Project - Color Triangles
QB64 Member Project - Foursight
QB64 Member Project - Domain
QB64 Member Project - Martin Fractals version four
QB64 Member Project - Color Rotating Text
QB64 Member Project - Inside Moves
QB64 Member Project - Dreamy Clock
QB64 Member Project - RGB Color Wheel
QB64 Member Project - Blokus
QB64 Member Project - ARB Checkers
QB64 Member Project - Rubix's Magic