9
$\begingroup$

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...

$\endgroup$
1
  • 1
    $\begingroup$ Welcome to Mathematica.SE! I suggest the following: 1) As you receive help, try to give it too, by answering questions in your area of expertise. 2)Read the FAQs! 3) When you see good Q&A, vote them up by clicking 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$
    – chris
    Nov 14, 2012 at 8:14

4 Answers 4

5
$\begingroup$

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]

Cartesian and polar 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]

Figure reproduction

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).

$\endgroup$
2
  • $\begingroup$ Excellent answer, as always! $\endgroup$
    – rm -rf
    Nov 14, 2012 at 16:13
  • 1
    $\begingroup$ This is an extremely helpful answer. Many thanks. My ability with Mathematica is very limited, and I couldn't have come up with this at all, but I can edit this to meet my needs. $\endgroup$ Nov 15, 2012 at 0:35
8
$\begingroup$

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, ∞]]

dual grid

$\endgroup$
7
$\begingroup$

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.

$\endgroup$
5
  • $\begingroup$ I appreciate the quick reply. How could this be modified to incorporate a different basis for R^2, like {{3,1},{1,2}}? $\endgroup$ Nov 14, 2012 at 4:33
  • $\begingroup$ @ZippyThePinhead I didn't read the article... just saw the figure. Do you want to orient the lines along some rotation θ instead? If so, then you'll have to use RotationTransform with primitives or as in J.M.'s answer. $\endgroup$
    – rm -rf
    Nov 14, 2012 at 4:39
  • $\begingroup$ No, I want to be able to pick two basis vectors for R^2 and show the coordinate system that results, superposed over R^2 with a different basis. The grid you generated above would correspond to the standard basis (background, grey) and the basis {{-sqrt(2)/2, sqrt(2)/2},{sqrt(2)/2, sqrt(2)/2}} (green). $\endgroup$ Nov 14, 2012 at 5:18
  • $\begingroup$ @Zippy, then the version in my answer is the one you're looking for. You're familiar with rotation matrices, I gather? $\endgroup$ Nov 14, 2012 at 7:54
  • $\begingroup$ Yes, and I'm going to work with the example code you provided. Everyone has been very helpful, many thanks. $\endgroup$ Nov 14, 2012 at 12:44
2
$\begingroup$

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]

Graph showing two different axes.

To add things such as arrows and anotations you can use Arrow and Text.

$\endgroup$
1
  • $\begingroup$ For me that graphic is an optical illusion: it makes the main grid look decidedly crooked. $\endgroup$
    – Mr.Wizard
    Nov 15, 2012 at 13:38

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge that you have read and understand our privacy policy and code of conduct.

Not the answer you're looking for? Browse other questions tagged or ask your own question.