MathGroup Archive 2009

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

Search the Archive

Re: "If" syntax question

  • To: mathgroup at smc.vnet.net
  • Subject: [mg105172] Re: "If" syntax question
  • From: dh <dh at metrohm.com>
  • Date: Mon, 23 Nov 2009 06:52:22 -0500 (EST)
  • References: <6029eb910911210735s5be59d99wf16925fd4cdc7302@mail.gmail.com> <heb69s$abq$1@smc.vnet.net>


Michael Greene wrote:

> Oops. I corrected the expression to use == instead of = in the conditional.

> Still don't get what I'm trying for which is a single 3d point coordinate.

> 

> 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}]]

> 

> 

> On Sat, Nov 21, 2009 at 7:35 AM, Michael Greene <mgreene at csumb.edu> wrote:

> 

>> 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?

>>

>>

>>

> 

> 

Hi Michael,

If needs a True/False value, not a list. Here the corrected version:

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}]]



Daniel






  • Prev by Date: Re: "If" syntax question
  • Next by Date: newbie q-n about FinancialData
  • Previous by thread: Re: "If" syntax question
  • Next by thread: Not all points plot on my graph...