efield {ggvfields} | R Documentation |
Electric field
Description
The vector field generated by collection of fixed electrical charges, as dictated by Coulomb's law. This function is mainly used to provide examples for visualizing vector fields with ggvfields.
Usage
efield(u, charge_positions, charges, k = 1, q_test = +1)
efield_maker(
charge_positions = rbind(c(-1, -1), c(1, 1)),
charges = c(-1, +1),
k = 1,
q_test = +1
)
Arguments
u |
The position of the test charge. |
charge_positions |
The positions of the fixed charges generating the
electric field. Defaulted in |
charges |
The charges of the points placed at the positions of
charge_positions. Defaulted in |
k |
The constant of proportionality, defaulted to 1. See examples for a more rigorous use of physical constants. |
q_test |
The test charge, defaulted to +1. |
Value
A vector containing the force felt by the test charge on account of the electric field.
See Also
https://en.wikipedia.org/wiki/Coulomb%27s_law
Examples
# set a - charge at (-1,-1) and a + charge at (1,1)
charge_positions <- rbind(c(-1,-1), c(1,1))
charges <- c(-1, +1)
# calculate force on test charge (+1) at c(0,1), ignoring physical constants
efield(c(0,1), charge_positions, charges)
# efield_maker() simply wraps this function, defaulting to those charges
f <- efield_maker()
f(c(0,1))
ggplot() +
geom_stream_field(fun = f, xlim = c(-2,2), ylim = c(-2,2)) +
scale_color_viridis_c(trans = "log10")
# electric constant from https://en.wikipedia.org/wiki/Vacuum_permittivity
ep0 <- 8.854187818814e-12
k <- (4*pi*ep0)^-1
efield(c(0,1), charge_positions, charges, k)
[Package ggvfields version 1.0.0 Index]