티스토리 뷰
Cartesian coordinates에서 반지름이 'r'인 구의 방정식은 아래와 같습니다.
x^2+y^2+z^2 = r^2
위 식을 spherical coordinates로 projection하면 아래와 같습니다.
x = rho*cos(theta)*sin(phi)
y = rho*sin(theta)*sin(phi)
z = rho*cos(phi)
위 식에서 theta는 0 부터 2*pi 까지의 azimuthal coordinate이고, phi는 0 부터 pi 까지의 polar coordinate입니다.
위 식을 이용하여 구(sphere)를 그려도 되고, 저는 여기서는 u = r*cos(phi)로 정의한 parametric equation을 이용해봤습니다. 위 식에서 u를 대입하면 간단히 나옵니다. 아래는 matlab source입니다. 한 번 실행해 보세요.
r = 1;
n = 50;
phi = (-n:1:n)'/n*pi;
theta = (-n:1:n)/n*2*pi;
u = r*cos(phi);
x = sqrt(r^2-u.^2)*cos(theta);
y = sqrt(r^2-u.^2)*sin(theta);
z = repmat(u,1,length(phi));
figure;plot3(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10);grid on;
figure;mesh(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10)
figure;surf(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10)
x^2+y^2+z^2 = r^2
위 식을 spherical coordinates로 projection하면 아래와 같습니다.
x = rho*cos(theta)*sin(phi)
y = rho*sin(theta)*sin(phi)
z = rho*cos(phi)
위 식에서 theta는 0 부터 2*pi 까지의 azimuthal coordinate이고, phi는 0 부터 pi 까지의 polar coordinate입니다.
위 식을 이용하여 구(sphere)를 그려도 되고, 저는 여기서는 u = r*cos(phi)로 정의한 parametric equation을 이용해봤습니다. 위 식에서 u를 대입하면 간단히 나옵니다. 아래는 matlab source입니다. 한 번 실행해 보세요.
r = 1;
n = 50;
phi = (-n:1:n)'/n*pi;
theta = (-n:1:n)/n*2*pi;
u = r*cos(phi);
x = sqrt(r^2-u.^2)*cos(theta);
y = sqrt(r^2-u.^2)*sin(theta);
z = repmat(u,1,length(phi));
figure;plot3(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10);grid on;
figure;mesh(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10)
figure;surf(x,y,z);xlabel('X');ylabel('Y');zlabel('Z');view(45,10)
'Mathematics > MATLAB' 카테고리의 다른 글
1.3 (예) 2구간으로 나뉜 그래프 그리기 (0) | 2008.08.18 |
---|---|
1.3 (예) subplot에 대한 예제 (0) | 2008.08.18 |
1.3 (예) 마우스로 좌표를 입력 받아 spline곡선 그리기 (0) | 2008.08.18 |