# Singularity Messing up Scale in Vector Field

pointofcharge = {1, 1, 1};
pointofsecond = {5, 5, 1};
s = "Segment";
electricfield = VectorPlot3D[
Boole[(Sqrt[(x - 1)^2 + (y - 1)^2 + (z - 1)^2] >
1) && (Sqrt[(x - 5)^2 + (y - 5)^2 + (z - 1)^2] > 1
)] (Normalize[{x, y, z} - pointofcharge]/
Norm[{x, y, z} - pointofcharge]^2 - (Normalize[{x, y, z} -
pointofsecond]/Norm[{x, y, z} - pointofsecond]^2)), {x, -10,
10}, {y, -10, 10}, {z, -10, 10}, PlotRange -> All,
VectorPoints -> 5, PlotRangePadding -> None, VectorStyle -> s];
Show[electricfield, Graphics3D[Ball[pointofcharge, .3]],
Graphics3D[Ball[pointofsecond, .3]], BoxRatios -> Automatic]


I encountered an issue while attempting to show the field of point charges. I am plotting a Vectorfield3D of a positive charge field subtracted by another charge field in a different position.

All is fine except for a couple vectors near the actual point-charges that cause the scaling to be way off. There are these strange vectors that are incredibly long, which I believe to be singularities. I have tried to remove them by using Boole to only render when the radius is larger than one, but that didn't work. The long vectors still exist and I have no idea what could be causing them or if my exclusion of the singularities is invalid.  I also tried simply to limit the magnitude of the vector, but nothing could remove those unusually long vectors

 restrict[v_, limit_] := Boole[Norm[v] < limit] * v;
field[point_] := ({x, y, z} - point)/Norm[{x, y, z} - point]^3;
sambob = VectorPlot3D[
restrict[field[pointofcharge], 5], {x, -10, 10}, {y, -10,
10}, {z, -10, 10}, PlotRange -> All, VectorPoints -> 6,
PlotRangePadding -> None, VectorStyle -> s];
Show[sambob, Graphics3D[Ball[pointofcharge, .3]],
Graphics3D[Ball[pointofsecond, .3]], BoxRatios -> Automatic]  • Welcome to Mathematica.SE! I hope you will become a regular contributor. To get started, 1) take the introductory Tour now, 2) when you see good questions and answers, vote them up by clicking the gray triangles, because the credibility of the system is based on the reputation gained by users sharing their knowledge, 3) remember to accept the answer, if any, that solves your problem, by clicking the checkmark sign, and 4) give help too, by answering questions in your areas of expertise. Jun 2 '15 at 15:51
• – Jens
Jun 2 '15 at 16:20

Since the default vector points are placed without any regard to the location of the singularities, you can get very large relative differences in the norm of the field vectors. Since the default vector arrows are rescaled relative to the 3D box and not to the absolute scale of the field vectors, you have to do any clipping or damping of the relative norm variations inside the option VectorScale. It allows you to specify a scaling function as follows:

pointofcharge = {1, 1, 1};
pointofsecond = {5, 5, 1};
s = "Segment";
electricfield =
VectorPlot3D[(Normalize[{x, y, z} - pointofcharge]/
Norm[{x, y, z} - pointofcharge]^2 - (Normalize[{x, y, z} -
pointofsecond]/Norm[{x, y, z} - pointofsecond]^2)), {x, -10,
10}, {y, -10, 10}, {z, -10, 10}, PlotRange -> All,
VectorPoints -> 5, PlotRangePadding -> None, VectorStyle -> s,
VectorScale -> {Automatic, Automatic, (ArcTanh[100 #5]) &}];
Show[electricfield, Graphics3D[Sphere[pointofcharge, .3]],
Graphics3D[Sphere[pointofsecond, .3]], BoxRatios -> Automatic] The choice I made here is:

VectorScale -> {Automatic, Automatic, (ArcTanh[100 #5]) &


This uses a common trick: exploit the saturation of the ArcTanh (or similarly ArcTan) functions to suppress variations at large values of the norm. The norm is passed to that function as argument number #5. This is a little weird because it's the same convention that is also used in 2D VectorPlot, even though the 3D version has more coordinates that should in principle be made available in the first six arguments, before the norm. Anyway, given that VectorScale counts arguments this way, I then compress the range of norms for which the length varies appreciably, by inserting the factor 100 in the ArcTanh.

With this scaling, it is also unnecessary to exclude the region around the charges from the vector plot, so I removed the Boole statement. Theonly other change I made was to replace Ball by Sphere so that the plot works in earlier versions of Mathematica.