-
Notifications
You must be signed in to change notification settings - Fork 3
/
LaplaceSolver.m
executable file
·59 lines (51 loc) · 1.58 KB
/
LaplaceSolver.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
function voxData = LaplaceSolver(voxData, shapeCenter, gridSize_wPadding, eps)
count=0;
voxData(shapeCenter(1), shapeCenter(2), shapeCenter(3), 3)=0;
voxData(shapeCenter(1), shapeCenter(2), shapeCenter(3), 2)=1;
voxData(shapeCenter(1), shapeCenter(2), shapeCenter(3), 1)=10;
%potvec=ones(3000000, 1)*200;
for i =1:gridSize_wPadding(1)
for j = 1:gridSize_wPadding(2)
for k = 1:gridSize_wPadding(3)
if (voxData(i,j,k,1) ==2)
count = count+ 1;
end
end
end
end
potvec=ones(count,1);
innerVox=ones(count,3);
totLength=count;
count=0;
for i =1:gridSize_wPadding(1)
for j = 1:gridSize_wPadding(2)
for k = 1:gridSize_wPadding(3)
if (voxData(i,j,k,1) ==2)
count = count+ 1;
potvec(count) = voxData(i,j,k,3);
innerVox(count,:) = [i,j,k];
end
end
end
end
maxError=100;
count=0;
prepotVec = potvec;
while (maxError > eps)
for i =1:totLength
x = innerVox(i,1);
y = innerVox(i,2);
z = innerVox(i,3);
temp = (voxData(x-1, y, z, 3) + voxData(x+1, y, z, 3)+ ...
voxData(x, y-1, z, 3) + voxData(x, y+1, z, 3)+...
voxData(x, y, z-1, 3) + voxData(x, y, z+1, 3))/6;
potvec(i) = temp;
voxData(x,y,z,3) = temp;
end
diff = prepotVec - potvec;
maxError =norm(diff,2);
disp(['Iteration = ' num2str(count)]);
disp(['Error = ' num2str(maxError)]);
count=count+1;
prepotVec = potvec;
end