double angle(CPoint Cen,CPoint First,CPoint Second)
{
CClientDC dc(this);
double lega1,lega2,legb1,legb2;
double norm,norm1,norm2,angle,prod,curl;
int x1,y1,x2,y2,x3,y3;

x2 = Cen.x; y2 = Cen.y;
x1 = First.x; y1 = First.y;
x3 = Second.x; y3 = Second.y;

lega1 = x1-x2;
legb1 = y1-y2;
lega2 = x3-x2;
legb2 = y3-y2;

norm1 = sqrt(lega1*lega1+legb1*legb1);//두 벡터의 크기
norm2 = sqrt(lega2*lega2+legb2*legb2);//두 벡터의 크기
norm = norm1 * norm2;
prod = (lega1*lega2)+(legb1*legb2);//두 벡터의 내적
angle = acos(prod/norm);

curl = (lega1*legb2)-(legb1*lega2);//두 벡터의 외적

if (curl<=0) return angle/3.141592654*180;

else return (360-angle/3.141592654*180);
}

+ Recent posts