Groups | Search | Server Info | Keyboard shortcuts | Login | Register [http] [https] [nntp] [nntps]
Groups > comp.soft-sys.math.mathematica > #4037 > unrolled thread
| Started by | Sam McDermott <samwell187@gmail.com> |
|---|---|
| First post | 2011-07-29 08:42 +0000 |
| Last post | 2012-01-16 12:07 +0000 |
| Articles | 3 — 2 participants |
Back to article view | Back to comp.soft-sys.math.mathematica
hatched regions, shading, and fills Sam McDermott <samwell187@gmail.com> - 2011-07-29 08:42 +0000
Re: hatched regions, shading, and fills Chris Young <cy56@comcast.net> - 2012-01-16 11:49 +0000
Re: hatched regions, shading, and fills Chris Young <cy56@comcast.net> - 2012-01-16 12:07 +0000
| From | Sam McDermott <samwell187@gmail.com> |
|---|---|
| Date | 2011-07-29 08:42 +0000 |
| Subject | hatched regions, shading, and fills |
| Message-ID | <j0trq5$d2s$1@smc.vnet.net> |
Hi, 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? Any help is much appreciated, Thanks, Sam
[toc] | [next] | [standalone]
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Date | 2012-01-16 11:49 +0000 |
| Message-ID | <jf12sh$5fl$1@smc.vnet.net> |
| In reply to | #4037 |
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}
]
]
[toc] | [prev] | [next] | [standalone]
| From | Chris Young <cy56@comcast.net> |
|---|---|
| Date | 2012-01-16 12:07 +0000 |
| Message-ID | <jf13us$5o1$1@smc.vnet.net> |
| In reply to | #4037 |
On 2011-07-29 08:42:45 +0000, Sam McDermott said:
> Hi,
>
> 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?
>
> Any help is much appreciated,
> Thanks,
> Sam
The following will at least fill a triangle with hatch lines, green if
the orientation is positive, red if negative.
The mesh lines are plotted parallel to the first side. A better way
might be to plot them perpendicular to an angle bisector of the
triangle.
It's a little slow, and it needs to have the hatch lines have the same
spacings no matter how the vertices of the triangle are moved around.
A notebook and screen shots are at:
http://home.comcast.net/~cy56/HatchLines.nb
http://home.comcast.net/~cy56/HatchLines1.png
http://home.comcast.net/~cy56/HatchLines2.png
Module[
{
x1, y1, x2, y2, x3, y3,
orient
},
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$]]]\)]]];
Show[
Graphics[
{
FaceForm[], EdgeForm[], Polygon[P],
Blue, Line[{P[[1]], P[[2]]}],
Red, Line[{P[[2]], P[[3]]}],
Darker[Yellow, 0.3], Line[{P[[3]], P[[1]]}]
}
],
RegionPlot[
And @@ (If[orient > 0, Positive, Negative] /@ {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}
} )] }),
{x, -2, 2}, {y, -2, 2},
ColorFunction -> (White &),
BoundaryStyle -> None,
Mesh -> Round[20 Norm[P[[2]] - P[[1]]], 1],
MeshStyle -> (Green // If[orient > 0, #, Red] &),
MeshFunctions -> {{x, y} \[Function] Det[( {
{x2, x3, x},
{y2, y3, y},
{1, 1, 1}
} )]},
PlotPoints -> 50
],
PlotRange -> 2,
Axes -> True,
GridLines -> Automatic
],
{{P, {{0, 0}, {1, 0}, {1, 1}}}, Locator}
]
]
[toc] | [prev] | [standalone]
Back to top | Article view | comp.soft-sys.math.mathematica
csiph-web