If I have 2 points (x0,y0) which is the center of the circle, and another point (x,y) (this is the red dot on the circle boundary in the image). How can I get the angle of the d
float AnglePointToPoint(const CCPoint & pFrom, const CCPoint & pTo)
{
float distanceX = pTo.x - pFrom.x;
float distanceY = pTo.y - pFrom.y;
float beta = acos( fabs(distanceX) / sqrt( pow(distanceX,2) + pow(distanceY,2) ) ) * 180 / M_PI;
float angleResult = 0.0f;
if( distanceX > 0 )
{
if( distanceY < 0 )
{
angleResult = beta + 90;//right_bot
}
else
{
angleResult = fabs(beta - 90);//right_top
}
}
else
{
if( distanceY < 0 )
{
angleResult = fabs(beta - 90) + 180;//left_bot
}
else
{
angleResult = beta + 270;//left_top
}
}
return angleResult;
}