def E(self, x): # pylint: disable=invalid-name
"""Electric field vector.
Ref: http://www.phys.uri.edu/gerhard/PHY204/tsl31.pdf
"""
x = array(x)
x1, x2, lam = self.x1, self.x2, self.lam
# Get lengths and angles for the different triangles
theta1, theta2 = angle(x, x1, x2), pi - angle(x, x2, x1)
a = point_line_distance(x, x1, x2)
r1, r2 = norm(x - x1), norm(x - x2)
# Calculate the parallel and perpendicular components
sign = where(is_left(x, x1, x2), 1, -1)
# pylint: disable=invalid-name
Epara = lam*(1/r2-1/r1)
Eperp = -sign*lam*(cos(theta2)-cos(theta1))/where(a == 0, infty, a)
# Transform into the coordinate space and return
dx = x2 - x1
if len(x.shape) == 2:
Epara = Epara[::, newaxis]
Eperp = Eperp[::, newaxis]
return Eperp * (array([-dx[1], dx[0]])/norm(dx)) + Epara * (dx/norm(dx))
评论列表
文章目录