I need to create branching as seen in neurons. Help me with the algorithm for this. A simple algorithm to mimic this branching pattern. Later need to add complexities.
Here's the code written by me in MATLAB. But there's something wrong with angles. I am unable to get a proper tree.
x1=400;
x2=x1+200;
y1=200;
y2=200;
plot([x1 x2],[y1 y2],'b-');
array1=[];
array2=[];
array3=[];
h=4;
array1=[x1,y1];
[m,n]=size(array1);
k=0;
theta1=150;
theta2=-150;
while(k<4)
for i=1:1:m
x01=array1(i,1);
y01=array1(i,2);
x0=x01;
y0=y01;
theta1=theta1-30;
theta2=theta2-30;
for j=1:2
x1=x0-h;
if(j==1)
slop1 = tand(theta1);
y1 = ((x1-x0)*(slop1))+y0;
else
slop1 = tand(theta2);
y1 = ((x1-x0)*(slop1))+y0;
end
array2=[array2;x1,y1];
plot([x0 x1],[y0 y1],'b-');
end
end
array1=[];
array1=array2;
array2=[];
[m,n]=size(array1);
k=k+1;
end