#/*********************************************************** # 3dgraph.rb -- 3次元グラフ #***********************************************************/ require "plotter.rb" Xmin = -1; Ymin = -1; Zmin = -1 # 座標の下限 Xmax = 1; Ymax = 1; Zmax = 1 # 座標の上限 def func(x, z) # 描く関数 (例) r2 = x * x + z * z return Math::exp(-r2) * Math::cos(10 * Math::sqrt(r2)) end lowerhorizon = []; upperhorizon = [] gr_on for i in 0..240 lowerhorizon[i] = 1e30; # 正の無限大 upperhorizon[i] = -1e30; # 負の無限大 end for iz in 0..20 z = Zmin + (Zmax - Zmin) / 20.0 * iz ok1 = 0 for ix in 0..200 x = Xmin + (Xmax - Xmin) / 200.0 * ix i = ix + 2 * (20 - iz); # 0..240 y = 30 * (func(x, z) - Ymin) / (Ymax - Ymin).to_f + 5 * iz; # 0..130 ok = 0 if (y < lowerhorizon[i]) lowerhorizon[i] = y; ok = 1 end if (y > upperhorizon[i]) upperhorizon[i] = y; ok = 1 end if ((ok == 1) && (ok1 == 1)); draw(i, y); else; move(i, y); end ok1 = ok end end gr_off exit 0