在MatLab中绘制从球体中特定点开始的随机线

在MatLab中绘制从球体中特定点开始的随机线,matlab,plot,Matlab,Plot,我试图从球体的特定半径开始绘制随机线,但我只想要上半球,如图所示 到目前为止,我能够创建随机起点(但对于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,

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

到目前为止,我能够创建随机起点(但对于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在绘制线的时候把所有的线都连接起来,所以你需要单独绘制,在一个循环中,例如

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
不同,并且上面的方法都期望以弧度而不是度为单位的值