MathGroup Archive 2012

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

Search the Archive

Re: hatched regions, shading, and fills

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124281] Re: hatched regions, shading, and fills
  • From: Chris Young <cy56 at comcast.net>
  • Date: Mon, 16 Jan 2012 17:03:05 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com
  • References: <j0trq5$d2s$1@smc.vnet.net>

On 2011-07-29 08:42:45 +0000, Sam McDermott said:

> After looking over some old threads, it looks like there is no elegant
> way to add hatch marked regions in the interior of a graphic. This is
> regrettable, because it would really simplify things for my particular
> task right now.
> 
> However, are there other easily accessed directives that might give a
> similar result? For instance, filling in a region with polka dots?
> Adding diagonal lines? Filling with a very simple texture?

I've got it so that the hatch lines are always perpendicular to the 
side opposite vertex 1.
The only problem is that, for some reason, the Manipulate seems to be 
being evaluated continously.

http://home.comcast.net/~cy56/HatchLines.nb
http://home.comcast.net/~cy56/HatchLinesPic1.png
http://home.comcast.net/~cy56/HatchLinesPic2.png
http://home.comcast.net/~cy56/HatchLinesPic3.png


Module[
 {
  x1, y1, x2, y2, x3, y3,
  orient,
  interior,
  Q              (*
  projection of first vertex onto opposite side *)
  },
 Manipulate[
  x1 = P[[1, 1]]; y1 = P[[1, 2]];
  x2 = P[[2, 1]]; y2 = P[[2, 2]];
  x3 = P[[3, 1]]; y3 = P[[3, 2]];
  orient = Sign[Chop[Det[\!\(\*
TagBox[
RowBox[{"(", "", GridBox[{
{"x1", "y1", "1"},
{"x2", "y2", "1"},
{"x3", "y3", "1"}
},
GridBoxAlignment->{
            "Columns" -> {{Center}}, "ColumnsIndexed" -> {},
             "Rows" -> {{Baseline}}, "RowsIndexed" -> {}},
GridBoxSpacings->{"Columns" -> {
Offset[0.27999999999999997`], {
Offset[0.7]},
Offset[0.27999999999999997`]}, "ColumnsIndexed" -> {}, "Rows" -> {
Offset[0.2], {
Offset[0.4]},
Offset[0.2]}, "RowsIndexed" -> {}}], "", ")"}],
Function[BoxForm`e$,
MatrixForm[BoxForm`e$]]]\)]]];
  interior[x_, y_] :=
   And @@ (If[orient > 0, # > 0, # < 0] & /@ {Det[( {
          {x1, x2, x},
          {y1, y2, y},
          {1, 1, 1}
         } )],  Det[( {
          {x2, x3, x},
          {y2, y3, y},
          {1, 1, 1}
         } )], Det[( {
          {x3, x1, x},
          {y3, y1, y},
          {1, 1, 1}
         } )] });
  Q = P[[2]] + Projection[P[[1]] - P[[2]], P[[3]] - P[[2]]];

  Show[
   RegionPlot[
    interior[x, y],  {x, -2, 2}, {y, -2, 2},

    ColorFunction -> (White &),
    BoundaryStyle -> None,
    Mesh -> Round[mesh Norm[P[[3]] - P[[2]]], 1],
    MeshStyle ->
     If[orient > 0, Lighter[Green, light], Lighter[Red, light]],
    MeshFunctions -> {{x, y} \[Function] Det[( {
          {x1, Q[[1]], x},
          {y1, Q[[2]], y},
          {1, 1, 1}
         } )]},
    PlotPoints -> 20
    ],
   Graphics[
    {
     Thick,
     Blue,     Line[{P[[1]], P[[2]]}],
     Red,       Line[{P[[2]], P[[3]]}],
     Yellow, Line[{P[[3]], P[[1]]}],

     Black,
     Table[Text[k, P[[k]], {2, 2}], {k, 3}]
     }
    ],
   PlotRange -> 2,
   Axes -> True,
   AxesStyle -> Gray,
   FrameStyle -> Lighter[Blue, 0.75],
   GridLines -> Automatic,
   GridLinesStyle -> Lighter[Blue, 0.75]
   ],

  {{P, {{0, 0}, {1, 0}, {1, 1}}}, Locator},
  {{mesh, 20}, 0, 40, 1},
  {{light, 0.5}, 0, 1}
  ]
 ]




  • Prev by Date: Re: How to check whether an infinite set is closed under addition?
  • Next by Date: Re: Cross reference
  • Previous by thread: Hatching triangle interior
  • Next by thread: Re: hatched regions, shading, and fills