Qbasicnews.com
May 26, 2020, 06:10:46 AM *
Welcome, Guest. Please login or register.

Login with username, password and session length
News: Back to Qbasicnews.com | QB Online Help | FAQ | Chat | All Basic Code | QB Knowledge Base
 
   Home   Help Search Login Register  
Pages: [1]
  Print  
Author Topic: Rel can you pls explain something in your bouncing ball demo  (Read 1287 times)
QbBasta
Member
*
Posts: 71


WWW
« on: October 20, 2003, 07:28:47 PM »

I became intrested in understanding how balls bounce when i downloaded your demo.. I read your comments and check Hugo Elias for a tutorial but i won't be happy just because i can do it by copying your code.. I wanna understand how it works and why some calculations are there..

balls(0).xv = COS(balls(0).angle * PI / 180) * balls(0).speed
balls(0).yv = SIN(balls(0).angle * PI / 180) * balls(0).speed

ok, here you split the direction and speed in to two vectors, that i understand..

impactx! = balls(1).xv - balls(0).xv
impacty! = balls(1).yv - balls(0).yv

then you calculate the resulting "force", now the things i don't understand begings..

what do you do when you normalize and what do you do when you returns the dot product between 2 vectors??

can you or somebody else be kind and explain why and what you are doing..
and also the following lines

    impulsex! = impulsex! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2
    impulsey! = impulsey! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2

    xva! = balls(0).xv + impulsex! / balls(0).mass
    yva! = balls(0).yv + impulsey! / balls(0).mass

    xvb! = balls(1).xv - impulsex! / balls(1).mass
    yvb! = balls(1).yv - impulsey! / balls(1).mass

Rel's code can be found at http://forum.qbasicnews.com/viewtopic.php?t=3408

Hope you find some time to explain it to me =)
thx!
Logged

ttp://hem.passagen.se/qb.basta
relsoft
*/-\*
*****
Posts: 3927



WWW
« Reply #1 on: October 21, 2003, 03:59:00 AM »

this:

Code:
balls(0).xv = COS(balls(0).angle * PI / 180) * balls(0).speed
balls(0).yv = SIN(balls(0).angle * PI / 180) * balls(0).speed


Calculates the Balls' x/y velocities(components of the vector)

Balls.speed is just the *Magnitude*/Length of the vector. ie. Speed


I had to divide by 2(Hugo did not) to compensate for the resulting force as it would geometrically speed itself up if I do not.

Code:
impulsex! = impulsex! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2
impulsey! = impulsey! * ImpactSpeed! * balls(0).mass * balls(1).mass / 2


This just calculates the new direction:

Code:
xva! = balls(0).xv + impulsex! / balls(0).mass
yva! = balls(0).yv + impulsey! / balls(0).mass

xvb! = balls(1).xv - impulsex! / balls(1).mass
yvb! = balls(1).yv - impulsey! / balls(1).mass



About:

Normalizing:  Normalizing is just making a vector a *unit* vector much like your Unit circle it has a length of 1. Making a vector a unit vector simplifies calcs.

Dot product:

If I remember it's also called the scalar product.  The dot product returns the *cosine* of the angle.  

Code:
Dot! = (ax! * bx!) + (ay! * by!)


Therefore it returns a scalar and not a vector.

Don't confuse this with the cross product as its returns a vector instead of a scalar.

Makes sense as x or y directions can either be negative,positive or zero. And that's what the dot returns. ;*)

The principle is like lambert's shading but in this case we do not need the NORMAL(perpendicular vector to a plane) as we treated each balls on the pixel they collided as perpendicular.

Perpendicular means it has a union of 90 degrees. 2 vectors intersecting that produces a 90 degree angle.


Scalar means it has no direction just and exact number/value.

I hope I made sense out of it. ;*)

If not just shout. ;*)
Logged

y smiley is 24 bit.


Genso's Junkyard:
http://rel.betterwebber.com/
Pages: [1]
  Print  
 
Jump to:  

Powered by MySQL Powered by PHP Powered by SMF 1.1.21 | SMF © 2015, Simple Machines Valid XHTML 1.0! Valid CSS!