Take the 2-minute tour ×
Mathematica Stack Exchange is a question and answer site for users of Mathematica. It's 100% free, no registration required.

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

share|improve this question
1  
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` –  chris Nov 14 '12 at 8:14
add comment

4 Answers

up vote 3 down vote accepted

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

share|improve this answer
    
Excellent answer, as always! –  rm -rf Nov 14 '12 at 16:13
1  
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. –  Zippy The Pinhead Nov 15 '12 at 0:35
add comment

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.

share|improve this answer
    
I appreciate the quick reply. How could this be modified to incorporate a different basis for R^2, like {{3,1},{1,2}}? –  Zippy The Pinhead Nov 14 '12 at 4:33
    
@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. –  rm -rf Nov 14 '12 at 4:39
    
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). –  Zippy The Pinhead Nov 14 '12 at 5:18
    
@Zippy, then the version in my answer is the one you're looking for. You're familiar with rotation matrices, I gather? –  J. M. Nov 14 '12 at 7:54
    
Yes, and I'm going to work with the example code you provided. Everyone has been very helpful, many thanks. –  Zippy The Pinhead Nov 14 '12 at 12:44
add comment

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

share|improve this answer
add comment

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.

share|improve this answer
    
For me that graphic is an optical illusion: it makes the main grid look decidedly crooked. –  Mr.Wizard Nov 15 '12 at 13:38
add comment

Your Answer

 
discard

By posting your answer, you agree to the privacy policy and terms of service.

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