2
$\begingroup$

I would like to learn how to make high quality images in Mathematica. In my pursuit, I have come across Michael Trott's Mathematica Guidebook for Graphics. I have been trying some of the examples, but I find that many of them don't work. For example, I would like for the following code to work:

torus[phi1_, phi2_, r1_, r2_] = 
  {r1 + r2, 0, 0} + 
  {r1 Cos[phi1] + r2 Cos[phi1] Cos[phi2], 
   r1 Sin[phi1] + r2 Sin[phi1] Cos[phi2], 
   r2 Sin[phi2]};

parts = 
  {{torus[phi1, phi2, 3, 1], {{phi1, 0, Pi/2}, {phi2, 0, Pi}}, 
      {pphi1 + 1, pphi2 + 1}}, 
   {torus[phi1, phi2, 3, 1], {{phi1, Pi/2, Pi}, {phi2, Pi/2, Pi}}, 
      {pphi1, pphi2/2 + 1}}, 
   {x # {0, 1, 1} + (1 - x) # & [torus[Pi/2, phi2, 3, 1]], 
      {{x, 0, 1}, {phi2, 0, Pi/2}}, {pphi1, pphi2/2 + 1}}, 
   {x  # {0, 1, 1} + (1 - x) # & [torus[phi1, Pi/2, 3, 1]], 
      {{phi1, Pi/2, Pi}, {x, 0, 1}}, {pphi1, pphi2}}};

pphi1 = 24; pphi2 = 24;
polys = 
  Cases[
    ParametricPlot3D[#1, Evaluate[Sequence @@ #2], 
      PlotPoints -> #3, 
      DisplayFunction -> Identity],
    _Polygon, Infinity] & @@@ parts;

makeSeams[{f_, {{x_, x1_, x2_}, {y_, y1_, y2_}}, {ppx_, ppy_}}] := 
  Line /@ {
    Table[f /. x -> x1, {y, y1, y2, (y2 - y1)/(ppy - 1)}], 
    Table[f /. x -> x2, {y, y1, y2, (y2 - y1)/(ppy - 1)}], 
    Table[f /. y -> y1, {x, x1, x2, (x2 - x1)/(ppx - 1)}], 
    Table[f /. y -> y2, {x, x1, x2, (x2 - x1)/(ppx - 1)}]} // N

seams = makeSeams /@ parts;

Show[
  Graphics3D[{
    EdgeForm[], Thickness[0.001], 
    {SurfaceColor[Hue[Random[]], Hue[Random[]], 2.5], #} & /@ polys, 
    seams}]]

However, I keep getting an error saying that the array produced has the wrong dimensions for a coordinate list.

$\endgroup$
1

1 Answer 1

5
$\begingroup$

Just wrap ParametricPlot3D with Normal. The problem is that Mathematica starting from version 6 introduces more advanced data type GraphicsComplex. Normal converts to good old Graphics3D.

Michael Trott's "Mathematica Guidebook for Graphics" was written for version 5.

polys = Cases[
 Normal[
  ParametricPlot3D[#1, Evaluate[Sequence @@ #2], PlotPoints -> #3,
    DisplayFunction -> Identity]], _Polygon, Infinity] & @@@ parts;
$\endgroup$
2
  • $\begingroup$ Your solution works great, thank you. Do you have any recommendations for learning how to update his code? $\endgroup$
    – Olsen
    Oct 16, 2014 at 23:23
  • 1
    $\begingroup$ New Mathematica versions have much more visualization possibilities, therefore many of Trotts attempts now can be realized with far less of efforts. Sure the book code can be adopted with afew of correcting commands and list brackets. However, I doubt if one to one code update have a sense in the light of of new and much more powerful possibilities. I think the entire approach should be reconsidered. $\endgroup$
    – Acus
    Oct 19, 2014 at 16:40

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

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