Re: Difficulties with LocatorPanel

• To: mathgroup at smc.vnet.net
• Subject: [mg124586] Re: Difficulties with LocatorPanel
• From: Chris Young <cy56 at comcast.net>
• Date: Wed, 25 Jan 2012 07:09:05 -0500 (EST)
• Delivered-to: l-mathgroup@mail-archive0.wolfram.com
• References: <i5ngcv\$2n5\$1@smc.vnet.net>

Here, I'm doing my best to emulate scaling of an axis by dragging a
Locator. Probably a better approach would be to use sliders to set the
actual PlotRange parameters directly. However, provided we remember
that we've essentially got a "fake" x-axis here, it's good for a
hands-on illustration of scaling of function plots.

Since Show doesn't tolerate more than one setting of the ranges of the
axes per plot, it's impossible to superimpose plots with two axes that
way. Maybe there's another way to do that?

For some reason, whatever I do I can't get Plot to work with the
"scale" variable here. I put in the P[[1]] directly and got the scaled
plotting to work that way, but it only goes by one increment at a time.
You can't drag continuously, the way you can if you omit the plotting.

http://home.comcast.net/~cy56/Mma/AxisScaledByLocator.nb
http://home.comcast.net/~cy56/Mma/AxisScaledByLocatorPic1.png
http://home.comcast.net/~cy56/Mma/AxisScaledByLocatorPic2.png

DynamicModule[
{
P = {1, 0},
scale,        (* taken from the x-coordinate of P[[1]] *)
xAxis
},

scale = Dynamic @ P[[1]];

Dynamic @ LocatorPane[
Dynamic @ P,

Show[
Graphics[
{
Black, AbsoluteThickness[0.5],
Line[{{0, 0}, {10 * scale, 0}}],

With[{y1 = -0.1, y2 = 0.1},
Table[
{Line[{{k scale, y1}, {k scale, y2}}],
Text[k, {k scale, 3 y1}]},
{k, 1, 10}]]
},
ImageSize -> 72 * {10, 1},
AspectRatio -> 2/20,
Axes -> {True, True},
AxesStyle -> {LightGray, Black},
PlotRange -> {{0, 20}, {-1, 1}}
],

Plot[{Sin[x], Sin[x/P[[1]]]}, {x, 0, 20},
PlotStyle -> {LightGray, Red}]
],

{{0, 0}, {20, 0}, {0.25, 0}},

Appearance -> {Framed["x1",
Background -> LightBlue,
FrameMargins -> 1]}
]
]

On 2010-09-02 06:31:59 +0000, David Carraher said:

> DynamicModule[
>  {
>   P = {1, 0},
>   scale,        (* taken from the x-coordinate of P[[1]] *)
>   xAxis
>   },
>
>  scale = Dynamic @ P[[1]];
>
>  Dynamic @ LocatorPane[
>    Dynamic @ P,
>
>    Show[
>     Graphics[
>      {
>       Black, AbsoluteThickness[0.5],
>       Line[{{0, 0}, {10 * scale, 0}}],
>
>       With[{y1 = -0.1, y2 = 0.1},
>        Table[
>         {Line[{{k scale, y1}, {k scale, y2}}],
>          Text[k, {k scale, 3 y1}]},
>         {k, 1, 10}]]
>       },
>      ImageSize -> 72 * {10, 1},
>      AspectRatio -> 2/20,
>      Axes -> {True, True},
>      AxesStyle -> {LightGray, Black},
>      PlotRange -> {{0, 20}, {-1, 1}}
>      ],
>
>     Plot[{Sin[x], Sin[x/P[[1]]]}, {x, 0, 20},
>      PlotStyle -> {LightGray, Red}]
>     ],
>
>    {{0, 0}, {20, 0}, {0.25, 0}},
>
>    Appearance -> {Framed["x1",
>       Background -> LightBlue,
>       FrameMargins -> 1]}
>    ]
>  ]Hi All,
>
> I've been struggling to implement a locator, located at {1,0} that
> rescales the x-axis by stretching/shrinking.
> I want to use LocatorPane rather than Locator because I eventually to add
> another half-dozen locators that have different behaviors and appearance.
>
> The solution in LocatorPane would work more or less like the following
> instance  of Locator[].
> The red and blue points position themselves dynamically as the scale
> stretches and shrinks (as desired).
> The Locator dynamically rescales the x-axis by stretching and shrinking.
> And It is always positioned at {1,0}.
>
> Manipulate[
>
> Graphics[{
>  Locator[Dynamic[p, (p = Scaled[{#[[1, 1]], .5}]) &], ImageSize -> 25],
>  {PointSize -> Large, Blue, Point[{.5, 0}], Red, Point[{2.5, 0}]}},
> ImageSize -> {350, 150},
> AspectRatio -> 1/4,
> PlotRange -> {{0, maxX = Dynamic[Abs[1/p[[1, 1]]]]}, {-6, 6}}, Axes ->
> True],
> {{p, Scaled[{0.01, 0.5}]}, ControlType -> None}
>
> ]
>
> The LocatorPane, In addition to having these features, and the inherent
> ability to hold several locators,  would:
> not be dependent on Scale[], because some locators will work with the
> Coordinate values themselves. (unless LocatorPanel can work with both
> scaled and regular locators.)
>
> Here's the best I've been able to come up with:
>
> Manipulate[
> Dynamic@Grid[{
>  {LocatorPane[Dynamic[pLoc],
> Graphics[{
> {PointSize -> Large, Blue, Point[{.5, 0}], Red,          Point[{2.5,
> 0}]}},
>  ImageSize -> {350, 150},
> AspectRatio -> 1/4,
> Axes -> True,
> PlotRange -> {{0, 1/Dynamic[pLoc[[1, 1]]]}, {-6, 6}}],
> (*Allowable roving of the Locators *)      {{{1/20, 0}, {20, 0}}},
>
> (*Appearance of Locatos *)
> Appearance -> {        Framed["x1", Background -> LightBlue,
> RoundingRadius -> 3,          FrameMargins -> 1]}]}    }],
>
>  (*Locator*)
> {{x1, {1, 0}}, ControlType -> None},
> {{pLoc, {x1}}, ControlType -> None},
>
> Alignment -> {Center, Center} ]
>
>
> I read the documentation carefully and worked on it until I can get no
> further ahead by myself.  But as you shall see, the locator in LocatorPane
> moves to  positions other than {1, 0}.
> I'm not sure whether my problem lies with the mathematics or with
> Mathematica.
>
> Any help would be appreciated.
>
>
>   thanks,
>
> David Carraher

• Prev by Date: Re: Compile function and AppendTo for lists (vrs. 8.0.4)
• Next by Date: GramSchmidt function
• Previous by thread: Colored, indexed, resizable locators
• Next by thread: GramSchmidt function