Main Content

이 번역 페이지는 최신 내용을 담고 있지 않습니다. 최신 내용을 영문으로 보려면 여기를 클릭하십시오.

행렬 회전 및 변환

이 예제에서는 Symbolic Math Toolbox™와 행렬을 사용하여 3차원으로 회전 및 변환을 수행하는 방법을 보여줍니다.

파라미터 곡면을 정의하고 플로팅하기

파라미터 곡면 x(u,v), y(u,v), z(u,v)를 다음과 같이 정의합니다.

syms u v
x = cos(u)*sin(v);
y = sin(u)*sin(v);
z = cos(v)*sin(v);

fsurf를 사용하여 곡면을 플로팅합니다.

fsurf(x,y,z)
axis equal

Figure contains an axes object. The axes object contains an object of type parameterizedfunctionsurface.

회전 행렬 만들기

x축, y축, z축을 중심으로 각도 t로 평면 회전을 나타내는 3×3 행렬 Rx, Ry, Rz를 만듭니다.

syms t

Rx = [1 0 0; 0 cos(t) -sin(t); 0 sin(t) cos(t)]
Rx = 

(1000cos(t)-sin(t)0sin(t)cos(t))

Ry = [cos(t) 0 sin(t); 0 1 0; -sin(t) 0 cos(t)]
Ry = 

(cos(t)0sin(t)010-sin(t)0cos(t))

Rz = [cos(t) -sin(t) 0; sin(t) cos(t) 0; 0 0 1]
Rz = 

(cos(t)-sin(t)0sin(t)cos(t)0001)

3차원에서 각 축을 중심으로 회전하기

먼저 곡면을 x축을 중심으로 시계 반대 방향으로 45도 회전합니다.

xyzRx = Rx*[x;y;z];
Rx45 = subs(xyzRx, t, pi/4);

fsurf(Rx45(1), Rx45(2), Rx45(3))
title('Rotating by \pi/4 about x, counterclockwise')
axis equal

Figure contains an axes object. The axes object with title Rotating by pi /4 about x, counterclockwise contains an object of type parameterizedfunctionsurface.

z축을 중심으로 시계 방향으로 90도 회전합니다.

xyzRz = Rz*Rx45;
Rx45Rz90 = subs(xyzRz, t, -pi/2);

fsurf(Rx45Rz90(1), Rx45Rz90(2), Rx45Rz90(3))
title('Rotating by \pi/2 about z, clockwise')
axis equal

Figure contains an axes object. The axes object with title Rotating by pi /2 about z, clockwise contains an object of type parameterizedfunctionsurface.

y축을 중심으로 시계 방향으로 45도 회전합니다.

xyzRy = Ry*Rx45Rz90;
Rx45Rz90Ry45 = subs(xyzRy, t, -pi/4);

fsurf(Rx45Rz90Ry45(1), Rx45Rz90Ry45(2), Rx45Rz90Ry45(3))
title('Rotating by \pi/4 about y, clockwise')
axis equal

Figure contains an axes object. The axes object with title Rotating by pi /4 about y, clockwise contains an object of type parameterizedfunctionsurface.

스케일 및 회전하기

z축을 따라 인자를 3으로 하여 곡면을 스케일링합니다. z에 대한 표현식에 3을 곱할 수 있습니다(z = 3*z). 보다 일반적인 접근 방식은 스케일링 행렬을 만든 다음 이 스케일링 행렬에 좌표 벡터를 곱하는 것입니다.

S = [1 0 0; 0 1 0; 0 0 3];
xyzScaled = S*[x; y; z]
xyzScaled = 

(cos(u)sin(v)sin(u)sin(v)3cos(v)sin(v))

fsurf(xyzScaled(1), xyzScaled(2), xyzScaled(3))
title('Scaling by 3 along z')
axis equal

Figure contains an axes object. The axes object with title Scaling by 3 along z contains an object of type parameterizedfunctionsurface.

스케일링된 곡면을 x축, y축, z축을 중심으로 시계 방향으로 45도 회전합니다. 이때 z, y, x의 순서로 회전하십시오. 이 변환에 대한 회전 행렬은 다음과 같습니다.

R = Rx*Ry*Rz
R = 

(cos(t)2-cos(t)sin(t)sin(t)σ1cos(t)2-sin(t)3-cos(t)sin(t)sin(t)2-cos(t)2sin(t)σ1cos(t)2)where  σ1=cos(t)sin(t)2+cos(t)sin(t)

회전 행렬을 사용하여 새로운 좌표를 구합니다.

xyzScaledRotated = R*xyzScaled;
xyzSR45 = subs(xyzScaledRotated, t, -pi/4);

곡면을 플로팅합니다.

fsurf(xyzSR45(1), xyzSR45(2), xyzSR45(3))
title('Rotating by \pi/4 about x, y, and z, clockwise')
axis equal

Figure contains an axes object. The axes object with title Rotating by pi /4 about x, y, and z, clockwise contains an object of type parameterizedfunctionsurface.

회전 행렬 R의 속성 확인하기

회전 행렬은 직교 행렬입니다. 따라서 R의 전치는 역행렬이기도 하며 R의 행렬식은 1입니다.

simplify(R.'*R)
ans = 

(100010001)

simplify(det(R))
ans = 1