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=sinaty=sinbtt[0,2π)


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,23,54,35,75,23,95,47,96,59,11


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


2b1,2a1





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:


xc2(1cos(θ))


with the points evenly spaced in θ. 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 ϕ to the x-coordinate:


x=sin(at+ϕ)y=sin(bt)t[0,2π)


If we apply phases ϕa and ϕb to the x and y-coordinates, respectively, this is equivalent to a curve with ϕ=ϕaabϕb and t=t+ϕbb.


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

functions - Get leading series expansion term?

Given a function f[x] , I would like to have a function leadingSeries that returns just the leading term in the series around x=0 . For example: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x)] x and leadingSeries[(1/x + 2 + (1 - 1/x^3)/4)/(4 + x)] -(1/(16 x^3)) Is there such a function in Mathematica? Or maybe one can implement it efficiently? EDIT I finally went with the following implementation, based on Carl Woll 's answer: lds[ex_,x_]:=( (ex/.x->(x+O[x]^2))/.SeriesData[U_,Z_,L_List,Mi_,Ma_,De_]:>SeriesData[U,Z,{L[[1]]},Mi,Mi+1,De]//Quiet//Normal) The advantage is, that this one also properly works with functions whose leading term is a constant: lds[Exp[x],x] 1 Answer Update 1 Updated to eliminate SeriesData and to not return additional terms Perhaps you could use: leadingSeries[expr_, x_] := Normal[expr /. x->(x+O[x]^2) /. a_List :> Take[a, 1]] Then for your examples: leadingSeries[(1/x + 2)/(4 + 1/x^2 + x), x] leadingSeries[Exp[x], x] leadingSeries[(1/x + 2 + (1 - 1/x...

mathematical optimization - Minimizing using indices, error: Part::pkspec1: The expression cannot be used as a part specification

I want to use Minimize where the variables to minimize are indices pointing into an array. Here a MWE that hopefully shows what my problem is. vars = u@# & /@ Range[3]; cons = Flatten@ { Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; Minimize[{Total@((vec1[[#]] - vec2[[u[#]]])^2 & /@ Range[1, 3]), cons}, vars, Integers] The error I get: Part::pkspec1: The expression u[1] cannot be used as a part specification. >> Answer Ok, it seems that one can get around Mathematica trying to evaluate vec2[[u[1]]] too early by using the function Indexed[vec2,u[1]] . The working MWE would then look like the following: vars = u@# & /@ Range[3]; cons = Flatten@{ Table[(u[j] != #) & /@ vars[[j + 1 ;; -1]], {j, 1, 3 - 1}], 1 vec1 = {1, 2, 3}; vec2 = {1, 2, 3}; NMinimize[ {Total@((vec1[[#]] - Indexed[vec2, u[#]])^2 & /@ R...

What is and isn't a valid variable specification for Manipulate?

I have an expression whose terms have arguments (representing subscripts), like this: myExpr = A[0] + V[1,T] I would like to put it inside a Manipulate to see its value as I move around the parameters. (The goal is eventually to plot it wrt one of the variables inside.) However, Mathematica complains when I set V[1,T] as a manipulated variable: Manipulate[Evaluate[myExpr], {A[0], 0, 1}, {V[1, T], 0, 1}] (*Manipulate::vsform: Manipulate argument {V[1,T],0,1} does not have the correct form for a variable specification. >> *) As a workaround, if I get rid of the symbol T inside the argument, it works fine: Manipulate[ Evaluate[myExpr /. T -> 15], {A[0], 0, 1}, {V[1, 15], 0, 1}] Why this behavior? Can anyone point me to the documentation that says what counts as a valid variable? And is there a way to get Manpiulate to accept an expression with a symbolic argument as a variable? Investigations I've done so far: I tried using variableQ from this answer , but it says V[1...