]> Creatis software - CreaPhase.git/blob - utilities_LW/CreateSphere3D.m
Useful functions for simulations (created by LW, free to use)
[CreaPhase.git] / utilities_LW / CreateSphere3D.m
1 %%%%%%%%%%%%%%%%
2 %%% Function that creates a 3D matrix (size dimx, dimy, dimz) containing a sphere, centered at (cx,
3 %%% cy, cz), of radius r
4 %%% Loriane, oct 2014
5 %c=128
6 %r=40
7 %%%%%%%%%%%%%%%%
8
9
10 r=70
11 cx=200;
12 cy=cx;
13 cz=50;
14 dimx=400;
15 dimy=dimx;
16 dimz=100;
17 coeff=9.917*10^-7;  % mu ou autre
18
19 Sphere=zeros(dimx, dimy, dimz);
20
21 for(i=1:dimx)
22     for(j=1:dimy)
23         for(k=1:dimz)
24             if((i-cx)^2+(j-cy)^2+(k-cz)^2 <= r^2)
25                 Sphere(i,j,k)=1;
26             end
27         end
28     end
29 end
30
31
32 Sphere=Sphere*coeff;
33 name='sphere_phase_Mg_19keV'
34
35 fid=fopen(strcat(name, '.raw'), 'w')
36 fwrite(fid, Sphere, 'float32');
37 fclose(fid);
38
39 cmd = ['/data/id19/bones01/bones/program/linux_debian/bin/rawtomhd filein=', strcat(name, '.raw'), ' fileout=', strcat(name, '.mhd'), ' dimx=', num2str(dimx), ' dimy=', num2str(dimy), ' dimz=', num2str(dimz), ' format=FLOAT'];
40 unix(cmd)
41