0
votes

I am trying to plot random lines, starting from a specific radius of a sphere, but I only want the upper hemisphere, as shown in the image

So far I am able to create random starting points(but for R=15), random intersections, random slopes, but I don't know how to connect all these to plot the lines.

My code is

%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));

I know that I need only two elements to draw a line, but I kind of confused right now... Any idea on how to do it?

1

1 Answers

1
votes

Because you don't want MATLAB to join up all of your lines when you plot them, you need to plot them separately, in a loop, e.g., something like

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

Note that this code also generates X and Y differently to your original - pol2cart and the above method both expect values in radians, not degrees.