심심할 때 2점의 각 구하기
x, y가 기준점이고
0도는 화면 바로 밑으로 진행하는 각 (100, 100) - (100, 200) 과 같이
그기서 화면 우측으로 진행하는 각은 + 각 (100, 100) - (200, 200) 은 45도
그기서 화면 좌측으로 진행하는 각은 - 각 (100, 100) - (0, 200) 은 -45도
그기서 기준점 바로 위 각은 180도 (100, 100) - (100, 0)
이런 식으로 됩니다.
//---------------------------------------------------------------------------
#include <math.h>
float GetAngleBetween2Point(int x, int y, int x2, int y2)
{
const double PI = 3.1415926535897932384626433;
float dx = x2 - x;
float dy = y2 - y;
float radian = (float)atan2(dx, dy);
float degree = (float)((radian * 180) / PI);
return degree;
}
float GetAngleBetween2Point(TPoint xy, TPoint xy2)
{
return GetAngleBetween2Point(xy.x, xy.y, xy2.x, xy2.y);
}
//---------------------------------------------------------------------------
// TEST
void __fastcall TForm1::FormCreate(TObject *Sender)
{
Caption = GetAngleBetween2Point(100, 100, 200, 200);
}
//---------------------------------------------------------------------------
여기서 유머 포인트는 PI 값입니다.
|