# OPTIMISED circular collision detection -100% performance speed upgrade from most traditional methods

This code performs a collission-detection calculation between two circles using some really basic trig. Usefull for games... Performance much higher than traditional circle-collision detection... only takes 45% the amount of time to do the same thing as most circle collision detection functions!!! thats over 100 percent performance increase. Just thought it'd be usefull to game programmers and such...
I bet your wondering "What did this guy do to speed things up so much?" Well thats plain and simple!!! I just replaced the (A)^2 part of the equation, where A = Y2 - Y1 or X2 - X1, with A * A, because its ALOT faster... just doing that, AND storing A in its own variable, speeds things up ALOT, it only takes aprox 45% of the time to do the same collision dectection task!!! Woopty-Dooo!!!! =)

Original Author: (Tim Miron) yar-interactive software

### Code

`'USE THIS in place of your regular'circle collision detection function'Only takes APROX. 45% of the time of'traditional circle collision dectectPublic Function OptCircCollide(X1 As Long, _Y1 As Long, X2 As Long, Y2 As Long, _R1 As Long, R2 As Long) _As BooleanDim X2mX1 As Long 'pre-calculate x2 - x1Dim Y2mY1 As Long 'pre-calculate y2 - y1   X2mX1 = X2 - X1Y2mY1 = Y2 - Y1'calculate distance between 2 points on'a X-Y grid:If Sqr((X2mX1 * X2mX1) + (Y2mY1 * Y2mY1)) _<= R2 + R1 Then OptCircCollide = TrueEnd Function`

Posted: 2002-06-01
By: ArchiveBot
Viewed: 78 times

Categories

Visual Basic 6

Attachments

No attachments for this post