MathGroup Archive 2009

[Date Index] [Thread Index] [Author Index]

Search the Archive

"If" syntax question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105145] "If" syntax question
  • From: Michael Greene <mgreene at csumb.edu>
  • Date: Sun, 22 Nov 2009 06:10:24 -0500 (EST)

I downloaded the cylinder net demonstration code to show my middle school
class. I thought it was pretty good but needed a few enhancements before I
used it in class.

One thing I wanted the animation to show was the circle radius rotating when
the circles were left in their flat orientation. So I modified the
demonstration and came up with:

 Manipulate[With[{da = 2 Pi/30}, With[
   {
    r1 = RotationTransform[s1*Pi/2, {1, 0, 0}, {0, h/2, 0}],
    r2 = RotationTransform[-s1*Pi/2, {1, 0, 0}, {0, -h/2, 0}],
    r3 = RotationTransform[-s2*Pi, {0, 0, 01}, {00, -r - h/2, 0}]
    },
   With[{
     d1 =
      Table[(r1[{r Cos[a], r Sin[a] + h/2 + r, 0}]), {a, 0, 2 Pi,
        da}], d2 =
      Table[r2[{r Cos[a], r Sin[a] - h/2 - r, 0}], {a, 0, 2 Pi, da}],
     l1 = {r3[{0, -h/2, 0}], {0, -r - h/2, 0}}},
    Graphics3D[{Opacity[.5], EdgeForm[],
      {EdgeForm[{Blue}], Polygon[d1]}, {EdgeForm[{Blue}],
       Polygon[d2]}, Line[r3[l1]], Table[
       Polygon[{
         {-a, +h/2, 0},
         {-a + r da, h/2, 0},
         {-a + r da, -h/2, 0},
         {-a, -h/2, 0}}],
       {a, 0, +(1 - s2) (r 2 Pi) - r da, r da}],
      Take[Table[Polygon[{
          {r Cos[a], +h/2, r + r Sin[a]},
          {r Cos[a + da], h/2,
           r + r Sin[a + da]}, {r Cos[a + da], -h/2,
           r + r Sin[a + da]}, {r Cos[a], -h/2,
           r + r Sin[a]}}], {a, -Pi/2, -Pi/2 + (2 Pi - 2 Pi/60),
         2 Pi/60}], Round[s2 60]]}, ImageSize -> {500, 400},
     Boxed -> False, SphericalRegion -> True,
     PlotRange -> {Automatic, {-3, 3}, {0, 2}}]]]], {{r, 1/2,
   "radius"}, .1, 1}, {{h, 1, "Height"}, .1,
  1}, {{s1, 0, "rotate caps"}, 0, 1, ControlType -> Trigger,
  DefaultDuration -> 1}, {{s2, 0, "wrap"}, 0, 1,
  ControlType -> Trigger, DefaultDuration -> 2}]

which does what I wanted when you click just the "Wrap" button. The circle
clearly makes a single rotation as the rectangle rolls "up" into a
cylinder.

I have a separate modification that shows the radius sticking to the end
caps as they get rotated into position when you click the "rotate caps"
button. Both modifications to the original involve the third rotation
operator (function?), r3. They differ only in the parameters being passed to
the third RotationTransform call. My first attempt at melding the two
disparate calls was to modify the r3 definition with the following does
nothing code:

r3=If[{s3=0},RotationTransform[-s2*Pi, {0, 0, 01}, {00, -r - h/2,
0}],RotationTransform[-s2*Pi, {0, 0, 01}, {00, -r - h/2, 0}]]

I say "does nothing" because the true and false outputs are identical. I was
just testing Mathematica to see if that usage was OK. The parser didn't like
that modification and the code quite working.

My question is, why didn't the r3=If... syntax work? What kind of thing is
r3 that it can't be one function under one condition and a separate function
under another? Perhaps there is some syntactical clue I have to give the
parser that indicates my intention here?



  • Prev by Date: Re: Freeze Panes in Grid Expression (addendum)
  • Next by Date: Re: "If" syntax question
  • Previous by thread: Re: Freeze Panes in Grid Expression (addendum)
  • Next by thread: Re: "If" syntax question