【问题标题】:Plot random lines starting from specific point in a sphere in MatLab在 MatLab 中从球体中的特定点开始绘制随机线
【发布时间】:2013-04-08 18:17:12
【问题描述】:

我正在尝试从球体的特定半径开始绘制随机线,但我只想要上半球,如图所示

到目前为止,我能够创建随机起点(但对于 R=15)、随机交叉点、随机斜率,但我不知道如何连接所有这些以绘制线条。

我的代码是

%Create the random starting points, slopes, intersections
tracks=input('Give me the number of muon tracks: ');
theta=180.*rand(tracks,1);
rho=15*ones(tracks,1);
startPoint = [theta rho];
[X,Y]=pol2cart(theta*pi/180,rho);
intersection =-6371+(2*6371).*rand(tracks,1);
slope = tand(360.*rand(tracks,1));

我知道我只需要两个元素来画一条线,但我现在有点困惑...... 有什么想法吗?

【问题讨论】:

    标签: matlab plot


    【解决方案1】:

    因为您不希望 MATLAB 在绘制它们时将所有线连接起来,所以您需要在循环中分别绘制它们,例如,类似

    theta = 2 * pi * rand(tracks, 2); % 2 rows of random points on a circle, in radians
    X = cos(theta); Y = sin(theta);
    close all;
    figure;
    hold on;
    for nPlot = 1:tracks
        plot(X(nPlot, :), Y(nPlot, :), 'r-o');
    end
    

    请注意,此代码生成的 X 和 Y 也与您的原始代码不同 - pol2cart 和上述方法都期望以弧度为单位的值,而不是度数。

    【讨论】:

      猜你喜欢
      • 2013-04-08
      • 1970-01-01
      • 2018-09-29
      • 2019-08-28
      • 2013-09-14
      • 2011-07-28
      • 2018-03-31
      • 1970-01-01
      • 2019-04-06
      相关资源
      最近更新 更多