Can someone explain this?
double distance( int x1, int y1, int x2, int y2 )
{
//Return the distance between the two points
return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) );
}
bool check_collision( Circle &A, Circle &B )
{
//If the distance between the centers of the circles is less than the sum of their radii
if( distance( A.x, A.y, B.x, B.y ) < ( A.r + B.r ) )
{
//The circles have collided
return true;
}
//If not
return false;
}
I dont get how this bit of code
//Return the distance between the two points
return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) );
returns the distance between two circles.. Code is from http://lazyfoo.net/SDL_tutorials/lesson19/index.php
This
returns the euclidean distance between the circle centres. As a formula this distance is simply
where (a1,a2) and (b1,b2) are the centres of the 2 circles.