3

I am plotting several parametric surfaces with Asymptote. When I change the parameters (tyMax in the MWE below), the value of the function can change significantly so I have to adjust the axes (xmin,xmax,...,zmax and unitsize) for each of them.

My goald is to adjust the axes automatically. What I thought of is simply to use the extremal values of f(t.x,t.y) for each surface, but I don't know how to achieve this.

How can I do that?

MWE (play with tyMax):

import graph3;

real xmin=-2, xmax=2;
real ymin=-2, ymax=2;
real zmin=-0.5, zmax=0.5;

limits((xmin,ymin,zmin),(xmax,ymax,zmax));

currentprojection=perspective(camera=(1.5,-2,1));

unitsize(2cm,2cm,2cm);

real X(pair t) { return cos(t.x+t.y);}
real Y(pair t) { return sin(t.x)*t.y;}
real Z(pair t) { return t.x**2+t.y;}

triple f(pair t) { return (X(t),Y(t),Z(t));}


real tyMax = 5;
surface s=surface(f,(0.,0),(2,tyMax), 60, 60, Spline);
draw(s,blue);

xaxis3(Label("$x_{n-1}$",MidPoint,align=Y-Z),Bounds(Both,Min),InTicks(Step=1),p=black);
yaxis3(Label("$x_{n}$",MidPoint,align=X-Z),Bounds(Both,Min),InTicks(Step=1),p=black);
zaxis3(Label("$\dot x_{n}$",EndPoint,align=X+Y),Bounds(Both,Min),InTicks(Step=1),p=black);

Illustration for tyMax=5 and tyMax=0.3 without changing the axis: you see that it needs adapting: while the first image is "OK", the second one is clearly not.

enter image description hereenter image description here

Note that the function are very simple in this MWE but in my use I cannot find closed-form expressions for the extrema.

Also note this question might be simply reformulated as "Find extrema of parametric function in Asymptote" but I wanted to give the context as there might be better solutions.


Edit Added an illustration of the same problem with orthographic projection, with an even simpler surface.

Code:

import graph3;

real xmin=-2, xmax=2;
real ymin=-2, ymax=2;
real zmin=-0.5, zmax=0.5;

limits((xmin,ymin,zmin),(xmax,ymax,zmax));

currentprojection=orthographic(camera=(1.5,-2,2));

unitsize(2cm,2cm,2cm);

real param = 2;
real alpha = 4;
draw(surface((param,param,param)--(param**alpha,2*param,3*param)--(3*param,param,param)--cycle),blue
);

xaxis3(Label("$x$",MidPoint,align=Y-Z),Bounds(Both,Min),InTicks(Step=1),p=black);
yaxis3(Label("$y$",MidPoint,align=X-Z),Bounds(Both,Min),InTicks(Step=1),p=black);
zaxis3(Label("$z$",EndPoint,align=X-Y),Bounds(Both,Min),InTicks(Step=1),p=black);

With param=1, alpha=1:

enter image description here

With param=2, alpha=4:

enter image description here

I would like:

  • the axes to be confined to the surface (i.e. if you reduce the box, you start cropping the surface)
  • the ratio of the box to be always the same, let's say for example that the output should always be a cube.
  • The effect you want to get rid of is a consequence of the projection you are using. A quick fix would be to set the projection to orthographic. – blaze Sep 17 '15 at 18:48
  • @blaze I don't see what it has to do with the projection: depending on the value of the parameters I'm using, the blue surface can be either "very small" or "very large". I just want to adapt the axes to that (to keep consistent box ratio for example). – anderstood Sep 17 '15 at 18:51
  • I see from your example images that your surface doesn't scale uniformly across all the axes, so I'm confused by "consistent box ratio". Furthermore, I'm confused with "for example". Do you know exactly what kind of result you want? Maybe give an example from the internet. I am not very knowledgeable of the mathematical details of the perspective view, but I think it is impossible to get all the axis parallel across the images, if that is what you mean by consistency. I do believe that the orthographic projection solves these issues in a quite elegant fashion. – blaze Sep 17 '15 at 20:07
  • 1
    I explored the grid3 and palette modules in hope of finding out how they do the trick. Unfortunately, I was not able to figure it out as of reading the suggestion by @CharlesStaats. Thank you very much! A side question: Is there any documentation of this function or did you find about it by reading the source? What are the modules that implement most of the stuff other modules use (so I can focus on them when studying the source)? Also, should I delete my answer since it is not relevant anymore? – blaze Sep 18 '15 at 22:10
  • 1
    @blaze: I don't remember whether the function is documented, but in general, I've found that a lot of such useful functions are undocumented. This particular function is found in the three module, specifically in the file three_surface.asy. The modules that implement most of the stuff other modules use are plain (including the files plain.asy, plain_*.asy) and three (including the files three.asy, three_*.asy). – Charles Staats Sep 20 '15 at 15:27
3

If s is a surface (parametric or otherwise), then min(s) is a triple (xmin, ymin, zmin), and max(s) is similar. Thus, box(min(s),max(s)) is the smallest three-dimensional box containing the surface (specified as a path3[]).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.