MathGroup Archive 2012

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

Search the Archive

Signed area demo using hatching

  • To: mathgroup at smc.vnet.net
  • Subject: [mg124374] Signed area demo using hatching
  • From: Chris Young <cy56 at comcast.net>
  • Date: Tue, 17 Jan 2012 06:00:19 -0500 (EST)
  • Delivered-to: l-mathgroup@mail-archive0.wolfram.com

Finally got the hatching demo working. Thank you, John, for pointing 
out that the problem was that only one Locator control specification is 
allowed in a Manipulate, although you can actually have as many 
locators as you want. Unfortunately, that means you have to divide up 
the list of locators, instead of just creating locators with the names 
you want.

On Jan 16, 2012, at 6:04 PM, John Fultz wrote:
Manipulate only supports one Locator control at a time, but your Manipulate has
two.  You need to reformulate it so that all four Locator points are in 
a single
Locator control.

The reason for this is because Manipulate doesn't actually use Locator, but
LocatorPane, and overlapping LocatorPanes makes no sense.  In an ideal world,
Manipulate might attempt to combine the controls into a single LocatorPane, but
there would still be limitations (for example, adding and deleting locators
would make much less sense).

Here's a demo of signed area using hatchlines. Wherever the red and 
green hatchlines cancel out, the net area is zero. This illustrates the 
"Surveyor's formula" for area, 
http://en.wikipedia.org/wiki/Surveyor%27s_formula#Area_and_centroid . 

Should rewrite the routine with options and defaults, but it's pretty 
fast, especially with PlotPoints at 30. 

http://home.comcast.net/~cy56/Mma/SignedArea.nb
http://home.comcast.net/~cy56/Mma/SignedAreaPic1.png
http://home.comcast.net/~cy56/Mma/SignedAreaPic2.png
http://home.comcast.net/~cy56/Mma/SignedAreaPic3.png

\[HorizontalLine]TriHatch[A_, B_, C_, 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[{B - A, C - A}]];
  
  interior[P_] :=
   And @@ (If[orient > 0, # > 0, # < 0] & /@ 
      {Det[{B - A, P - A}],  Det[{C - B, P - B}], 
       Det[{A - C, P - C}] });
  
  Q = Projection[A - B, C - B] + B;
  
  RegionPlot[
   interior[{x, y}],  {x, -2, 2}, {y, -2, 2},
   
   PlotStyle -> Opacity[0],
   ColorFunction -> (White &),
   
   Mesh -> Round[
     mesh Max[Norm[C - B], Norm[Q - B], Norm[Q - C]],
     1
     ],
   
   MeshStyle -> Directive[
     Opacity[0.5],
     If[orient > 0, Lighter[Green, light], Lighter[Red, light]]
     ],
   
   MeshFunctions -> {{x, y} \[Function] Det[{Q - A, {x, y} - A}]},
   PlotPoints -> plotPts,
   BoundaryStyle -> None,
   Evaluate[opts]
   ]
  ]



  • Prev by Date: Re: Question about DeleteCases to remove list elements based on first character
  • Next by Date: Re: Locator points not working in Manipulate calling RegionPlot, etc.
  • Previous by thread: Re: determining coefficients of a polynomial
  • Next by thread: For best performance Graphics Card Quadro 600 or geforce GTX 560 ?