aboutsummaryrefslogtreecommitdiffstats
path: root/buch/chapters/090-pde/membran/membran.m
blob: acc45b9e0d254a5af76e6e20c549948ac5330a7e (plain)
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
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
#
# membran.m
#
# (c) 2022 Prof Dr Andreas Müller, OST Ostschweizer Fachhochschule
#
global n;
n = 3;
global A;
A = 0.2;
global nullstelle;
nullstelle = 13.0152;
global skala;
skala = 1 / nullstelle;
phisteps = 628;
phistep = 2 * pi / phisteps;
rsteps = 200;
rstep = 1 / rsteps;

fn = fopen("membran.inc", "w");
fprintf(fn, "#macro flaeche()\n");

function retval = punkt(fn, phi, r, n)
	global nullstelle;
	global skala;
	global A;
	fprintf(fn, "\n\t    <%.4f, %.4f, %.4f>",
		r * cos(phi),
		A * besselj(n, nullstelle * r) * cos(n * phi),
		r * sin(phi)
	);
endfunction

for i = (0:phisteps)
	phi = i * phistep;
	r = rstep;
	fprintf(fn, "\ttriangle {");
	punkt(fn, 0, 0, n);		fprintf(fn, ",");
	punkt(fn, phi, rstep, n);	fprintf(fn, ",");
	punkt(fn, phi+phistep, rstep, n);
	fprintf(fn, "\n\t}\n");

	for j = (1:rsteps-1)
		r = j * rstep;
		fprintf(fn, "\ttriangle {");
		punkt(fn, phi, r, n);			fprintf(fn, ",");
		punkt(fn,  phi+phistep, r, n);		fprintf(fn, ",");
		punkt(fn, phi+phistep, r+rstep, n);
		fprintf(fn, "\n\t}\n");
		fprintf(fn, "\ttriangle {");
		punkt(fn, phi, r, n);			fprintf(fn, ",");
		punkt(fn, phi+phistep, r+rstep, n);	fprintf(fn, ",");
		punkt(fn, phi, r+rstep, n);
		fprintf(fn, "\n\t}\n");
	end
end

fprintf(fn, "#end\n");

function retval = ring(fn, r, n)
	phisteps = 100;
	phistep = 2 * pi / phisteps;
	for i = (1:phisteps)
		phi = phistep * i;
		fprintf(fn, "\tcylinder {");
		punkt(fn, phi - phistep, r, n);		fprintf(fn, ",");
		punkt(fn, phi, r, n);			fprintf(fn, ",");
		fprintf(fn, "\n\t    r");
		fprintf(fn, "\n\t}\n")
		fprintf(fn, "\tsphere {");
		punkt(fn, phi - phistep, r, n);		fprintf(fn, ",");
		fprintf(fn, "\n\t    r");
		fprintf(fn, "\n\t}\n")
	end
end

function retval = radius(fn, phi, n)
	rsteps = 100;
	rstep = 1 / rsteps;
	for i = (0:rsteps-1)
		r = i * rstep;
		fprintf(fn, "\tcylinder {");
		punkt(fn, phi, r, n);		fprintf(fn, ",");
		punkt(fn, phi, r+rstep, n);	fprintf(fn, ",");
		fprintf(fn, "\n\t    r");
		fprintf(fn, "\n\t}\n")
		fprintf(fn, "\tsphere {");
		punkt(fn, phi, r, n);		fprintf(fn, ",");
		fprintf(fn, "\n\t    r");
		fprintf(fn, "\n\t}\n")
	end
end

fprintf(fn, "#macro phigitter()\n");
rsteps = 20;
rstep = 1 / rsteps;
for j = (1:rsteps-1)
	ring(fn, rstep * j, n);
end
fprintf(fn, "#end\n");

fprintf(fn, "#macro rgitter()\n");
phisteps = 72;
phistep = 2 * pi / phisteps;
for i = (0:phisteps-1)
	radius(fn, phistep * i, n);
end
fprintf(fn, "#end\n");

fclose(fn);