Skip to main content

plotting - Hightlight all the self-intersections of a Lissajous figure



This graph–also known as a Lissajous figure–contains so many self-intersections.How can I highlight them?


ParametricPlot[{Sin[100 t], Sin[99 t]}, {t, 0, 2 π}, 
PlotRange -> All]

Answer



Manipulate[
ParametricPlot[({Sin[n t1], Sin[(n - 1) t1]}), {t1, 0, 2 Pi},
Epilog -> {Red, PointSize[Large],
Table[If[OddQ[i + j],
Point[{Cos[Pi i/(2 (n - 1))], Cos[Pi j/(2 (n))]}]], {i,
2 n - 3}, {j, 2 n - 1}]}], {{n, 5}, 2, 20, 1}]


enter image description here


General Case I


We can generalize to the Lissajous curve specified by the two non-negative integers $a$ and $b$:


$$ x = \sin at \\ y = \sin bt \\ t \in [0,2\pi) $$


Without loss of generality, I will assume $b

We can start by making a table of small cases:


Column[Row /@ 
Table[ParametricPlot[({Sin[a t], Sin[b t]}), {t, 0, 2 Pi},
Epilog -> {}, PlotLabel -> {a, b}, Axes -> False,

ImageSize -> Tiny], {a, 10}, {b,
Select[Range[a - 1], CoprimeQ[#, a] &]}], Alignment -> Center]

enter image description here


When both $a$ and $b$ are odd, we get a degenerate curve that traces itself twice. I'll handle those cases later.


It looks like each self-intersection occurs on a horizontal and vertical line shared with several other solutions. We can make a table mapping $a$ and $b$ to the number of horizontal and vertical grid lines (ignoring $b=1$ as a special case for now):


$$ 3,2\to 3,5\\ 4,3\to 5,7\\ 5,2\to 3,9\\ 5,4\to 7,9\\ 6,5\to 9,11 $$


It's fairly evident that the number of grid lines is merely:


$$ 2b-1,\,2a-1 $$





The spacing of the grid lines looks mathematically like it might be more difficult. However, the spacing looks familiar to me: like the spacing of points in an airfoil .dat file:


Graphics[Point@
Rest[Import[
"http://m-selig.ae.illinois.edu/ads/coord/naca2412.dat"]]]

enter image description here


I remember from AE311 (incompressible flow) that this spacing follows the transformation:


$$ x\mapsto \frac{c}{2}\left(1-\cos(\theta)\right) $$


with the points evenly spaced in $\theta$. Could it really be that simple?


Manipulate[

ParametricPlot[({Sin[a t], Sin[b t]}), {t, 0, 2 Pi},
GridLines -> {Cos[Pi Range[2 b - 1]/(2 b)],
Cos[Pi Range[2 a - 1]/(2 a)]}, PlotLabel -> {a, b},
Axes -> False], {{a, 5}, 2, 20, 1}, {{b, 4},
Select[Range[a - 1], CoprimeQ[#, a] &]}]

enter image description here


Heck yeah it is: lucky guess!


Note that only every other grid node contains an intersection; they form a sort of checkerboard pattern. This accounts for the seeming fewer number of grid lines when $b=1$: only every other line is occupied, so there are twice (plus one) as many grid lines as intersections.


We can also take a look at the odd-odd special cases:



enter image description here


We can see that they follow a double-size checkerboard pattern, with adjacent intersections two diagonals apart.


With all this in mind, we can now extend the code from the original example:


Manipulate[
ParametricPlot[
{Sin[a t], Sin[b t]}, {t, 0, 2 Pi},
GridLines -> {Cos[Pi Range[2 b - 1]/(2 b)], Cos[Pi Range[2 a - 1]/(2 a)]},
PlotLabel -> {a, b}, Axes -> False,
Epilog -> {Red, PointSize[Large],
Table[If[

If[OddQ[a] && OddQ[b],
EvenQ[i] && Divisible[i + j + a + b + 2, 4],
OddQ[i + j]],
Point[Cos[Pi/2 {i/b, j/a}]]
],
{i, 2 b - 1}, {j, 2 a - 1}]}
],
{{a, 5}, 2, 20, 1}, {{b, 4}, Select[Range[a - 1], CoprimeQ[#, a] &]}
]


enter image description here


General Case II


We can follow a similar procedure for phased Lissajous curves. Without loss of generality, we can apply a phase $\phi$ to the $x$-coordinate:


$$ x = \sin(at +\phi) \\ y = \sin(bt) \\ t \in [0,2\pi) $$


If we apply phases $\phi_a$ and $\phi_b$ to the $x$ and $y$-coordinates, respectively, this is equivalent to a curve with $\phi=\phi_a-\frac a b \phi_b$ and $t'=t+\frac{\phi_b}b$.


First we'll take a look at what's going on:


Manipulate[
ParametricPlot[{Sin[a t + Ï•], Sin[b t]}, {t, 0, 2 Pi},
PlotLabel -> {a, b}, Axes -> False], {{a, 5}, 2, 20, 1}, {{b, 4},
Select[Range[a - 1], CoprimeQ[#, a] &]}, {Ï•, 0, 2 Pi}]


enter image description here


I like to visualize this as the projection of a pattern on the surface of a vertical cylinder, rotating about its axis:


enter image description here


A little bit of work transforms the original solution to follow the intersections of the cylinder pattern:


enter image description here


Note that we're missing half of the intersections now! The missing intersections are where lines from the 'front' half of the cylinder overlap the 'back' half. We can get those via a similar process, treating the pattern as a projection from the surface of a horizontal cylinder. In the image above, we essentially want to reflect the 'missing' intersections across the diagonal:


enter image description here


This gives us our final result:


Manipulate[

With[{gcd = GCD[a, b]},
With[{a = a/gcd, b = b/gcd},
ParametricPlot[
{Sin[a t + Ï•], Sin[b t]}, {t, 0, 2 Pi},
PlotLabel -> {a, b}, Axes -> False,
Epilog -> {
PointSize[Large],
Red,
Table[
If[EvenQ[i + j],

Point[{Sin[2 Pi (i + a)/(2 b) + Ï•], Cos[Pi j/a]}]
],
{i, 2 b}, {j, a - 1}
],
Orange,
Table[
If[EvenQ[i + j],
Point[{Cos[Pi i/b], Sin[2 Pi (j + b)/(2 a) - b/a Ï•]}]
],
{i, b - 1}, {j, 2 a}

]
}
]
]
],
{{a, 6}, 1, 20, 1}, {{b, 13}, 1, 20, 1}, {{Ï•, Pi/10}, 0, 2 Pi}
]

enter image description here


(Note that for some values of Ï•, you will see repeated intersections or intersections at the edge of the curve. This happens when the curve becomes degenerate and overlaps itself.)



Comments

Popular posts from this blog

plotting - How to draw lines between specified dots on ListPlot?

I would like to create a plot where I have unconnected dots and some connected. So far, I have figured out how to draw the dots. My code is the following: ListPlot[{{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4,13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full] I have thought using ListLinePlot command, but I don't know how to specify to the command to draw only selected lines between the dots. Do have any suggestions/hints on how to do that? Thank you. Answer One possibility would be to use Epilog with Line : ListPlot[ {{1, 1}, {2, 2}, {3, 3}, {4, 4}, {1, 4}, {2, 5}, {3, 6}, {4, 7}, {1, 7}, {2, 8}, {3, 9}, {4, 10}, {1, 10}, {2, 11}, {3, 12}, {4, 13}, {2.5, 7}}, Ticks -> {{1, 2, 3, 4}, None}, AxesStyle -> Thin, TicksStyle -> Directive[Black, Bold, 12], Mesh -> Full, Epilog -> { Line[ ...

equation solving - Invert and fit implicitly defined curve

I need to fit an implicitly defined curve. I thought I could get some data out of Solve , and then using FindFit . Therefore, I would like to find the relation the parametric curve defined by $F(x,y)=0$: Solve[-(1/2) + 1/2 (0.41202 BesselK[0, 0.1 Sqrt[x^2 + y^2]] + (0.101483 x BesselK[1, 0.1 Sqrt[x^2 + y^2]])/Sqrt[x^2 + y^2]) == 0, y] But I can't get an output: Solve was unable to solve the system with inexact coefficients or the system obtained by direct rationalization of inexact numbers present in the system. Since many of the methods used by Solve require exact input, providing Solve with an exact version of the system may help. >> Edit: In particular, I would like to fit the data coming from the curve with the expression of another curve, and not with a function $f(x)$. In particular, since this clearly looks like a cardioid , I would like it to fit to something like it. What other strategies could I try?

dynamic - How can I make a clickable ArrayPlot that returns input?

I would like to create a dynamic ArrayPlot so that the rectangles, when clicked, provide the input. Can I use ArrayPlot for this? Or is there something else I should have to use? Answer ArrayPlot is much more than just a simple array like Grid : it represents a ranged 2D dataset, and its visualization can be finetuned by options like DataReversed and DataRange . These features make it quite complicated to reproduce the same layout and order with Grid . Here I offer AnnotatedArrayPlot which comes in handy when your dataset is more than just a flat 2D array. The dynamic interface allows highlighting individual cells and possibly interacting with them. AnnotatedArrayPlot works the same way as ArrayPlot and accepts the same options plus Enabled , HighlightCoordinates , HighlightStyle and HighlightElementFunction . data = {{Missing["HasSomeMoreData"], GrayLevel[ 1], {RGBColor[0, 1, 1], RGBColor[0, 0, 1], GrayLevel[1]}, RGBColor[0, 1, 0]}, {GrayLevel[0], GrayLevel...