Hatching triangle interior
- To: mathgroup at smc.vnet.net
- Subject: [mg124282] Hatching triangle interior
- From: Chris Young <cy56 at comcast.net>
- Date: Mon, 16 Jan 2012 17:03:26 -0500 (EST)
- Delivered-to: l-mathgroup@mail-archive0.wolfram.com
If the number of plot points is kept down, this does a pretty fast hatching of the triangle interior. Green for positive orientation, red for negative. I'm hoping this can be generalized to any convex polygon via permuting the indices for a list of points. http://home.comcast.net/~cy56/TriHatch.nb http://home.comcast.net/~cy56/TriHatchPic1.png http://home.comcast.net/~cy56/TriHatchPic2.png \[HorizontalLine]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}, ColorFunction -> (White &), Mesh -> Round[mesh Norm[P3 - P2], 1], MeshStyle -> If[orient > 0, Lighter[Green, light], Lighter[Red, light]], MeshFunctions -> {{x, y} \[Function] Det[{Q - P1, {x, y} - P1}]}, PlotPoints -> plotPts ] ] Chris Young