나는 stackoverflow를 검색하여 this question을 찾고 2D 모양 회전에 대해 알게되었습니다. 2D 다각형 모양 알고리즘 회전
I는 포맷int x1=-30, x2=-15, x3=20, x4=30;
int my1=-30,y2=-15,y3=0,y4=15,y5=20,y6=30;
의 좌표가 나는 모양
void draw_chair()
{
int loc_xc = xc+xp;
int loc_yc = yc+yp;
line(x2+loc_xc,my1+loc_yc,x2+loc_xc,y5+loc_yc);
line(x3+loc_xc,my1+loc_yc,x3+loc_xc,y5+loc_yc);
line(x2+loc_xc,my1+loc_yc,x3+loc_xc,my1+loc_yc);
line(x2+loc_xc,y2+loc_yc,x3+loc_xc,y2+loc_yc);
line(x2+loc_xc,y3+loc_yc,x3+loc_xc,y3+loc_yc);
line(x1+loc_xc,y4+loc_yc,x4+loc_xc,y4+loc_yc);
line(x2+loc_xc,y3+loc_yc,x1+loc_xc,y4+loc_yc);
line(x3+loc_xc,y3+loc_yc,x4+loc_xc,y4+loc_yc);
line(x1+loc_xc,y4+loc_yc,x1+loc_xc,y6+loc_yc);
line(x4+loc_xc,y4+loc_yc,x4+loc_xc,y6+loc_yc);
}
그릴이 기능을 사용이
int xc=320, yc=240;//Center of the figure
int xp=0, yp=0;//Pivot point for this figure
같은 일부 센터 피벗 점을 문제는, 이제 나는 회전 된 x와 y 값을 계산하는 방법에 혼란 스럽다. 나는 구글을 시도하고이 코드 조각
int tempx=x1;
x1=tempx*cos(angle)-my1*sin(angle);
my1=tempx*sin(angle)+my1*cos(angle);
tempx=x2;
x2=tempx*cos(angle)-y2*sin(angle);
y2=tempx*sin(angle)+y2*cos(angle);
tempx=x3;
x3=tempx*cos(angle)-y3*sin(angle);
y3=tempx*sin(angle)+y3*cos(angle);
tempx=x4;
x4=tempx*cos(angle)-y4*sin(angle);
y4=tempx*sin(angle)+y4*cos(angle);
나는이 시도 회전 발견하지만하지 않았다 회전 모양을 제대로 대신이 코드가 다른 이상한 모양으로 형태를 변환합니다. 또한 각 포인트에 대해 새로운 값을 계산하는 방법은 4 x 포인트와 6 y 포인트가 있습니까?
아이디어가 있으십니까? 또는 암시? 감사합니다.
Google에서 코드를 복사/붙여 넣기하는 대신 회전 행렬이 작동하는 방식에 대해 알아보십시오. – Blender