坐标系转换和坐标转换是最简单的,但是公式经常容易搞混,放在这里随时查看。 翻译自: http://www.metro-hs.ac.jp/rs/sinohara/zahyou_rot/zahyou_rotate.htm 翻译: 汤 永康 出处: http://blog.csdn.net/tangyongkang 转贴请注明出处 1 围绕原点的旋转 如下图, 在2维坐标上,有一点p(x, y) , 直线opの长度为r, 直线op和x轴的正向的夹角为a。 直线op围绕原点做逆时针方向b度的旋转,到达p’ (s,t) s = r cos(a + b) = r cos(a)cos(b) – r sin(a)sin(b) (1.1) t = r sin(a + b) = r sin(a)cos(b) + r cos(a) sin(b) (1.2) 其中 x = r cos(a) , y = r sin(a) 代入(1.1), (1.2) , s = x cos(b) – y sin(b) (1.3) t = x sin(b) + y cos(b) (1.4) 用行列式表达如下: 2.座标系的旋转 在原坐标系xoy中, 绕原点沿逆时针方向旋转theta度, 变成座标系 sot。 设有某点p,在原坐标系中的坐标为 (x, y), 旋转后的新坐标为(s, t)。 oa = y sin(theta) (2.1) as = x cos(theta) (2.2) 综合(2.1),(2.2) 2式 s = os = oa + as = x cos(theta) + y sin(theta) t = ot = ay – ab = y cos(theta) – x sin(theta) 用行列式表达如下:
我们现在知道了 gnuplot 有第一( first )和第二( second )两套坐标系统,但是 gnuplot 的坐标系统还不止于此。除此之外,它还有 graph , screen 和 character 三套坐标系统。 graph 和 screen 都是归一化的坐标系统。 graph 以坐标轴包围区域为界,左下角为 0,0 ,右上角为 1,1 ; screen 以整个图片区域为界,左下角为 0,0 ,右上角为 1,1 。 character 顾名思义,是以字符大小为单位长度的坐标系统,因此它的单位长度依赖于字体大小。它的原点位置和 screen 相同。 下面我们结合 label 命令来了解一下这几个坐标系统。我们之前讲过 xlabel 和 ylabel 。而这里的 label 命令,是在图中任何地方插入文字标签。还是来看例子: gnuplot sinc(x) = sin(pi*x)/(pi*x) gnuplot set xlabel "X" gnuplot set ylabel "Y" gnuplot unset key gnuplot set samples 500 gnuplot set xrange gnuplot set xtics 1 gnuplot set x2range gnuplot set x2tics 1 gnuplot set y2range gnuplot set y2tics 1 gnuplot set grid gnuplot set label 1 "Hello first" at 2,0.5 gnuplot set label 2 "Hello second" at second 2,0.5 gnuplot set label 3 "Hello graph" at graph 0.2,0.5 gnuplot set label 4 "Hello screen" at screen 0.2,0.5 gnuplot set label 5 "Hello character" at character 10,5 gnuplot plot sinc(x) 这里我们画一个 sinc 函数图像。为了说明问题,我们把第二坐标系也都标示了出来,虽然函数图像并没有用到第二坐标。其他命令前面都讲过了,这里只看五个 set label 命令。 set label 之后紧跟的那个整数,就是一个标识符,用以区别各个 label ,可以随便选个整数。在字符串之后, at 参数指定标签坐标。默认为 first 坐标系统,也可以使用其它坐标系统。下面是生成的图片: 为了帮助大家理解,我们把 graph 和 screen 各自的坐标区域分别用绿色和橙色表示了出来。 标签文字的默认对齐方式为居左,也就是指定的坐标位置在文字的左边。我们也可以在 label 命令里选择其他对齐方式。除此之外,我们还可以在 label 命令里指定文字颜色,旋转文字,或者在指定坐标位置处加一个点。下面例子中的每个参数不必一一解释了,因为和我们前面接触过的命令都是一致的: gnuplot set label 1 "Hello red left" at 2,0.4 left textcolor rgb "#FF0000" gnuplot set label 2 "Hello green center" at 2,0.5 center textcolor rgb "#00FF00" gnuplot set label 3 "Hello blue right" at 2,0.6 right textcolor rgb "#0000FF" gnuplot set label 4 "Hello rotate" at -2,0.4 rotate by 45 gnuplot set label 5 "Hello point" at -3,0.2 point pt 7 lc rgb "#FF9900" gnuplot replot