2011-07-22 62 views
3

我是MATLAB新手,有一個根本性問題,就是我在查找在線資源時遇到問題。我有一個圓的方程:C = center +(radius * cos(theta))+(radius * sin(theta))。我想把這個圓圈圖形化爲我之前繪製的其他東西......所有這些都是3D。我已經嘗試過使用theta = linspace(0,2 * pi),但是在構建矩陣大小不同意的圓的方程時!如果你能提供任何好的幫助!在MATLAB中繪製參數化的3D圓圈

回答

0

我不知道你正在嘗試做的,但考慮到這個例子:

theta = linspace(0,2*pi,100); 
C = [0;0]; 
r = 1; 

p = bsxfun(@plus, r.*[cos(theta);sin(theta)], C); 
plot(p(1,:), p(2,:), '.-') 
axis equal 

enter image description here

1

這裏是繪製一個圓與給定的半徑和中心(假設圓的一個例子位於平面z = 0):

radius = 2;  %# Define your radius 
center = [1 2]; %# Define your circle center [Cx Cy] 
theta = linspace(0,2*pi);   %# Create an array of theta values 
X = center(1)+radius.*cos(theta); %# Create the X values for the circle 
Y = center(2)+radius.*sin(theta); %# Create the Y values for the circle 
Z = zeros(size(X));    %# Create the Z values for the circle (needed 
            %# for 3D plotting) 
hold on;  %# Add to the current existing plot 
plot3(X,Y,Z); %# Plot your circle in 3D 

這裏有一些在線資源的鏈接,應該是一個很好的起點學習MATLAB繪圖的基本知識:

+0

啊,這大大示範幫助,唯一增加的是,它不在於Z = 0。我將如何去修改代碼的三維圓,使z =/= 0?與此同時,我會繼續在這裏和在發佈的資源上進行重擊。 – sue

+0

@sue:如果圓圈位於平面'z = N'中,那麼您可以按如下方式初始化'Z':'Z = N. * ones(size(X));'然而,如果圓圈傾斜這樣它不會平躺在XY平面上,您的方程將比您上面的方程更復雜。 – gnovice

+0

啊,就是這樣。我試圖在任何一點上繪製曲線的密切圈。無論哪種方式,該圓都可以傾斜。我相信我有這個圈子的公式是正確的......但圖表一直是相當艱鉅的。 – sue

1

由於圓本質上是一個二維的實體,您會需要生成代表它的點到3D空間中嵌入的已知2D平面。然後,您可以隨意旋轉,縮放和翻譯。

一個簡單的演示代碼,希望清楚:

n= 78; theta= linspace(0, 2* pi, n); c= [1 2 3]'; r= sqrt(2); 

points= r*[cos(theta); sin(theta); zeros(1, n)]+ repmat(c, 1, n); 
plot3(points(1,:), points(2,:), points(3,:), 's-') 
axis equal, hold on 

R= rref([rand(3) eye(3)]); R= R(:, 4: 6); 
points= R* points; 
plot3(points(1,:), points(2,:), points(3,:), 'ro')