MathGroup Archive 2008

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

Search the Archive

Re: Re: Question about Dynamic-ly restricting Locator position

  • To: mathgroup at smc.vnet.net
  • Subject: [mg94596] Re: [mg94581] Re: [mg94556] Question about Dynamic-ly restricting Locator position
  • From: "David Park" <djmpark at comcast.net>
  • Date: Wed, 17 Dec 2008 06:33:09 -0500 (EST)
  • References: <11470788.1229426303043.JavaMail.root@m02>

Here is a fancier version using Presentations that colors the annular region
and displays the point location in polar form. I have also added some
further explanation of the routines from Presentations that are used.

1) panelpage, pagelet and phrase are essentially shortcuts for Panel, Column
and Row.
2) ComplexPolar is a polar representation of a complex number. It has a
built-in display format: r\[Angle]\[Theta]. Using a polar form makes it easy
to Clip the radius of the point. The point location is displayed in polar
form. polarpt is the primary dynamic variable. The Cartesian point location,
pt, is calculated in calcAll. (I use that format because in general there
are a number of primary variables, and a number of dependent variables that
are calculated with a routine calcAll.)
3) PolarToComplex, ComplexToPolar, ToComplex and ToCoordinates are routines
for converting between the various representations of complex numbers.
4) Draw2D allows us to stack graphics objects produced by various methods in
one drawing statement. It makes it easy to combine a RegionPlot with other
primitives.
5) ProportionalNumberForm gives fixed width number formatting with
proportional fonts such as "Segoe UI" used in Panels. This prevents 'jitter'
when number values change in a dynamic display.
6) CirclePointLocator is based on CirclePoint and gives a colored point with
a black outline for the locator. Such representations are much more common
in geometric diagrams than the militaristic gun sight.

Needs["Presentations`Master`"]

Module[
 {polarpt = ComplexPolar[.5, 0],
  pt, calcAll},
 
 calcAll[pp_] := pt = ToCoordinates@PolarToComplex[pp];
 calcAll[polarpt];
 
 panelpage[
  pagelet[
   Draw2D[
    {Blue,
     RegionDraw[.3^2 < x^2 + y^2 < 1^2, {x, -2, 2}, {y, -2, 2}],
     AbsoluteThickness[2], Black,
     Circle[], Circle[{0, 0}, .3],
     Locator[
      Dynamic[pt, (polarpt = ComplexToPolar@ToComplex[#]; 
         polarpt = MapAt[Clip[#, {.3, 1.}] &, polarpt, 1]; 
         calcAll[polarpt]) &], CirclePointLocator[3, Red]]},
    PlotRange -> 2,
    ContentSelectable -> False,
    ImageSize -> 300](* Draw2D *),
   Dynamic@phrase[
     "Point position: ",
     ComplexPolar[
      ProportionalNumberForm[First[polarpt], {4, 3}], 
      Row[{ProportionalNumberForm[
         Last[polarpt]/Degree // Chop, {4, 1}], \[Degree]}]]]
   ],
  Style["Restricting a Locator to an Annular Region", 16]
  ](* panelpage *)
 ]


David Park
djmpark at comcast.net
http://home.comcast.net/~djmpark/  



From: John Fultz [mailto:jfultz at wolfram.com] 

On Tue, 16 Dec 2008 02:34:42 -0500 (EST), vasil michev wrote:
> How do I implement this
>
> Graphics[{Circle[], Circle[{0, 0}, .3],
> Locator[Dynamic[
> pt, (pt = If[Norm[#] > .3 && Norm[#] < 1, #, {1, 0}]) &]]},
> PlotRange -> 2]
>
> into Manipulate? Everything i tried either crashes Mathematica or
> gives no result, any help will be greatly appretiated.

Here's a quick example.

Manipulate[If[Norm[pt] <= .3 || Norm[pt] >= 1, pt = {1, 0}]; 
 Graphics[{Circle[], Circle[{0, 0}, .3]}, PlotRange -> 2, 
  PlotLabel -> pt], {{pt, {1, 0}}, Locator}]

Sincerely,
 
John Fultz
jfultz at wolfram.com
User Interface Group
Wolfram Research, Inc.






  • Prev by Date: Re: Re: Mathematica 7 weirdness
  • Next by Date: Re: A Version 7 Symbolic Integration Problem
  • Previous by thread: Re: Re: Question about Dynamic-ly restricting Locator position
  • Next by thread: Need Help