Sree Siddaganga Education Society®
SIDDAGANGA INSTITUTE OF TECHNOLOGY
(As Autonomous Institute Affiliated to VTU Belagavi Approved by AICTE New Delhi)
Department Of ELECTRICAL AND ELECTRONICS ENGINEERING
ENGINEERING ELECTROMAGNETICS (S5EEI02)
ABL:
(i) Coordinate systems and conversion between coordinate
systems: Conversion from rectangular to spherical coordinate
system
(ii)Plotting of Electric field and equipotential surfaces for
different configurations :Field and potential plot due to two
point charge
Submitted By
Name: Yeshwanth KUMAR K
USN: 1SI23EE423
RECTANGULAR TO SPHERICAL CONVERSION
% Input rectangular coordinates (x, y, z)
x = 6;
y = 8;
z = 10;
% Compute radial distance (r)
r = sqrt(x^2 + y^2 + z^2);
% Compute polar angle (theta)
theta = acos(z / r); % in radians
% Compute azimuthal angle (phi)
phi = atan2(y, x); % in radians
% Display results
fprintf('Spherical Coordinates:\n');
fprintf('r = %.2f\n', r);
fprintf('theta = %.2f radians (%.2f degrees)\n', theta, rad2deg(theta));
fprintf('phi = %.2f radians (%.2f degrees)\n', phi, rad2deg(phi));
% Create the plot
figure;
% Plot rectangular coordinates
subplot(1, 2, 1);
plot3(x, y, z, 'ro', 'MarkerFaceColor',
'r'); hold on;
xlabel('X');
ylabel('Y');
zlabel('Z');
grid on;
axis equal;
title('Rectangular Coordinates');
text(x, y, z, sprintf(' (%.2f, %.2f, %.2f)', x, y, z), 'Color', 'r');
% Plot spherical coordinates in the same plot
% Convert to spherical coordinate system
sphere_x = r * sin(theta) * cos(phi);
sphere_y = r * sin(theta) * sin(phi);
sphere_z = r * cos(theta);
% Mark the point using spherical coordinates
plot3(sphere_x, sphere_y, sphere_z, 'bo', 'MarkerFaceColor', 'b');
text(sphere_x, sphere_y, sphere_z, sprintf(' (%.2f, %.2f, %.2f)', sphere_x, sphere_y, sphere_z), 'Color',
'b');
% Adding line between origin and the point
plot3([0, x], [0, y], [0, z], 'k--', 'LineWidth', 1);
plot3([0, sphere_x], [0, sphere_y], [0, sphere_z], 'k--', 'LineWidth', 1);
% Add labels for clarity
legend('Point in Rectangular Coordinates', 'Point in Spherical Coordinates', 'Location', 'Best');
% Plot spherical coordinate system
subplot(1, 2, 2);
% Polar coordinate system
theta_vals = linspace(0, pi, 100);
phi_vals = linspace(0, 2*pi, 100);
[theta_grid, phi_grid] = meshgrid(theta_vals,
phi_vals); x_sphere = r * sin(theta_grid) .*
cos(phi_grid); y_sphere = r * sin(theta_grid) .*
sin(phi_grid); z_sphere = r * cos(theta_grid);
% Plot the sphere
surf(x_sphere, y_sphere, z_sphere, 'FaceAlpha', 0.3, 'EdgeColor', 'none');
hold on;
plot3(sphere_x, sphere_y, sphere_z, 'bo', 'MarkerFaceColor', 'b');
xlabel('X');
ylabel('Y');
zlabel('Z');
axis equal;
title('Spherical Coordinate System');
grid on;
(i) Field and potential plot due to two-point charge
4.440e+000 : >4.674e+000
4.207e+000 : 4.440e+000
3.973e+000 : 4.207e+000
3.739e+000 : 3.973e+000
Air
3.505e+000 : 3.739e+000
3.272e+000 : 3.505e+000
3.038e+000 : 3.272e+000
2.804e+000 : 3.038e+000
2.570e+000 : 2.804e+000
2.337e+000 : 2.570e+000
2.103e+000 : 2.337e+000
1.869e+000 : 2.103e+000
1.635e+000 : 1.869e+000
1.402e+000 : 1.635e+000
1.168e+000 : 1.402e+000
9.341e-001 : 1.168e+000
7.004e-001 : 9.341e-001
4.666e-001 : 7.004e-001
2.329e-001 : 4.666e-001
<-8.726e-004 : 2.329e-001
Density Plot: V, Volts