# 3D Plot for Attractive and Repuslive Field Functions [closed]

I am using Mathematica to plot the total potentials (which is the sum of an attractive potential field and a repulsive potential field) - This is related the Artificial Potential Field Method in Motion Planning, for example, see Wikipedia.

The attractive potential is "downhill" like a bowl and the repulsive potential is "uphill" ("spike")

I have attached the output for two cases (each case has two different viewing angles).

The first two figures are Case 1 and the last two are Case 2.

I prefer Case 2 (the last two figures) to which I have added to the Plot3D command:

ClippingStyle -> None


My problem is with the repulsive potential (the spike). There appears to some sort of "messy cylinder" (maroon in color) going through the entire spike. This is visible in View 2 of each case.

Is there anyway I can get rid of the cylinder by adding some options to Plot3D?    Edit Given below is the code for generating the plot.

(*Assignments*)
r = 0.5;

q = 1;

xmax = 70;
ymax = 70;

o[1, 1] = 25; o[1, 2] = 30;
A = 3; B = 4;

p1 = 35; p2 = 35;

(*This parameter can be changed, where g[l]>0*)
Table[g[l] = 1000, {l, 1, q}];

(*Function definitions*)
H = 1/2 ((x - p1)^2 + (y - p1)^2);

Table[EO[l] = 1/2 (((x - o[l, 1])/(A[l] + r))^2 + ((y - o[l, 1])/(B[l] + r))^2 - 1),{l, 1, q}];

(*We require the plot of the following function*)
L = H + Sum[g[l]/EO[l], {l, 1, q}];

(*The plot*)
Plot3D[L, {x, 0, xmax}, {y, 0, ymax}, ColorFunction -> "Rainbow", Mesh -> None, PlotStyle -> Directive[Opacity], ClippingStyle -> None]

• @Kuba, Thanks. I will include the code. – Jack Mar 12 '15 at 11:21
• @Kuba, I have added the code. I was randomly generating the position of the repulsive potential but I have kept it fixed in the code given here. The parameter g[l] is user-defined. The larger it is the greater the repulsive potential. – Jack Mar 12 '15 at 12:10
• Use the option PlotPoints in Plot3D. For instance PlotPoints->100 gives a fairly smooth outline of the objects. – Dr. Wolfgang Hintze Mar 12 '15 at 12:27
• related: 4244 – Kuba Mar 12 '15 at 12:29
• @ Dr. Wolfgang Hintze and @Kuba, Thank you for the help. – Jack Mar 13 '15 at 3:02

The behavior is due to your calculations, specifically the EO[l]-table, inducing a singularity region (i.e.: the EO[l]-table is 0 for the region you see in your plot).

So, the plots are "correct", which you can verify by adding the options PlotRange->All and PlotPoints->250 (or even more).

You will have to fix those singularities (in this case resulting from deleting by zero) to get your desired smooth result.

## Proof of the singularity in the E[l]-table

Plot[Evaluate[Table[EO[l],{l,1,q}]/.y->20],{x,0,40},AxesOrigin->{0,0}] • Thank you very much. I have rewritten EO[l] as a piecewise function where I set EO[l] to 1 whenever it is 0. It solved the problem. – Jack Mar 12 '15 at 12:33