【问题标题】:Graphing a parameterized 3D circle in MATLAB在 MATLAB 中绘制参数化的 3D 圆
【发布时间】:2011-07-22 19:15:27
【问题描述】:

我是 MATLAB 新手,遇到一个基本问题,我在寻找在线资源时遇到了问题。我有一个圆方程:C = center + (radius*cos(theta)) + (radius*sin(theta))。除了我事先绘制的其他东西之外,我还想绘制这个圆圈……全部都是 3D 的。我试过使用 theta = linspace(0,2*pi) 但是在为圆构造我的方程时,它说矩阵大小不同意!如果您能提供任何帮助,那就太好了!

【问题讨论】:

    标签: matlab


    【解决方案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 绘图基础知识的良好起点:

    【讨论】:

    • 啊,那个演示很有帮助,唯一的补充是它不在z = 0。我将如何修改该代码以使 z=/= 0 的三维圆?我将继续在这里以及同时发布的资源上进行攻击。
    • @sue: 如果圆位于平面z = N,那么您可以改为初始化Z,如下所示:Z = N.*ones(size(X)); 但是,如果您的圆倾斜使得它不位于平在 X-Y 平面上,你的方程会比你上面的更复杂。
    • 啊,原来如此。我试图在任何点绘制曲线的密切圆。那个圆圈可以以任何方式倾斜。我相信我的圆圈公式是正确的……但是绘制它的图形非常令人生畏。
    【解决方案2】:

    由于圆本质上是一个 2D 实体,因此您需要将表示它的点生成到嵌入 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')
    

    【讨论】:

      【解决方案3】:

      我不确定您要做什么,但请考虑以下示例:

      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
      

      【讨论】:

        猜你喜欢
        • 2014-12-29
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-05-10
        • 2021-01-28
        • 1970-01-01
        相关资源
        最近更新 更多