From: crazyman on
Hey hi everyone
I am new to Matlab and wanna write a code to find the coordinate x,y,z which can be used as a centre of 8 sphere of radius r=.015 which must lie inside a cube of .09*.09*.09.The spheres must not touch each other and should not touch the boundary so i calculate the distance between them and compared it to 2*.015 i dont know but there is something wrong with my loop can any one suggest what is going wrong



for i=1:8
x(i)=rand(1,1)*.065; % will generate random number from 0 to .065
y(i)=rand(1,1)*.065;
z(i)=rand(1,1)*.065;
if x(i)<.018 % to take care that they dont intersect boundary
x(i)=x(i)+.015;
end
if y(i)<.018
y(i)=y(i)+.015;
end
if z(i)<.018
z(i)=z(i)+.015;
end
end

% let r=.01 and thickness =.004 therefore distance between them <
% .014*2=.028~ .03 or R^2=.0009

for l=1:8
for m=1:8

if (l~=m)
R=sqrt((x(l)-x(m))*(x(l)-x(m))+(y(l)-y(m))*(y(l)-y(m))+(z(l)-z(m))*(z(l)-z(m)));
if(R<.03) % R is the square of distance between them therefore should be <.0009
z(l)=z(l) +.001 -.001*R;
if z(l)>.085 % to take into account that it doesnot touch boundary
z(l)=z(l)-.015;
end
l=1;
m=1;
end

end

end
end
 | 
Pages: 1
Prev: Modeling a Radar System
Next: uitable question...