ball collision
ball collision
ball collision
ball collision
ball collision
ball collision ball collision ball collision ball collision ball collision ball collision ball collision ball collision
ball collision ball collision
ball collision
Go Back  Xtreme Visual Basic Talk > > > ball collision


Reply
 
Thread Tools Display Modes
  #1  
Old 02-13-2013, 12:59 AM
thd6961 thd6961 is offline
Newcomer
 
Join Date: Feb 2013
Location: St.Louis
Posts: 1
Default ball collision


So I am taking a graphics class in which the teacher has chosen vb to teach us. So far so good but as I progress with the material I came across a requirement that I write a program in which I generate two balls (no pictureboxes or ovalshapes) and said balls bounce off the walls of the form and each other. Also the speed at which the balls travel is to be randomly generated, so no declaration of momentum. I'm roughly halfway through the program, the balls are bouncing off the walls of the form as they should however I have ran into a bit of a problem getting them to bounce off each other. I tried a few different strategies and the closest i've gotten was to get the balls to bounce off each other when they cross paths on the x and y axis but it is not limited to the actual size of the ball. So ball1 could be up at the top and ball 2 could be at the bottom of the form and they would reverse momentum but not actually collide. Any help would be greatly appreciated. I think I may be overthinking this, but I have exhausted all other options. I can post code if need be.
Reply With Quote
  #2  
Old 02-13-2013, 07:41 AM
passel's Avatar
passelball collision passel is offline
Sinecure Expert

Super Moderator
* Guru *
 
Join Date: Jun 2003
Location: Upstate New York, usa
Posts: 8,024
Default

I would calculate the distance between the two centers of the ball.
Assuming they are both the same size, if the distance is less than (or equal) the diameter of the ball (the sum of the two radii), then the balls have collided.
If the balls were different sizes, then if the distance between them is less than (or equal) to the sum of the two radii, you have a collision.
Since summing the two radii is always the collision distance, you might as well code it that way regardless of whether the balls are the same size.
__________________
There Is An Island Of Opportunity In The Middle of Every Difficulty.
Miss That, Though, And You're Pretty Much Doomed.
Reply With Quote
Reply


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off

Forum Jump

Advertisement:





Free Publications
The ASP.NET 2.0 Anthology
101 Essential Tips, Tricks & Hacks - Free 156 Page Preview. Learn the most practical features and best approaches for ASP.NET.
subscribe
Programmers Heaven C# School Book -Free 338 Page eBook
The Programmers Heaven C# School book covers the .NET framework and the C# language.
subscribe
Build Your Own ASP.NET 3.5 Web Site Using C# & VB, 3rd Edition - Free 219 Page Preview!
This comprehensive step-by-step guide will help get your database-driven ASP.NET web site up and running in no time..
subscribe
ball collision
ball collision
ball collision ball collision
ball collision
ball collision
ball collision ball collision ball collision ball collision ball collision ball collision ball collision
ball collision
ball collision
 
ball collision
ball collision
 
-->