1. 원안에 점 가두기 ( 빙빙 돌려보자. )
- 호도=각도*3.1416/180 이 핵심!! 참고 : winapi.co.kr 삼각함수
// 원점과 대상점 을 인자로 더해주면 라디안 값을 얻어온다..
#define SQUARE(x) ((x)*(x))
#define PAI acos(-1.0)
double FindTheta(double baseX, double baseY, double x, double y)
{
int index = 0;
double diffx, diffy, Dist, theta, degree;
diffx = (x-baseX);
diffy = (baseY-y);
Dist = hypot( diffx, diffy );
theta = acos(fabs(diffx)/Dist)*180 / PAI;
if(diffx>0 && diffy>0)
index = 1;
else if(diffx<0 && diffy>0)
index = 2;
else if(diffx<0 && diffy<0)
index = 3;
else if(diffx>0 && diffy<0)
index = 4;
else if(diffx==0 && diffy>0)
degree = 90.0;
else if(diffx==0 && diffy<0)
degree = 270.0;
else if(diffx>0 && diffy==0)
degree = 360.0;
else if(diffx<0 && diffy==0)
degree = 180.0;
switch(index)
{
case 1 : //1사분면
degree = theta;
break;
case 2 ://2사분면
degree = 180.0 - theta;
break;
case 3 ://3사분면
degree = 180.0 + theta;
break;
case 4 ://4사분면
degree = 360.0 - theta;
break;
}
return degree * PAI / 180;
}
#define SQUARE(x) ((x)*(x))
#define PAI acos(-1.0)
double FindTheta(double baseX, double baseY, double x, double y)
{
int index = 0;
double diffx, diffy, Dist, theta, degree;
diffx = (x-baseX);
diffy = (baseY-y);
Dist = hypot( diffx, diffy );
theta = acos(fabs(diffx)/Dist)*180 / PAI;
if(diffx>0 && diffy>0)
index = 1;
else if(diffx<0 && diffy>0)
index = 2;
else if(diffx<0 && diffy<0)
index = 3;
else if(diffx>0 && diffy<0)
index = 4;
else if(diffx==0 && diffy>0)
degree = 90.0;
else if(diffx==0 && diffy<0)
degree = 270.0;
else if(diffx>0 && diffy==0)
degree = 360.0;
else if(diffx<0 && diffy==0)
degree = 180.0;
switch(index)
{
case 1 : //1사분면
degree = theta;
break;
case 2 ://2사분면
degree = 180.0 - theta;
break;
case 3 ://3사분면
degree = 180.0 + theta;
break;
case 4 ://4사분면
degree = 360.0 - theta;
break;
}
return degree * PAI / 180;
}
- 원안에 점을 가두자(Region)~ BOOL PtInEllipse( RECT rcEllipse, POINT pt )
BOOL PtInEllipse( RECT rcEllipse, POINT pt )
{
HRGN hRgn =
CreateEllipticRgn( rcEllipse.left, rcEllipse.top, rcEllipse.right, rcEllipse.bottom );
if( PtInRegion( hRgn, pt.x, pt.y ) )
{
DeleteObject( hRgn );
return TRUE;
}
DeleteObject( hRgn );
return FALSE;
}
{
HRGN hRgn =
CreateEllipticRgn( rcEllipse.left, rcEllipse.top, rcEllipse.right, rcEllipse.bottom );
if( PtInRegion( hRgn, pt.x, pt.y ) )
{
DeleteObject( hRgn );
return TRUE;
}
DeleteObject( hRgn );
return FALSE;
}
- 삼각형 외 다각형의 내부 클릭 여부 확인 ~ BOOL PtInTriangle( POINT *Verts, POINT pt )
BOOL BTriangle::PtInTriangle( POINT *Verts, POINT pt )
{
HRGN hRgn =CreatePolygonRgn( Verts, 3, WINDING); // 핵심..정점수만큼의 Region 영역을 생성..
if( PtInRegion( hRgn, pt.x, pt.y ) )
{
DeleteObject( hRgn );
return TRUE;
}
DeleteObject( hRgn );
return FALSE;
}
{
HRGN hRgn =CreatePolygonRgn( Verts, 3, WINDING); // 핵심..정점수만큼의 Region 영역을 생성..
if( PtInRegion( hRgn, pt.x, pt.y ) )
{
DeleteObject( hRgn );
return TRUE;
}
DeleteObject( hRgn );
return FALSE;
}
Tag | 삼각함수