geometry - C++ Checking For Two Spheres Intersecting/Collidiing -


im getting c++ , have been researching how have 2 spheres interact 1 another. of have found complex or actual math formulas. there more simplistic way of creating function recognize when side of sphere makes contact another? im not asking work, appreciate kind of clean visual, pseudo code or or code snippet, me understand more. or maybe links havent found?

thanks!

check if distance between spheres' centers less sum of radii.

class sphere { public:     double centerx, centery, centerz, radius;     // ....  };  double distancebetween( const sphere& a, const sphere& b ) {     return sqrt( pow( a.centerx - b.centerx, 2 ) + pow( a.centery - b.centery, 2 ) + pow( a.centerz - b.centerz, 2 ) ); }  bool arecolliding( const sphere& a, const sphere& b ) {     return distancebetween( a, b ) < ( a.radius + b.radius ); } 

Comments

Popular posts from this blog

c++ - llvm function pass ReplaceInstWithInst malloc -

java.lang.NoClassDefFoundError When Creating New Android Project -

Decoding a Python 2 `tempfile` with python-future -