728x90
반응형
[프로그래밍에서 각도는 radian을 사용하여 작성한다.]
#include <math.h>
#define _PI 3.141592f
float degreeToRadian(float degree)
{
return _PI * degree / 180.f;
}
{
float result = sinf(degreeToRadian(30.f));
}
오각형 그리기_1
#define ANGULAR 5.0f
#define _PI 3.141592f
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
// TODO: 여기에 hdc를 사용하는 그리기 코드를 추가합니다...
RECT rc;
GetClientRect(hWnd, &rc);
int CenterclientX = rc.right / 2; // client 창의 x 중심
int CenterclientY = rc.bottom / 2; // client 창의 y 중심
// 오각형의 무게중심 좌표
int Radius = 100; // 정오각형에 외접하는 원의 반지름 정의 즉, 오각형의 크기를 지정
float angle = (2.0f * _PI) / ANGULAR; // 무게중심을 기준으로 각의 크기 마다 변하는 각도 라디안 계산 ex) 정오각형 : 72도
int StartDrawX = CenterclientX + sinf(Count) * Radius;
int StartDrawY = CenterclientY + cosf(Count) * Radius; // 정오각형 아래 꼭지점을 시작으로 정의
MoveToEx(hdc, StartDrawX, StartDrawY, NULL); // 정오각형 시작점
int pointX, pointY; // 각 꼭지점들의 좌표를 변수로 선언
for (int i = 0; i < ANGULAR; i++) // 각의 개수만큼 반복
{
pointX = CenterclientX + sinf(angle * (i + 1) + Count) * Radius; // angle의 값을 변화 시켜주면서 sinf를 통해 x 좌표
pointY = CenterclientY + cosf(angle * (i + 1) + Count) * Radius; // angle의 값을 변화 시켜주면서 cosf를 통해 y 좌표
LineTo(hdc, pointX, pointY); // 구한 꼭지점의 x,y좌표를 찍어 도형을 그림
}
Count += 30;;
EndPaint(hWnd, &ps);
}
오각형 그리기_2
#define angular 5
#define _PI 3.141592f
#include <math.h>
case WM_PAINT:
{
PAINTSTRUCT ps;
HDC hdc = BeginPaint(hWnd, &ps);
RECT rc;
GetClientRect(hWnd, &rc);
float x = rc.right / 2, y = rc.bottom / 2;
float Radius = 100.0f; //반지름
float angle = 360.0f / angular;
MoveToEx(hdc, x, y, NULL);
for (int i = 0; i < angular; i++) {
float nextAngle = (_PI*(angle*i))/180.0f;
x = Radius * cosf(nextAngle) + x;
y = Radius * sinf(nextAngle) + y;
LineTo(hdc, x, y);
}
EndPaint(hWnd, &ps);
728x90
반응형
'Education > Edu | .net' 카테고리의 다른 글
# 2.6) [Win32API] Polyline 사용하여 별 그리기 (0) | 2021.01.04 |
---|---|
# 2.5) [Win32API] 오각형 타이머 설정하여 회전시키기 (0) | 2021.01.04 |
# 2.3) [Win32API] 윈도우즈 데스크톱 애플리케이션 코드 설명(2) (0) | 2020.12.31 |
# 2.2) [Win32API] 윈도우즈 데스크톱 애플리케이션 코드 설명(1) (0) | 2020.12.31 |
# 2.1) [Win32API] 윈도우즈 데스크톱 애플리케이션 코드 설명(0) (0) | 2020.12.28 |