Gnuplot:将参数方程或极坐标函数转换或重写为调色板线条颜色。

huangapple go评论58阅读模式
英文:

Gnuplot : convert or rewrite parametric or polar functions for the palette linecolor

问题

I will translate the content you provided in English without the code:

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

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 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 the function itself?"

英文:

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):
Gnuplot:将参数方程或极坐标函数转换或重写为调色板线条颜色。

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?

答案1

得分: 1

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:6*pi] '+' u (x01($1,beta)):(y01($1,beta)):(zValueForGradient($1,beta))

Alternatively, do you maybe want to have a polar plot graph?

Script:

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:

Gnuplot:将参数方程或极坐标函数转换或重写为调色板线条颜色。

英文:

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:

Gnuplot:将参数方程或极坐标函数转换或重写为调色板线条颜色。

huangapple
  • 本文由 发表于 2023年3月21日 01:42:09
  • 转载请务必保留本文链接:https://go.coder-hub.com/75793577.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定