有人可以解释一下吗?
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;
}
Run Code Online (Sandbox Code Playgroud)
我不知道这段代码怎么样
//Return the distance between the two points
return sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) );
Run Code Online (Sandbox Code Playgroud)
返回两个圆之间的距离..代码来自http://lazyfoo.net/SDL_tutorials/lesson19/index.php
这个
sqrt( pow( x2 - x1, 2 ) + pow( y2 - y1, 2 ) )
Run Code Online (Sandbox Code Playgroud)
返回圆心之间的欧氏距离.作为一个公式,这个距离很简单
sqrt((a1-b1)^2 + (a2-b2)^2)
Run Code Online (Sandbox Code Playgroud)
其中(a1,a2)和(b1,b2)是2个圆的中心.