1. Physics Foundations
Governing laws, fields, potentials, and fundamental physical constants
1.1 Coulomb's Law
Coulomb's Law quantifies the electrostatic force $\mathbf{F}_{12}$ exerted by a point charge $q_1$ located at $\mathbf{r}_1$ upon a second charge $q_2$ located at $\mathbf{r}_2$ in a vacuum.
Here, $\varepsilon_0$ denotes the permittivity of free space, defining the capability of a vacuum to permit electric field line formation. The force vector obeys Newton's third law ($\mathbf{F}_{12} = -\mathbf{F}_{21}$) and follows an inverse-square distance dependence ($r^{-2}$).
1.2 Electric Field ($\mathbf{E}$) and Electric Potential ($V$)
The electric field $\mathbf{E}(\mathbf{r})$ is a vector field representing force per unit test charge $q_0$. For a continuous spatial charge distribution with volumetric charge density $\rho(\mathbf{r}')$:
Because static electric fields are conservative ($\nabla \times \mathbf{E} = \mathbf{0}$), $\mathbf{E}$ can be uniquely expressed as the negative gradient of a scalar Electric Potential $V(\mathbf{r})$:
Physical meaning: Potential $V$ measures work required per unit charge to move from a reference point (typically infinity, where $V(\infty)=0$) to location $\mathbf{r}$. The negative sign dictates that the field points directionally along the steepest decrease in potential energy.
1.3 Related Electrostatic Maxwell Equations
Electrostatics is governed by two fundamental Maxwell equations in static limit ($\frac{\partial \mathbf{B}}{\partial t} = \mathbf{0}$):
Fundamental Physical Constants
Concept of Scalar Heat Maps
Numerical simulators represent the continuous scalar field $V(x,y)$ on discrete 2D spatial grids. Mapping raw numerical potential values to visual spectrums provides intuitive field visualization:
2. Vector Calculus
Differential operators, gradients, field flux divergence, and irrotational conditions
Gradient ($\nabla V$)
The gradient operator $\nabla$ operating on scalar potential $V(x,y,z)$ produces a vector field pointing toward the maximal rate of spatial increase:
Divergence ($\nabla \cdot \mathbf{E}$)
Computes net outward vector flux per unit volume at an infinitesimal volume element:
Curl ($\nabla \times \mathbf{A}$)
Measures localized circulation/rotation density of vector field $\mathbf{A}$:
3. Numerical Methods & Discretization
Taylor expansion finite differences, 5-point Poisson stencil, and iterative solver schemes
3.1 First & Second-Degree Finite Differences
Consider a 1D grid with spatial step spacing $h = \Delta x$. The first-order spatial derivatives of potential $V(x)$ are approximated via forward, backward, and central difference stencils:
Step-by-Step Derivation of Second-Degree Central Derivative
To derive the second-degree partial derivative $\frac{\partial^2 V}{\partial x^2}$, expand $V(x+h, y)$ and $V(x-h, y)$ using Taylor series expansions around node $(x,y)$:
Adding Equation (1) and Equation (2) cancels all odd-order derivative terms ($h, h^3, \dots$):
Isolating $\frac{\partial^2 V}{\partial x^2}$ and switching to discrete grid indexing $(i, j)$ yields the second-order accurate central difference formula:
3.2 Derivation of the 5-Point Stencil for Poisson's Equation
Combining Gauss's Law ($\nabla \cdot \mathbf{E} = \frac{\rho}{\varepsilon_0}$) with conservative gradient relation ($\mathbf{E} = -\nabla V$) yields Poisson's Equation:
Expand the 2D Laplacian operator $\nabla^2 V = \frac{\partial^2 V}{\partial x^2} + \frac{\partial^2 V}{\partial y^2}$ by substituting second-order central difference formulas along both grid dimensions $x$ and $y$ with uniform mesh size $h = \Delta x = \Delta y$:
Group terms with common denominator $h^2$:
Multiply by $h^2$, rearrange terms, and solve for node potential $V_{i,j}$ to arrive at the explicit discrete update formula:
3.3 Iterative Solvers for Poisson's Grid Matrix
Jacobi Method
SimultaneousComputes step $(k+1)$ strictly using previous iteration values $k$. Requires keeping dual array buffers in memory.
Gauss-Seidel
In-PlaceUpdates array values in-place. Uses newly computed $(k+1)$ values for calculated neighbors $(i-1,j)$ and $(i,j-1)$ immediately.
SOR Method
AcceleratedOver-relaxes Gauss-Seidel step via relaxation parameter $\omega \in (1, 2)$ to dramatically accelerate convergence:
4. Connecting the Dots: Complete Pipeline
Mapping continuous electrodynamics to computational grid routines
The block diagram below outlines the full algorithmic flow executed inside the electrostatic engine:
Spatial Grid & Boundary Initialization
Discretize spatial domain $\Omega$ into $N \times N$ matrix mesh nodes $V[N][N]$. Set boundary condition potentials (e.g. $V_{\text{boundary}} = 0$ for grounded walls or Dirichlet conductor plates).
Charge Density Mapping ($\rho$)
Map discrete point charges $q_k$ onto neighboring spatial mesh points $(i, j)$ to build source charge matrix $\rho[i][j]$.
Iterative Poisson Stencil Solving (SOR)
Loop over internal non-boundary grid points applying 5-point Poisson SOR stencil updates until residual norm drops below threshold $\epsilon$:
Electric Vector Field Gradient Calculation ($\mathbf{E} = -\nabla V$)
Compute discrete vector components $E_x(i,j)$ and $E_y(i,j)$ across converged potential array $V$ using central differences:
Color Heatmap Rendering & Vector Quiver Overlay
Map potential array $V(i,j)$ into RGB color spectrum buffer while overlaying scaled directional arrows for vector field $\mathbf{E}(i,j)$.
Explore Code Implementation
View complete source code, matrix algorithms, and build instructions on GitHub.