What are the rules to formulate either polar or parametric equations in gnuplot such that the palette
linecolor can be used?
This post explains the plotting of some parametric equations I am interested in, and I would like to rewrite that plot using the palette
ability of gnuplot as described here. I read this post which shows how this might be possible, so my long-winded attempt to get anything close is below - before a brief note: I retained the beta
parameter only to get the new plot to work before I understand it - i.e. there is no "beta" parameter I am interested in per se, and I see there is a "convert polar to cartesian" in the code, though I do not grasp how it is being used:
### parametric plot
reset session
x00(t) = (R + r)*cos(t) - d*cos((R + r)/r*t)
y00(t) = (R + r)*sin(t) - d*sin((R + r)/r*t)
#
beta=1.0
x01(t,beta) = (R + r)*cos(t*beta) - d*cos((R + r)/r*t*beta)
y01(t,beta) = (R + r)*sin(t*beta) - d*sin((R + r)/r*t*beta)
#
zValueForGradient(t,beta)= cos(t*beta)
#
# convert polar to cartesian
r_x(t)=x01(t,beta)*cos(t)
r_y(t)=y01(t,beta)*sin(t)
# #
set palette model RGB defined (-1 "blue", 0 "black", 1 "red")
#
set parametric
set size ratio -1
set grid x,y
set multiplot layout 2,2
# epicycloid:
set title "want epicycloid \n with gradient"
R=3.0; r=1.0 ; d=0.5
plot [0:2*pi] '+' u (r_x($1)):(r_y($1)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette
# hypotrochoid:
set title "want hypotrochoid \n with gradient"
R=5.0; r=-3.0; d=5.0
plot [0:3*pi] '+' u (r_x($1)):(r_y($1)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette
# epicycloid:
set title "true epicycloid"
R=3.0; r=1.0 ; d=0.5
set xrange[-6:6]
set yrange[-6:6]
set trange[0:2*pi]
plot x00(t),y00(t) w l t '' lw 2 lc "red"
# hypotrochoid:
set title "true hypotrochoid"
R=5.0; r=-3.0; d=5.0
set xrange[-8:8]
set yrange[-8:8]
set trange[0:6*pi]
plot x00(t),y00(t) w l t '' lw 2 lc "blue"
unset multiplot
### end of script
the plot looks like this (wxt 0 enhanced
terminal):
The attempted plots - with no resemblance of epicycloids or hypotrochoids - are on the top row, the plots of the original functions from this plot are on the bottom row. One can clearly see the functions (x01
, y01
, r_x
, r_y
in the script) are is getting colored according to the z palette
(zValueForGradient(t,beta)
). Seems close, but clearly as well, I do not understand how to apply this to functions as described in the source post. It is unclear to me how to treat these functions, or to use the approach in this to get the intended effect.
To reiterate : how should a parametric function be treated in gnuplot so that it will be colored according to palette
, but also preserve the nature of function itself?
I am not sure whether I fully understood your question.
Why do you want to convert x01(t,beta)
and y01(t,beta)
into cartesian coordinates? They are already in cartesian coordinates. Simply use them directly, e.g. like:
plot [0:2*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))
plot [0:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))
Alternatively, do you maybe want to have a polar plot graph?
Script:
### parametric plot
reset session
x00(t) = (R + r)*cos(t) - d*cos((R + r)/r*t)
y00(t) = (R + r)*sin(t) - d*sin((R + r)/r*t)
#
beta=1.0
x01(t,beta) = (R + r)*cos(t*beta) - d*cos((R + r)/r*t*beta)
y01(t,beta) = (R + r)*sin(t*beta) - d*sin((R + r)/r*t*beta)
#
zValueForGradient(t,beta)= cos(t*beta)
#
# convert polar to cartesian
r_x(t)=x01(t,beta)*cos(t)
r_y(t)=y01(t,beta)*sin(t)
#
set palette model RGB defined (-1 "blue", 0 "black", 1 "red")
#
set parametric
set size ratio -1
set grid x,y
set multiplot layout 2,2
# epicycloid:
set title "want epicycloid \n with gradient"
R=3.0; r=1.0 ; d=0.5
plot [0:2*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette
# hypotrochoid:
set title "want hypotrochoid \n with gradient"
R=5.0; r=-3.0; d=5.0
plot [0:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta)) t '' w l lw 2 lc palette
# epicycloid:
set title "true epicycloid"
R=3.0; r=1.0 ; d=0.5
set xrange[-6:6]
set yrange[-6:6]
set trange[0:2*pi]
plot x00(t),y00(t) w l t '' lw 2 lc "red"
# hypotrochoid:
set title "true hypotrochoid"
R=5.0; r=-3.0; d=5.0
set xrange[-8:8]
set yrange[-8:8]
set trange[0:6*pi]
plot x00(t),y00(t) w l t '' lw 2 lc "blue"
unset multiplot
### end of script
Result: