Is there a slick way to generate the dual-grid graphs such as you can see on pages 7, 9, and 10 of this article, or this one?
I've searched, but found nothing. Thanks in advance...
Mathematica Stack Exchange is a question and answer site for users of Wolfram Mathematica. It only takes a minute to sign up.
Sign up to join this communityIs there a slick way to generate the dual-grid graphs such as you can see on pages 7, 9, and 10 of this article, or this one?
I've searched, but found nothing. Thanks in advance...
By definition, a (real) "coordinate" is a map from a region into the Real numbers. To show a coordinate, we usually fix specific values, such as $\ldots, -3, -2, \ldots, 1, 2, 3, \ldots$, and graph the inverse images (level sets) of these values. We will want to distinguish different coordinates by varying the graphical representations of these level sets.
We should encapsulate these elements--coordinate functions, graphical attributes, and discrete sets of values--in some convenient data structure. The simplest to use is a list. For example, here are descriptions of a pair of Cartesian coordinates and a pair of Polar coordinates:
coordinates = {
{#1 &, Gray, Range[-3, 3]},
{#2 &, Gray, Range[-3, 3]},
{Norm[{#1, #2}] &, Directive[Darker[Red], Dashed], Range[-3, 3]},
{ArcTan[#1, #2] &, Directive[Darker[Red], Dashed], Range[-\[Pi] + \[Pi]/7, \[Pi], 2 \[Pi]/7]}
};
Here's the "slick" part: merely map ContourPlot
over this list and wrap it all in Show
to overlay the whole bunch.
Show[ContourPlot[#1[x, y], {x, -3, 3}, {y, -3, 3}, Contours -> #3,
ContourStyle -> #2, ContourShading -> None] & @@@ coordinates]
(The mashup along the negative $x$ axis is a Mathematica problem with contouring ArcTan
; it's not the result of this particular method.)
In a similar way we can reproduce the Arnold figures using the very calculations they are intended to illustrate. Here is (most) of one of them:
basis = {{1, 1}, {-1, 1}}; (* New basis *)
dual = Inverse[basis]; (* New coordinate functions *)
green = ConstantArray[Green, 8]~Join~{Black}~Join~ConstantArray[Green, 8];
coordinates = {
{(dual.{#1, #2} // First) &, green, Range[-8, 8]},
{(dual.{#1, #2} // Last) &, green, Range[-8, 8]},
{#1 &, LightGray, Range[-5, 5]},
{#2 &, LightGray, Range[-5, 5]}
};
Show[ContourPlot[#1[x, y], {x, -5, 5}, {y, -5, 5}, Contours -> #3,
ContourStyle -> #2, ContourShading -> None] & @@@ coordinates]
This is not limited to two coordinate systems: coordinates
can be a list of any length, allowing display of any number of coordinate functions simultaneously. And it is direct: you do not have to work out the inverse coordinate functions (which would be required with a solution based on Plot
or ParametricPlot
, for instance).
A possible starting point:
With[{θ = π/3},
DeleteCases[
ParametricPlot[{{x, y}, RotationTransform[-θ][Sqrt[2] {x, y}]},
{x, -5, 5}, {y, -5, 5}, PlotRange -> {{-5, 5}, {-5, 5}}],
_Polygon, ∞]]
Here's a start using just simple plotting functions.
With[{m = 5},
Plot[
{Table[i x + j, {j, -2 m, 2 m}, {i, {-1, 1}}], Sequence[-x, x]}, {x, -m, m},
AspectRatio -> 1, PlotRange -> {-m, m}, PlotStyle -> {Green, {Thick, Black}},
AxesStyle -> Thick, Ticks -> None, GridLines -> ({Range[-m, m], Range[-m, m]}),
GridLinesStyle -> Directive@LightGray
]
]
You can get fancier and gain more control using graphics primitives.
RotationTransform
with primitives or as in J.M.'s answer.
$\endgroup$
You can accomplish things like this by defining your own functions to generate descriptions for Graphics
here is a simple function that generates a grid over two arbitrary basis vectors:
genGrid[v1_, v2_, l_: 10] := {
Line /@ Table[v1 n1 + v2 n2, {n1, -l, l}, {n2, {-l, l}}],
Line /@ Table[v1 n1 + v2 n2, {n2, -l, l}, {n1, {-l, l}}]
}
You can then use it along with other graphics options to style your resulting figure:
Graphics[{
{Black, genGrid[{1, 0}, {0, 1}]},
{Gray, genGrid[{1, 1}, {2, 1}, 14]}
}, PlotRange -> 3, Frame -> True, PlotRangeClipping -> True]
To add things such as arrows and anotations you can use Arrow
and Text
.
Read the FAQs
! 3) When you see good Q&A, vote them up byclicking the gray triangles
, because the credibility of the system is based on the reputation gained by users sharing their knowledge. ALSO, remember to accept the answer, if any, that solves your problem,by clicking the checkmark sign
` $\endgroup$