Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #7865
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Newsgroups | comp.soft-sys.math.mathematica |
| Subject | Hatching triangle interior |
| Date | 2012-01-16 11:50 +0000 |
| Organization | Steven M. Christensen and Associates, Inc and MathTensor, Inc. |
| Message-ID | <jf12tf$5fv$1@smc.vnet.net> (permalink) |
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
Back to comp.soft-sys.math.mathematica | Previous | Next | Find similar | Unroll thread
Hatching triangle interior Chris Young <cy56@comcast.net> - 2012-01-16 11:50 +0000
csiph-web