• Hi All

    Please note that at the Chandoo.org Forums there is Zero Tolerance to Spam

    Post Spam and you Will Be Deleted as a User

    Hui...

  • When starting a new post, to receive a quicker and more targeted answer, Please include a sample file in the initial post.

''Collision'' checking with moving objects in Excel VBA 2019

SpielbergRules

New Member
Hello Excel/VBA gurus,

Some time ago I started a VBA project for a friend/client in Excel 2019.

The "splash" screen was to show their logo and have moving "orbs" slowly move around it. However, the orbs needed to bounce off of each other.

I thought it would be easy to do until I remembered the square bounding box. The amount of math I figured that was needed to check all around several orbs was insane and would make this thing slow to a crawl.

Before I start scanning stuff, I just wanted to ask if anyone has tried anything like that.

So basically, 5 "orbs" (or just circles for this example) need to move around in a defined space, but bounce off of each other. The logo itself would be "behind" the orbs and is irrelevant for this example.

I will find the code so I can post it, but it's really insane and "primitive".

Thanks for any advice.

Mike
 
Excel should easily handle that for 5 orbs

The calcs for all that isn't complex
 
Hi, as it depends how it is coded as the calculation should be fast enough …​
Thanks for the reply. Three sin' much programming done. I did mention in the original post that I would have to scan the sketches I made which (in my head) are pretty complex. I just have to dig them out again. :)
 
Excel should easily handle that for 5 orbs

The calcs for all that isn't complex
Thanks for the reply. I am glad you say the calcs should be easy... Maybe for you! :) My brain doesn't function like it used to after graduating in 1982... I have forgotten more than I have learned.

Even tho I googled around a lot, I was unable to find anything related to what I wanted.

I am certainly not asking for anyone to write the code for me, but can you maybe give me a pointers on what/how to write it?

I am assuming that there is a lot of geometry or trig involved. That was what I have forgotten more than I learned in school.

That bounding box REALLY throws me off.

I gotta find my sketches...

Thanks again
 
Attach at least a sample workbook with some 'orbs' within a worksheet​
and the necessary elaboration for the rules to follow, their movements and so on …​
 
Attach at least a sample workbook with some 'orbs' within a worksheet​
and the necessary elaboration for the rules to follow, their movements and so on …​
I don't have that unfortunately - what little I had was burned off to a CD which I think is long gone. The rest is all on sketches that I am looking for as we speak. :)
 
Ok, so I was unable to find my original work, unfortunately. Some time after the "orb" idea, I thought it would be cool to try and make a "pinball machine" in Excel VBA. Naturally, my math skills were quite lacking, but I DID find ONE sheet I scanned (attached) with the basic idea of what I was trying to go for (and why I thought it would be an insane amount of programming that is way above my pay grade...

This is from over 6 years ago. I think you can see I got in way over my head...

I hope this helps in maybe giving me some hints on what kind of math is needed...

The way my brain works is I usually can't figure out stuff myself (on this level) but once I am shown, I can learn from that, make modifications and changes, etc.

Thanks!
 

Attachments

  • Collison Check Sketch 052616.png
    Collison Check Sketch 052616.png
    412 KB · Views: 5
Surprisingly, I found a few more sketches. (Long story short, after moving around some over the years, a ton of my papers got mixed up.)

I hope these papers help a little more. I can't find anything on the logo orbs, but those don't really matter I guess, since this is basically the same thing.

As I look at these sheets again (again, remembering how much I have forgotten over the years,) I am wondering if I was on to something , but didn't realize it at the time. hmm...
Pinball Coordinates and Calculations.pngPinball Radians to Degrees Calculations.pngCollision Check Sketch 2.png
 
A demonstration as a beginner starter :​
Just wanted to say *THANK YOU!* for taking the time to make this for me!

It wouldn't let me open the file by double clicking because it says the file contains a virus. it does not, naturally.

I can open the file from within Excel. But it won't let me run it because of the trust settings, even tho my trust settings are set to allow macros, etc. It's all good.

I have NO idea why it won't run. So I tried saving as an XLSM. THAT worked!

Now, I have to say HOLY COW! I can't believe how little code there is to do that and how fast it runs.!

I don't think i would have EVER been able to figure this out myself - and I have been using Excel since the Early 90s!

Now on to learn something today from your code!

*THANK YOU!*
 
The way to run it 'fast' is to not move the objects one by one but all at once​
the reason why the Pause codeline updating the display is after the loops, once each object movement computed.​
But it depends too on the 'speed factor' chosen (constant F within the code, 1 for the slowest, used 3 as fast enough) …​
 
Absolutely outstanding sir. When I was tried creating that logo, I used a zillion If-Thens to find the edges of the screen and all that. Oh man this is just amazing!

of course, I got stuck on that bounding box "issue" which is a non-issue here!

I have to analyze the heck out of this and make my own comments as i learn!

Thank you again - just incredible.
 
Last edited by a moderator:
As that just needs to compare the bottom, the Left, the right and the Top coordinates​
in order to answer the main question : is the object in or out of the authorized area ? …​
 
It makes sense when you explain it. I thought the biggest problem (for me) was when the object was rotating (forgot to mention that). How would it know if the orb was next to the edge when it wa rotated is what drove me nuts, but you got it! :)
 
Back
Top