Generate an equation of a 3D line from one point and two angles

4 次查看(过去 30 天)
Hi,
I have been other thinking this and think I am missing a very simple solution.
The problem: I have a 3D space in which x-y [0 3000] and z[0 600]. I want to generate random "lines" specified by points. For this, I generate seed points, within the xyz plane between the given limits. I also generate Phi [0 pi] and Theta[0 2*pi] such that I have a random initial start and random angular information. Using this information alone, is it possible to generate a set of points within the xyz space limits based upon random Theta and Phi?
I've attached some prelim code that may help.
SizeSimulated_xy= 3000;
SizeSimulated_z=600;
Boundries_xy=[0 SizeSimulated_xy];
Boundries_z=[0 SizeSimulated_z];
xmin=Boundries_xy(1);
xmax=Boundries_xy(2);
xmin_z=Boundries_z(1);
xmax_z=Boundries_z(2);
Phi=rand(1,1)*pi;
Theta=rand(1,1)*2*pi;
xyRand = xmin+rand(1,2)*(xmax-xmin);
zRand=xmin_z+(xmax_z-xmin_z)*rand(1,1);
r=sqrt(xyRand(1,1).^2+xyRand(1,2).^2+zRand.^2);
x_dir=r*cos(Phi)*sin(Theta);
y_dir=r*cos(Phi)*cos(Theta);
z_dir=r*sin(Phi);
direction=[x_dir;y_dir;z_dir];
a=direction(1,1);
b=direction(2,1);
c=direction(3,1);
x0=xyRand(1,1);
y0=xyRand(1,2);
z0=zRand;
Although here is my problem:
z=z0+(c/a)*(x-x0);
x=z0+(a/c)*(z-z0);
y=y0+(b/c)*(z-z0);
Thanks!

回答(1 个)

KSSV
KSSV 2017-9-21
P0 = [0 3000] ;
Z0 = 0 ; Z1 = 600 ;
P0 = [P0 Z0] ;
%%Top plane
x = linspace(-100,100,10) ;
y = linspace(-3000,3000,10) ;
[X,Y] = meshgrid(x,y) ;
Z = Z1*ones(size(X)) ;
figure
hold on
plot3(P0(1),P0(2),P0(3),'*r')
plot3(X,Y,Z,'.r')
for i = 1:size(X,1)
for j = 1:size(X,2)
plot3([P0(1) X(i,j)],[P0(2) Y(i,j)],[P0(3) Z(i,j)],'b')
drawnow
end
end
view(3)

类别

Help CenterFile Exchange 中查找有关 Creating and Concatenating Matrices 的更多信息

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by