clear all;
close all;

step_size = 0.025;
distance = 4;

r = 0.025:step_size:distance;     % 2,5cm - 10m
roh = 100;                        % spez. Bodenwiderstand von 100 Ohm*m
I = 50;                           % Fehlerstrom = 50A


R_a = roh ./ (2*pi * r);

U_r = (-1) .* R_a .* I;
U = [flipdim(U_r,2),U_r];
r = [(-1) .* flipdim(r,2), r];

f1 = figure(1);
plot(r,U);
set(gca,'FontSize',12);
title('2-D Darstellung des Spannungstrichters','Interpreter', 'Latex','FontSize',15);
xlabel('Abstand r [m]','Interpreter', 'Latex','FontSize',12);
ylabel('Potential U [V]','Interpreter', 'Latex','FontSize',12);
grid on;
print(f1,'-dpdf','-r600','Dateiname.pdf'); 

grid on;
hold off;

x = -distance:step_size:distance;
y = -distance:step_size:distance;
n = 1;
m = 1;
x(x==0)=[];
y(y==0)=[];
r_s = zeros(length(U),length(U));
for n = 1:1:length(U)
    for m = 1:1:length(U)
        r_s(n,m) = sqrt(x(n)^2+y(m)^2);
        m = m + 1;
    end 
    n = n+1;
end

R_b = roh ./ (2*pi * r_s);
U_s = (-1) .* R_b .* I;

f2 = figure(2);
surf(r_s,r_s,U_s,'EdgeColor','none')
title('3-D Darstellung des Spannungstrichters','Interpreter', 'Latex','FontSize',15);
xlabel('Abstand r [m]','Interpreter', 'Latex','FontSize',12);
ylabel('Abstand r [m]','Interpreter', 'Latex','FontSize',12);
zlabel('Potential U [V]','Interpreter', 'Latex','FontSize',12);
view(-45,22);
print(f2,'-dpdf','-r1200','f2.pdf'); 