2013-03-28 1 views

답변

4

PDE 도구 상자가있는 경우 pdeellip을 사용할 수 있습니다. 그렇지 않으면 당신은 쓸 수 있습니다 :

% input ellipse parameters 
theta_grid = linspace(0,2*pi); 
phi = 45*180/pi; 
X0=10; 
Y0=20; 
a=40; 
b=15; 

% the ellipse in x and y coordinates 
ellipse_x_r = X0 + a*cos(theta_grid); 
ellipse_y_r = Y0 + b*sin(theta_grid); 

%Define a rotation matrix 
R = [ cos(phi) sin(phi); -sin(phi) cos(phi) ]; 

%let's rotate the ellipse to some angle phii 
r_ellipse = R * [ellipse_x_r;ellipse_y_r]; 

plot(r_ellipse(1,:),r_ellipse(2,:),'-x') 
다음

enter image description here

다른 옵션들 대신 XY 좌표, "우표"배열로 타원의 :

a=20; 
b=9; 
phi=45; 
[x y] = meshgrid(-50:50,-50:50); 
el=((x-X0)/a).^2+((y-Y0)/b).^2<=1; 
imagesc(imrotate(el,phi)); colormap(bone) 

enter image description here

1

나는 야 주어진 솔루션에 문제가 있다고 생각하십시오. 회전이 중심에서 정의 되었기 때문에 회전이 수행 된 후 일부 위언 결과가 발생합니다 (보았을 때 그려진 타원의 중심은 (10, 20)이 아닙니다)

나는 정답이 될 것이라고 믿습니다 솔루션에 대한

theta_grid = linspace(0,2*pi); 
phi = 45*180/pi; 
X0=10; 
Y0=20; 
a=40; 
b=15; 

% the ellipse in x and y coordinates centered at 0 
ellipse_x_r = a*cos(theta_grid); 
ellipse_y_r = b*sin(theta_grid); 

% Define a rotation matrix 
R = [ cos(phi) sin(phi); -sin(phi) cos(phi) ]; 
n = length(ellipse_x_r); 

% let's rotate the ellipse to some angle phii and then translate it to (X0, Y0) 
r_ellipse = R * [ellipse_x_r; ellipse_y_r] + repmat([X0; Y0], [1, n]); 

plot(r_ellipse(1,:),r_ellipse(2,:),'-x') 

덕분에 나는이 어디서나 작업을 수행하는 방법을 찾을 수 없습니다 이것은 내가 찾은 가장 도움이 포스트 이었지만.

건배!
파블로

편집 : 흠, SO의 코드 포맷터에 버그가 있습니다. 주석 내부의 'A'는 문자열이 아닙니다. =)

관련 문제