Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

I'd like to prepare some presentations in Mathematica to help students visualize functions of two variables (it's a usual calculus course). I thought it would be both cool and useful to have the graphs as red/cyan anaglyphs. Is it possible to do that, and if yes, how?

Edit: Simon Woods' answer below is great, but it produces a static image. I'd prefer an interactive version (rotatable - is it a word? - with a mouse); if this is not possible, then I'd like to have at least an animation. (I guess the latter shouldn't be too hard - I'd only have to put suitable commands in some loop, export the images and mount them as an animation; the point is, I'm a Mathemathica newbie and don't know (yet) how to do it - but I can probably figure that out on my own.)

share|improve this question
1  
by anaglyph, do you mean this? –  acl Aug 11 '12 at 19:52
    
Yes, I'll clarify that in the question. –  mbork Aug 11 '12 at 19:54
3  
Check out the StereoImagery package by Mark Fisher: markfisher.net/~mefisher/mma/mathematica.html and a nice example by @Vitaly vimeo.com/15262935 –  s0rce Aug 11 '12 at 20:07
add comment

1 Answer 1

up vote 17 down vote accepted

I think the basic idea is to create two slightly different views and combine them in the red and (green + blue) channels.

p = Plot3D[Sin[x y]^2, {x, -2, 2}, {y, -2, 2}];

{r, g} = ColorConvert[
 Image[Show[p, ViewPoint -> {3 Sin[#], 3 Cos[#], 2} &[# Degree]],
   ImageSize -> {360, 275}], "Grayscale"] & /@ {141, 139};

ColorCombine[{r, g, g}]

enter image description here

A simple way to animate is just to change the ViewPoint in a loop and Export the individual frames. I use some software called VirtualDub to combine the images into a movie or animated gif:

Do[{r, g} = ColorConvert[
     Image[Show[p, SphericalRegion -> True, 
       ViewPoint -> {3 Sin[#], 3 Cos[#], 2} &[# Degree]], 
      ImageSize -> {360, 275}], "Grayscale"] & /@ {2 a + 1, 2 a - 1}; 
 Export["frame" <> ToString[a] <> ".bmp", ColorCombine[{r, g, g}]]
 , {a, 0, 44}]

enter image description here

share|improve this answer
    
It works for me, but I think you should remove the tick labels as they are vertically displaced somewhat. –  Sjoerd C. de Vries Aug 11 '12 at 20:06
    
Also, shouldn't you keep the ViewCenter the same in both pictures? –  Sjoerd C. de Vries Aug 11 '12 at 20:09
    
Thanks, this is very nice. However, it is "just an image", I cannot e.g. rotate it interactively. I'll modify the question once again;). –  mbork Aug 11 '12 at 20:30
    
@SjoerdC.deVries, the ViewCenter is the same in both images I think. –  Simon Woods Aug 11 '12 at 21:22
    
@mbork, interactive rotation is probably possible, but I don't know how to do it! –  Simon Woods Aug 11 '12 at 21:26
show 4 more comments

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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