DCL:らくらくDCL:描画の基本(2):ユーザー座標系(U-座標系)での基本描画
変換メソッド(元関数)を変えることによってさまざまな座標系での描画が可能です. SGPACK
で扱える座標系には, 大別して, 直交直線座標系(1〜4), 直交曲線座標系
(5〜7), 地図投影座標系(10番台〜30番台), ユーザー定義座標系
(99), の4種類があります. 括弧内の数字は変換メソッド(元関数)番号です. kihon8
のプログラム例では, よく使う直交直線座標系の4つを見ておきましょう.
メソッド(元サブルーチン) bplot では, ビューポートの枠を描き, 一次メソッド(元関数)を実線
で, 指数メソッド(元関数)を破線で, 対数メソッド(元関数)を点線で描き, (X=30,Y=40) を中心に
sgtxu で文字列 '(30,40)' を描きます. sgstrn ルーチン
で変換メソッド(元関数)番号を1と指定すると,直角一様座標(左上)となります. 2ならばy軸が対数の片対数座標(右上), 3ならばx軸が対数の片対数座標(左下), 4な
らば両対数座標(右下)となります.
# kihon8.rb
require "narray"
require "numru/dcl"
include NumRu
include NMath
xmin = 1.0
xmax = 100.0
ymin = 1.0
ymax = 100.0
def bplot
nmax = 50
x = NArray.sfloat(nmax)
y = NArray.sfloat(nmax)
DCL::slpvpr(1)
#-- 一次関数 ----
x.indgen(2.0, 2.0)
y = x
DCL::sgsplt(1)
DCL::sgplu(x, y)
#-- 指数関数 ----
y = exp(0.05*x)
DCL::sgsplt(2)
DCL::sgplu(x, y)
#-- 対数関数 ----
y = 20.0 * log(x)
DCL::sgsplt(3)
DCL::sgplu(x, y)
#-- 文字列 ----
DCL::sgstxs(0.02)
DCL::sgtxu(30.0, 40.0, '(30,40)')
end
#-- graph ---
iws = (ARGV[0] || (puts ' WORKSTATION ID (I) ? ;'; DCL::sgpwsn; gets)).to_i
DCL::sgopn iws
DCL::sglset('LCLIP', true)
DCL::sgfrm
#-- 直角一様座標(左上) ----
DCL::sgswnd(xmin, xmax, ymin, ymax)
DCL::sgsvpt(0.1, 0.4, 0.6, 0.9)
DCL::sgstrn(1)
DCL::sgstrf
bplot
#-- 片対数(y)座標(右上) ----
DCL::sgswnd(xmin, xmax, ymin, ymax)
DCL::sgsvpt(0.6, 0.9, 0.6, 0.9)
DCL::sgstrn(2)
DCL::sgstrf
bplot
#-- 片対数(x)座標(左下) ----
DCL::sgswnd(xmin, xmax, ymin, ymax)
DCL::sgsvpt(0.1, 0.4, 0.1, 0.4)
DCL::sgstrn(3)
DCL::sgstrf
bplot
#-- 対数座標(右下) ----
DCL::sgswnd(xmin, xmax, ymin, ymax)
DCL::sgsvpt(0.6, 0.9, 0.1, 0.4)
DCL::sgstrn(4)
DCL::sgstrf
bplot
DCL::sgcls