How do I remove sawtooth like effect in plot3d?

I attempt to draw a 3d plot using plot3d.  The function contains a weighted combination of absolute values.  To simplify the problem statement, suppose drawing -abs(x-y) for x=-1..1, y=-1..1.  It was found that near the zero plane, the plot become sawtooth like, which is an unexpected result.  How can I remove this effect?

Axel Vogt's picture

avoiding gridstyle seems fine to me

plot3d(-abs(x-y) , x=-1..1, y=-1..1
    #, gridstyle=triangular
    , axes=boxed
 );
You can increase Digits or use more numpoints as well, 
see ?plot3d/option
gkokovidis's picture

How do I remove sawtooth like effect in plot3d?

The gridstyle does not seem to alter the problem.  Increasing the number of points helps, but the "sawtooth" does not go away, it just gets finer.  This can be seen clearly with the plot below, rotated to highlight the sawtooth.

plot3d(-abs(x-y) , x=-1..1, y=-1..1,orientation=[-27,85]);
 

 

Regards,
Georgios Kokovidis
Dräger Medical


reparameterize

Reparameterize so the new parameters u, v fit the geometry of the problem:

 

u:=(x,y)->(x+y)/2;
v:=(x,y)->(x-y)/2;

plot3d([u(x,y)+v(x,y),u(x,y)-v(x,y),-abs(2*u(x,y))],x=-1..1,y=-1..1,axes=boxed);

 

Robert Israel's picture

Not a solution

What you've done, Alex, is change the problem: instead of plotting -abs(x-y) you're plotting -abs(x+y).

The point is this: plot3d(f(x,y),x=..., y=...) actually plots triangular patches:  [x[i],y[j],f(x[i],y[j])], x[i],y[j+1],f(x[i],y[j+1])], [x[i+1],y[j],f(x[i+1],y[j])] and
[x[i],y[j+1],f(x[i],y[j+1])], x[i+1],y[j],f(x[i+1],y[j])], [x[i+1],y[j+1],f(x[i+1],y[j+1])]

For -abs(x+y), with equal numbers of grid points in both directions the "ridge" x=-y
falls on the edges of this triangulation, while for -abs(x-y) the "ridge" x=y does not.

You might try 

>  plot3d([-s,y,-abs(-s-y)], s=-1..1, y=-1..1, axes=box,
      labels=[x,y,z]);

 

 

 

Thank you very much!

Thank you very much!

Comment viewing options

Select your preferred way to display the comments and click "Save settings" to activate your changes.
}