gnuplotparametric-equations

gnuplot : parametric equation, positive variable OK, negative variable confusing


Using gnuplot (5.4 patchlevel 2 - see script below), I plotted the parametric equation from this Wikipedia entry:

https://en.wikipedia.org/wiki/Cyclocycloid

If the given epicycloid variables R=3, r=1, d=0.5 are used (see below), the result matches that on the Wikipedia page. However, using the hypotrochoid variables R=5, r=-3, d=5 produces a plot that does not match the example (it should be a five-fold symmetric star shape). That it is a circle is suggestive of a technical misunderstanding.

script :

reset
# hypotrochoid:
R=5 ; r=(-3) ; d=5
# epicycloid:
# R=3 ; r=1 ; d=(0.5)
x(t) = (R + r) * cos(t) - d * cos( ( ( R + r ) / ( r )  ) * t )
y(t) = (R + r) * sin(t) - d * sin( ( ( R + r ) / ( r )  ) * t )
set parametric
set size square
plot x(t),y(t)

I suspect I have a fundamental misunderstanding of how gnuplot uses the values, how users provide them, or with parametric plotting. I have tried a number of things to explore this, such as :

-adding or removing parentheses

-expressing -3 as -3.0 (interesting, as it produces a fish-like trace)

-incrementally increasing or decreasing the values

-fractions v. decimals

... generally, the negative value produces results that are unexpected. I have managed to get nice drawings, but they are not producing the result on Wikipedia. I cannot tell if it is the expression, the value, or both - perhaps the Wikipedia article needs more information, or it is a mathematics question. It has me running in... circles.

pos-answer follow-up : notice - the range is unspecified, and gnuplot dutifully produces a plot to, apparently, the default of 2*pi - while clearly, the Wikipedia entry shows the plot needs to be run for 3 cycles to see the symmetric pattern.


Solution

  • This is the "everlasting pitfall" of gnuplot's integer division. Make your input parameters floating point values and everything should be fine.

    Script:

    ### parametric plot
    reset session
    
    x(t) = (R + r)*cos(t) - d*cos((R + r)/r*t)
    y(t) = (R + r)*sin(t) - d*sin((R + r)/r*t)
    set parametric
    set size ratio -1
    set grid x,y
    
    set multiplot layout 1,2
    
        # epicycloid:
        R=3.0; r=1.0  ; d=0.5
        set trange[0:2*pi]
        plot x(t),y(t) w l lw 2 lc "red"
    
        # hypotrochoid:
        R=5.0;  r=-3.0;  d=5.0
        set trange[0:6*pi]
        plot x(t),y(t) w l lw 2 lc "blue"
    
    unset multiplot
    ### end of script
    

    Result:

    enter image description here

    Addition:

    Just for completeness: rotating the graph by 90°, by exchanging cos() and sin() and changing the sign on y(t). And keeping the graph a square by same x- and y-range.

    Script:

    ### parametric plot
    reset session
    
    x(t) =  (R + r)*sin(t) - d*sin((R + r)/r*t)
    y(t) = -(R + r)*cos(t) + d*cos((R + r)/r*t)
    
    set parametric
    set size ratio -1
    set grid x,y
    
    set multiplot layout 1,2
    
        # epicycloid:
        R=3.0; r=1.0  ; d=0.5
        set xrange[-6:6]
        set yrange[-6:6]
        set trange[0:2*pi]
        plot x(t),y(t) w l lw 2 lc "red"
    
        # hypotrochoid:
        R=5.0;  r=-3.0;  d=5.0
        set xrange[-8:8]
        set yrange[-8:8]
        set trange[0:6*pi]
        plot x(t),y(t) w l lw 2 lc "blue"
    
    unset multiplot
    ### end of script
    

    Result:

    enter image description here