6

I am using Asymptote to generate 3D images which I embed in .pdf's. Is there a way to clip these 3D images, much like you can clip 2D images to a path? I'd be happy to clip to the interior of a rectangular solid.

The reason I ask is that using Spline to graph some functions creates some wavy, undesired end behavior. I've given an example below of a hyperboloid of one sheet. With spline, there is a warble at the top. I've tried to cut it off with a bool condition, but that gives very undesirable results.

Here is an example; note where you can comment out lines to see different results.

 import graph3;

 size(200,200,IgnoreAspect); currentprojection=orthographic(4,4,0);
 defaultrender.merge=true;

 defaultpen(0.5mm);

 //Draw the surface z^2 - x^2 - y^2=1 
 triple f(pair t) {return (cos(t.y)*tan(t.x), sin(t.y)*tan(t.x),1/cos(t.x));
 }

 bool cond(pair t) {return 1/cos(t.x) <1.5;}

 //The following plots with just Spline. Note the warble.
 surface s=surface(f,(-1,0),(1,2*pi),32,16,Spline); 

 // Comment above and uncomment below to use the boolean cond. 
 //surface s=surface(f,(-1,0),(1,2*pi),32,16,Spline,cond); 
 pen p=rgb(0,0,.7); 
 draw(s,rgb(.6,.6,1)+opacity(.7),meshpen=p);

I could remove the Spline option but I like how it smooths things otherwise.

Here's the warble:

paraboloid with wavy edges

And here's what happens if you try to cut it off with the bool option:

paraboloid sheathed in cone

GregH
  • 3,499
  • clip 3D seems a difficult task and in the documentation there is no 3D clipping function. For a surface s I think it is possible with the latest bool option. See http://asymptote.sourceforge.net/gallery/3D%20graphs/partialsurface.asy in the documentation. For a path3 I have no idea, except to implement such a function. – O.G. Feb 13 '15 at 20:31
  • I couldn't find a 3D clipping function, either, but thought I'd ask in case I just missed it. I have graphed with the bool options, but don't get the desired result I was looking for. – GregH Feb 16 '15 at 13:08
  • Can you give an example ? – O.G. Feb 16 '15 at 20:50
  • 1
    Possibly relevant: http://tex.stackexchange.com/a/159240/484 – Charles Staats Feb 18 '15 at 04:11

1 Answers1

7

This does not answer your question, but it does solve your problem here. You can eliminate the waviness in this case by telling the spline interpolator that z is monotonically increasing with respect to t.x (which is the u parameter). You do this by playing with the spline type parameter:

surface s=surface(f,(-1,0),(1,2*pi),32,16,
          usplinetype=new splinetype[] {notaknot,notaknot,monotonic},
          vsplinetype=Spline);

Code in full:

 settings.outformat="png";
 settings.render=4;
 import graph3;

 size(400,400,IgnoreAspect); currentprojection=orthographic(4,4.1,2);
 defaultrender.merge=true;

 defaultpen(0.5mm);

 //Draw the surface z^2 - x^2 - y^2=1 
 triple f(pair t) {return (cos(t.y)*tan(t.x), sin(t.y)*tan(t.x),1/cos(t.x));
 }

 surface s=surface(f,(-1,0),(1,2*pi),32,16,
          usplinetype=new splinetype[] {notaknot,notaknot,monotonic},
          vsplinetype=Spline);

 pen p=rgb(0,0,.7); 
 draw(s,rgb(.6,.6,1)+opacity(.7),meshpen=p);

The result:

enter image description here

  • 1
    Thanks for the help. I like your tutorial on Asymptote, although you could add more the 3D section ... :) – GregH Feb 20 '15 at 17:36