1

I'll try to dive right into the subject. I'm a mathematician and professor and would like to help my students (and myself) visualise problems and solutions in multivariable calculus. In particular, when working with line and surface integrals of a two-variable function, I would like to be able to plot the curves or the surfaces which enclose the integration domain.

Ideally and maximally, I would like to:

  • produce a 3D plot which shows two intersecting surfaces, described by some (parametric) equations;
  • highlight the curve along which the surfaces intersect, like so; Surfaces intersecting
  • see "in real time" the labels of the points on which I click;
  • basic manipulation of the plot, i.e. zooming, panning, rotating;
  • exporting it in vector format (SVG, PDF or better, EPS for integration in LaTeX).

I have almost zero experience in Python programming and I feel tempted by Mathematica, since I also need some symbolic computations. But can all of the above be done reasonably well and fast using Python? I just couldn't find such examples in all of the extensive documentation of Matplotlib and others.

If not with Python, what do you recommend?

I'm ready and available to learn any language, provided it gets the required result reasonably fast and better than most of the alternatives.

Thank you very much!

ImportanceOfBeingErnest
  • 321,279
  • 53
  • 665
  • 712
Adrian Manea
  • 121
  • 1
  • 4
  • By "highlight the curve along which the surfaces intersect," do you mean you want the software to find what that curve is, or will you import a parametrization in one dimension (say) to the program? – Rory Daulton Jan 25 '17 at 20:26
  • Well, if I also have the equation of the intersection, then I assume it's easy to just plot it along with the surfaces. But what I want is that the software to highlight it, basically to draw it, e.g. as a boolean subtraction of the two surfaces. To find it, I assume it can, with algebra. – Adrian Manea Jan 25 '17 at 20:28
  • As a further example, I found that Mathematica can do this nicely: http://mathematica.stackexchange.com/questions/5968/plotting-implicitly-defined-space-curves – Adrian Manea Jan 25 '17 at 20:30
  • While there is little that isn't possible in python (equipped with the respective libraries), it's sure not as easy as in mathematica. First, I'm not aware of any easy command in python like mathematica's `findIntersection3D`, this would need to be done 'by hand'. Second, I'm not sure if matplotlib is a good way to go, given that it really is a 2D plotting library where 3D is performed as projections to 2D space, often leading to undesired results (object being hidden behind others etc.). – ImportanceOfBeingErnest Jan 25 '17 at 21:25
  • If you provide us with the surfaces and the intersecting curve, we could make the corresponding plots to let you see, in how far matplotlib or mayavi are suitable tools for your purpose. – ImportanceOfBeingErnest Jan 25 '17 at 21:26
  • @ImportanceOfBeingErnest well, for concrete examples, there is one in the link I provided that contains the Mathematica solution. Take the torus (x^2 +y^2 + z^ +8)^2= 36(x^2 +y^2) and the cylinder y^2 + (z-2)^2 = 4. The two curves of intersection are http://www4f.wolframalpha.com/Calculate/MSP/MSP19761cf33a458c40fhh2000018daih73i61i3dig?MSPStoreType=image/gif&s=56&w=314.&h=46. and http://www4f.wolframalpha.com/Calculate/MSP/MSP19791cf33a458c40fhh200003f3e7d505a79f274?MSPStoreType=image/gif&s=56&w=303.&h=46. – Adrian Manea Jan 26 '17 at 04:30
  • By using this example, I will have a direct comparison with the Mathematica method (at least as described in the first link I posted in the comments). – Adrian Manea Jan 26 '17 at 04:47
  • I'm sorry, I see that the equations for the curves of intersection are no longer available at that link. Their equations are: x = ± sqrt(-sqrt(y^2 - 35 z^2 - 4 z + 36) - y^2 - z^2 + 10) and x = ± sqrt(sqrt(y^2 - 35 z^2 - 4 z + 36) - y^2 - z^2 + 10). – Adrian Manea Jan 26 '17 at 06:05
  • 1
    The problem is that matplotlib expects its input in an explicit way (`x=.., y=.., z=..`), while the surfaces you provide here, are given implicitely ( `f(x,y,z)=0`). I'm not sure if there is a general way to transform the latter to the former, which is a requirement for using matplotlib. – ImportanceOfBeingErnest Jan 26 '17 at 09:44
  • @ImportanceOfBeingErnest alright, thanks. At least I feel I've narrowed the search a bit, I'll look into implicit functions plotting in Matplotlib, to see if I find something satisfactory. – Adrian Manea Jan 26 '17 at 09:46
  • 1
    I found [this discussion](http://matplotlib.1069221.n5.nabble.com/plot-arbitrary-3D-surface-td44249.html) about plotting parametric surfaces in matplotlib, which might be helpful. – ImportanceOfBeingErnest Jan 26 '17 at 09:47
  • @ImportanceOfBeingErnest thanks, I'll look into that. I'm more and more tempted into purchasing Mathematica, honestly, but of course, Python has its clear advantages. We'll see. If anyone has further insight, please. – Adrian Manea Jan 26 '17 at 10:07
  • 1
    @AdrianM If you haven't delved deep into any of those programs, you might to check out the visual programming add-on for rhino called 'Grasshopper' here's an example of what it can do (http://www.grasshopper3d.com/forum/topics/expresseion-surface). It's targeted for use by engineers and architects but I personally use it for studying multivariable calculus. So far, I haven't encountered any multivariable function that it can't plot. – spencer Aug 25 '17 at 07:28
  • @whiteredblack I can't say I have advanced too much, actually, so your suggestion really comes in handy, thanks! I'll check 'Grasshopper' out soon. – Adrian Manea Aug 25 '17 at 15:14

1 Answers1

1

Since the dialogue in the comments with @ImportanceOfBeingErnest provided fruitful, I'll post an answer with my decision, that seems to check all the requirements.

The main problem appears to be when plotting implicitly defined surfaces or curves, so I focused my search in this direction. Parametric curves and surfaces work OK in Matplotlib and Mayavi.

I found this discussion particularly useful for "tricking" Mayavi into plotting implicitly defined surfaces. This way, I can plot both the surfaces and their intersecting curve on the same canvas.

Also, as a mathematician, I found this post very educative.

Alternatively, for mathematicians particularly, I keep hearing about Sage. It has a method of plotting implicit functions, like so.

Overall, it may not be as pretty, as simple or as fast as Mathematica, but at least until I find the money to pay for a license of it, I think I will dive into Python and its scientific + graphic libraries. In the long run, I feel I'm making the right choice, given the universality of Python, its popularity and multitude of applications literally everywhere.

Feel free to comment or answer further. I thought it was better to post my decision as an answer although it looks more like a roadmap or planning, maybe other readers could find it useful.

Thank you for your time!

Community
  • 1
  • 1
Adrian Manea
  • 121
  • 1
  • 4
  • 1
    "I found this discussion particularly useful for "tricking" Mayavi" > The post you link is about Matplotlib, not Mayavi. You may also find [this question](http://stackoverflow.com/questions/6030098/how-to-display-a-3d-plot-of-a-3d-array-isosurface-in-matplotlib-mplot3d-or-simil) useful, where different solutions are provided for Matplotlib as well as Mayavi. The commands `mlab.pipeline.scalar_field()` and `mlab.pipeline.iso_surface` in Mayavi seems useful. Also, the implementation of `skimage.measure.marching_cubes` which allows to plot the surface as `tricontour` is interesting. – ImportanceOfBeingErnest Jan 27 '17 at 09:07
  • @ImportanceOfBeingErnest Yes, sorry, you're right, that topic is on Matplotlib. Nevertheless, thank you again for further references. Now I just have to dive right into it, since I'm pretty much untrained. I think the intention of finding the appropriate solution (Python/Mathematica) and study materials for it seems met. Now I have to work on it. – Adrian Manea Jan 27 '17 at 09:11