forked from adririquelme/DSE
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathCreaTetraedro.m
94 lines (90 loc) · 3.18 KB
/
CreaTetraedro.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
function [ P ] = CreaTetraedro( l, h,inc, error)
% Función que genera las coordenadas de puntos en la superficie de un
% tetraedro
% l: lado de la base
% h: altura del hexaedro. 0 si es regular
% inc: separación entre los puntos
% error: error gaussiano que le metemos a los puntos
% Copyright (C) {2015} {Adrián Riquelme Guill, adririquelme@gmail.com}
%
% This program is free software; you can redistribute it and/or modify
% it under the terms of the GNU General Public License as published by
% the Free Software Foundation; either version 2 of the License, or
% any later version.
%
% This program is distributed in the hope that it will be useful,
% but WITHOUT ANY WARRANTY; without even the implied warranty of
% MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
% GNU General Public License for more details.
%
% You should have received a copy of the GNU General Public License along
% with this program; if not, write to the Free Software Foundation, Inc.,
% 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA.
% Discontinuity Set Extractor, Copyright (C) 2015 Adrián Riquelme Guill
% Discontinuity Set Extractor comes with ABSOLUTELY NO WARRANTY.
% This is free software, and you are welcome to redistribute it
% under certain conditions.
P=[0 0 0]; %se inicia el vector
if l==0
P=[0] % el tetraedro es nulo y no se puede crear
else
if h==0
h = l*(6^0.5)/3; % el tetraedro será regular
end
% creamos el tetraedro
t=0:(inc/h):1;
% r=t/h*(l/(3^0.5));
[x,y,z]=cylinder(t,3);
[a,b]=size(x);
for ii=1:b-1
for jj=1:a
zi=z(jj,ii)*h;
xi=x(jj,ii)*(l/3^0.5);
yi=y(jj,ii)*(l/3^0.5);
zf=z(jj,ii+1)*h;
xf=x(jj,ii+1)*(l/3^0.5);
yf=y(jj,ii+1)*(l/3^0.5);
d=((xi-xf)^2+(yi-yf)^2+(zi-zf)^2)^(0.5);
if d==0
v=[0 0 0];
else
if xi==xf && yi==yf && zi==zf
v=[xi yi zi];
else
if d/inc - floor(d/inc)==0
inci=floor(d/inc);
else
inci=floor(d/inc)+1;
end
xn=[xi:(xf-xi)/inci:xf]+random('Normal',0,error/3,1);
yn=[yi:(yf-yi)/inci:yf]+random('Normal',0,error/3,1);
if zi==zf
zn=[0];
for kk=1:(inci+1)
zn(1,kk)=zf+random('Normal',0,error/3,1);
end
else
zn=[zi:(zf-zi)/inci:zf]+random('Normal',0,error/3,1);
end
v=[xn;yn;zn]';
end
end
P=[P;v];
end
end
% % guardamos en un archivo tetraedro.txt
% fi = fopen('tetraedro.txt', 'w') ;
% [n,p]=size(P);
% for k=1:n
% fprintf(fi, '%f %f %f \n', P(k,1),P(k,2),P(k,3));
% end
% fclose(fi);
% guardamos en un archivo puntos.txt
fi = fopen('puntos.txt', 'w') ;
[n,p]=size(P);
for k=1:n
fprintf(fi, '%f %f %f \n', P(k,1),P(k,2),P(k,3));
end
fclose(fi);
end
end