Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]


Groups > comp.soft-sys.math.mathematica > #7942 > unrolled thread

Re: Locator points not working in Manipulate calling RegionPlot, etc.

Started byHeike Gramberg <heike.gramberg@gmail.com>
First post2012-01-17 10:59 +0000
Last post2012-01-18 11:05 +0000
Articles 2 — 2 participants

Back to article view | Back to comp.soft-sys.math.mathematica

This discussion starts older than the indexed window; earlier articles aren't shown. The article labeled Started by below is the oldest one visible, not the original post.


Contents

  Re: Locator points not working in Manipulate calling RegionPlot, etc. Heike Gramberg <heike.gramberg@gmail.com> - 2012-01-17 10:59 +0000
    Re: Locator points not working in Manipulate calling RegionPlot, etc. Chris Young <cy56@comcast.net> - 2012-01-18 11:05 +0000

#7942 — Re: Locator points not working in Manipulate calling RegionPlot, etc.

FromHeike Gramberg <heike.gramberg@gmail.com>
Date2012-01-17 10:59 +0000
SubjectRe: Locator points not working in Manipulate calling RegionPlot, etc.
Message-ID<jf3ka7$q7r$1@smc.vnet.net>
The problem is that you have two Locator controls which messes things up. You could do something like this instead.

Manipulate[
 PolyHatch[pts[[;; 4]], pts[[-1]], mesh, lighter, plotPoints],
 {{pts, {{1, 0}, {1, 1}, {2, 1}, {2, 0}, {0, 0}}}, Locator},
 {{mesh, 20}, 1, 30},
 {{lighter, .3}, 0, 1},
 {{plotPoints, 15}, 10, 30, 1}]

By the way, to make the manipulate less laggy you could use for example ParametricPlot to plot the triangles instead of
RegionPlot. For example, this produces the same result but is much more responsive:

TriHatch[P1_, P2_, P3_, mesh_, light_, plotPts_, opts___] :=
 Module[{orient, qq },
  orient = Sign[Det[{P2 - P1, P3 - P1}]];
  qq = Projection[P1 - P2, P3 - P2] + P2;

  ParametricPlot[
   a P1 + (1 - a) (b P2 + (1 - b) P3), {a, 0, 1}, {b, 0, 1},
   PlotStyle -> None,
   Mesh -> Round[mesh Norm[P3 - P2], 1],
   MeshStyle ->
    If[orient > 0, Lighter[Green, light], Lighter[Red, light]],
   MeshFunctions -> {Function[{x, y}, Det[{qq - P1, {x, y} - P1}]]},
   PlotPoints -> plotPts,
   BoundaryStyle -> None, Evaluate[opts]]
  ]

Manipulate[
 PolyHatch[pts[[;; 4]], pts[[-1]], mesh, lighter, plotPoints],
 {{pts, {{1, 0}, {1, 1}, {2, 1}, {2, 0}, {0, 0}}}, Locator},
 {{mesh, 20}, 1, 30},
 {{lighter, .3}, 0, 1},
 {{plotPoints, 5}, 2, 20, 1}]

(note that for ParametricPlot the number of PlotPoints can be as  small as small as 2 whereas for RegionPlot you
need at least 20 points for a reasonable plot).


Heike.

On 16 Jan 2012, at 23:03, Chris Young wrote:

> No matter what I do, in terms of wrapping with DynamicModule, avoiding
> using variables from a module in an enclosed Dynamic or Manipulate, I
> can't get this very basic example to work. I just want to be able to
> drag around 4 points to set the quadrilateral, and then hatch all the
> subtriangles formed by drawin lines to the sides of the quadrilateral
> from the point T.  House of trying everything I could think of have
> failed to get the Locator points to work.
>
> Any help hugely appreciated.
>
> http://home.comcast.net/~cy56/PolyHatchFromTestPt.nb
> http://home.comcast.net/~cy56/PolyHatchFromTestPt.png
>
> Chris Young
> cy56@comcast.net
>
>
> _TriHatch[P1_, P2_, P3_, mesh_, light_, plotPts_, opts___] :=
> Module[
>  {
>   orient,           (* orientation of the triangles *)
>   interior,      (*
>   inequalities for interior of triangle *)
>   Q                          (*
>   projection of first vertex onto opposite side *)
>   },
>  orient = Sign[Det[{P2 - P1, P3 - P1}]];
>
>  interior[P_] :=
>   And @@ (If[orient > 0, # > 0, # < 0] & /@
>      {Det[{P2 - P1, P - P1}],  Det[{P3 - P2, P - P2}],
>       Det[{P1 - P3, P - P3}] });
>
>  Q = Projection[P1 - P2, P3 - P2] + P2;
>
>  RegionPlot[
>   interior[{x, y}],  {x, -2, 2}, {y, -2, 2},
>   PlotStyle -> Opacity[0.1],
>   ColorFunction -> (White &),
>   Mesh -> Round[mesh Norm[P3 - P2], 1],
>   MeshStyle -> If[orient > 0, Lighter[Green, light], Lighter[Red, light]],
>   MeshFunctions -> {{x, y} =E2=8A=82 Det[{Q - P1, {x, y} - P1}]},
>   PlotPoints -> plotPts,
>   BoundaryStyle -> None,
>   Evaluate[opts]
>   ]
>  ]
>
>
>
> \[HorizontalLine]Ctr[P_] := Plus @@ P/Length[P]
>
> \[HorizontalLine]PolyHatch[P_, T_, mesh_, light_, plotPts_] :=
> Module[
>  {C, n},
>
>  C = \[HorizontalLine]Ctr[P];
>  n = Length[P];
>
>  (*Print["n == ",n];*)
>
>  Show[
>   Table[
>    \[HorizontalLine]TriHatch[T, P[[j]], P[[If[j < n, j + 1, 1]]],
>     mesh, light, plotPts],
>    {j, 1, n}
>    ],
>   Graphics[
>    {
>     Table[
>      {Hue[0.85 (j - 1)/n], Thick,
>       Line[{P[[j]], P[[If[j < n, j + 1, 1]]]}]},
>      {j, 1, n}
>      ],
>     Gray, PointSize[Large], Point[C]
>     }
>    ]
>   ]
>  ]
>
>

[toc] | [next] | [standalone]


#7976

FromChris Young <cy56@comcast.net>
Date2012-01-18 11:05 +0000
Message-ID<jf6926$gc8$1@smc.vnet.net>
In reply to#7942
Thanks very much to Heike for the suggestion. Doing a parametric plot
of the whole triangular region (via two parameters, not just a line
plot via one parameter) tells Mathematica where to put the mesh much more
quickly than using RegionPlot, especially since it works fine with
PlotPoints set to 2, unlike RegionPlot. I wonder if this would
translate to a general polygon filling routine, though.

http://home.comcast.net/~cy56/ParametricTriHatch.nb
http://home.comcast.net/~cy56/ParametricTriHatchPIc1.png
http://home.comcast.net/~cy56/ParametricTriHatchPIc2.png
http://home.comcast.net/~cy56/ParametricTriHatchPIc3.png
http://home.comcast.net/~cy56/ParametricTriHatchPIc4.png

\[HorizontalLine]TriHatch3[A_, B_, C_, mesh_, light_, plotPts_,
  opts___] :=
 Module[
  {
   orient, (* the orientation of the triangle; counter-
   clockwise is positive *)
   N,             (* the projection,
   or "normal", from A onto BC *)
   base        (*
   the extended base, for spacing the hatch lines uniformly *)
   },

  orient =  Sign[Det[{B - A, C - A}]];
  N =            Projection[A - B, C - B] + B;
  base =     Max[Norm /@ {N - B, N - C, C - B}];

  ParametricPlot[
   u A + (1 - u) (v B + (1 - v) C),
   {u, 0, 1}, {v, 0, 1},

   PlotStyle -> None,

   Mesh ->                      Round[mesh * base, 1],
   MeshStyle ->
    If[orient > 0, Lighter[Green, light], Lighter[Red, light]],
   MeshFunctions -> {{x, y} \[Function] Det[{N - A, {x, y} - A}]},

   PlotPoints -> plotPts,
   BoundaryStyle -> None,
   Evaluate[opts]]
  ]

On 2012-01-17 10:59:19 +0000, Heike Gramberg said:

> The problem is that you have two Locator controls which messes things
> up. You could do something like this instead.
>
> Manipulate[
>  PolyHatch[pts[[;; 4]], pts[[-1]], mesh, lighter, plotPoints],
>  {{pts, {{1, 0}, {1, 1}, {2, 1}, {2, 0}, {0, 0}}}, Locator},
>  {{mesh, 20}, 1, 30},
>  {{lighter, .3}, 0, 1},
>  {{plotPoints, 15}, 10, 30, 1}]
>
> By the way, to make the manipulate less laggy you could use for example=

> ParametricPlot to plot the triangles instead of
> RegionPlot. For example, this produces the same result but is much more=

> responsive:
>
> TriHatch[P1_, P2_, P3_, mesh_, light_, plotPts_, opts___] :=
>  Module[{orient, qq },
>   orient = Sign[Det[{P2 - P1, P3 - P1}]];
>   qq = Projection[P1 - P2, P3 - P2] + P2;
>
>   ParametricPlot[
>    a P1 + (1 - a) (b P2 + (1 - b) P3), {a, 0, 1}, {b, 0, 1},
>    PlotStyle -> None,
>    Mesh -> Round[mesh Norm[P3 - P2], 1],
>    MeshStyle ->
>     If[orient > 0, Lighter[Green, light], Lighter[Red, light]],
>    MeshFunctions -> {Function[{x, y}, Det[{qq - P1, {x, y} - P1}]]},
>    PlotPoints -> plotPts,
>    BoundaryStyle -> None, Evaluate[opts]]
>   ]
>
> Manipulate[
>  PolyHatch[pts[[;; 4]], pts[[-1]], mesh, lighter, plotPoints],
>  {{pts, {{1, 0}, {1, 1}, {2, 1}, {2, 0}, {0, 0}}}, Locator},
>  {{mesh, 20}, 1, 30},
>  {{lighter, .3}, 0, 1},
>  {{plotPoints, 5}, 2, 20, 1}]
>
> (note that for ParametricPlot the number of PlotPoints can be as  small=

> as small as 2 whereas for RegionPlot you
> need at least 20 points for a reasonable plot).

[toc] | [prev] | [standalone]


Back to top | Article view | comp.soft-sys.math.mathematica


csiph-web