Analysis of collagen networks

Define common PDFs

pG[m_,ξ_]:=Module[{μ=ξ[[1]],Σ=ξ[[2]]},
Return[RandomVariate[MultinormalDistribution[μ,Σ],m]]];

Generate network by recursion

Generate a list with nSeg line segments starting from point P

BranchNetwork[P_,p_,ξ_,nSeg_]:=Module[{v,Q},
v=p[nSeg,ξ];
Q=P+# & /@ v;
Return[ {P,#} & /@ Q] ];

ξG1={{0,0,0}, 0.5IdentityMatrix[3]};
LG1=BranchNetwork[{0,0,0},pG,ξG1,4]

L1 is a list of line segments {P1,P2}. P2 is one level deeper that P1. Function returns list L2 of segments {P2,P3}.

AddNetworkLevel[L1_,p_,ξ_,nSeg_]:=Module[{L2},
Flatten[Map[BranchNetwork[#[[2]],p,ξ,nSeg]&,L1],1]
]

LG2=AddNetworkLevel[LG1,pG,ξG1,3]

Select line segments {P1,P2} within a list for which P2 lies outside a bounding cube

LevelBoundarySegments[L_,Lcube_]:=Select[L,Norm[#[[2]],Infinity]>=Lcube &]

LG2bnd=LevelBoundarySegments[LG2,1]

LevelInteriorSegments[L_,Lcube_]:=Select[L,Norm[#[[2]],Infinity]<Lcube &]

LG2int=LevelInteriorSegments[LG2,1]

{Length[LG2int],Length[LG2bnd],Length[LG2]}

Generate a network nL levels deep.

network[nL_,p_,ξ_,nSeg_,Lcube_]:=Module[
{l ,level,intlevel},
For[l=1, l≤nL,l++,
level=AddNetworkLevel[net[[-1]],p,ξ,nSeg];
intlevel=LevelInteriorSegments[level,Lcube];
AppendTo[net,intlevel]; 
];     
]

Function to plot network

PlotNetwork[net_]:=Module[{l,g={}},
For[l=1,l≤Length[net],l++,
AppendTo[g,Graphics3D[{ColorData[3,"ColorList"][[l]],Map[Line[#]&,net[[l]]]}]]];
Return[g];
];

Define network PDF and recursively generate the network

Lcube=1; nSeg=4; nLevels=6; br=Table[{-Lcube,Lcube},3];
ξG1={{0,0,0}, 0.05IdentityMatrix[3]};
net={BranchNetwork[{0,0,0},pG,ξG1,nSeg]};
network[nLevels,pG,ξG1,nSeg,Lcube];
netSegments=Flatten[net,1];
{Length[#] & /@ net,Length[netSegments]}

Show[Flatten[PlotNetwork[net],1],AspectRatio->Automatic,BoundingRegion->br]

?ColorData

ColorData[3,"ColorList"]

?Line