--[[ $Id: x22.lua 9526 2009-02-13 22:06:13Z smekal $ Simple vector plot example Copyright (C) 2008 Werner Smekal This file is part of PLplot. PLplot is free software you can redistribute it and/or modify it under the terms of the GNU General Library Public License as published by the Free Software Foundation either version 2 of the License, or (at your option) any later version. PLplot is distributed in the hope that it will be useful, but WITHOUT ANY WARRANTY without even the implied warranty of MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU Library General Public License for more details. You should have received a copy of the GNU Library General Public License along with PLplot if not, write to the Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA --]] -- initialise Lua bindings for PLplot examples. dofile("plplot_examples.lua") -- Pairs of points making the line segments used to plot the user defined arrow arrow_x = { -0.5, 0.5, 0.3, 0.5, 0.3, 0.5 } arrow_y = { 0, 0, 0.2, 0, -0.2, 0 } arrow2_x = { -0.5, 0.3, 0.3, 0.5, 0.3, 0.3 } arrow2_y = { 0, 0, 0.2, 0, -0.2, 0 } -- Vector plot of the circulation about the origin function circulation() nx = 20 ny = 20 dx = 1 dy = 1 xmin = -nx/2*dx xmax = nx/2*dx ymin = -ny/2*dy ymax = ny/2*dy cgrid2 = {} cgrid2["xg"] = {} cgrid2["yg"] = {} cgrid2["nx"] = nx cgrid2["ny"] = ny u = {} v = {} -- Create data - circulation around the origin. for i = 1, nx do x = (i-1-nx/2+0.5)*dx cgrid2["xg"][i] = {} cgrid2["yg"][i] = {} u[i] = {} v[i] = {} for j=1, ny do y = (j-1-ny/2+0.5)*dy cgrid2["xg"][i][j] = x cgrid2["yg"][i][j] = y u[i][j] = y v[i][j] = -x end end -- Plot vectors with default arrows pl.env(xmin, xmax, ymin, ymax, 0, 0) pl.lab("(x)", "(y)", "#frPLplot Example 22 - circulation") pl.col0(2) pl.vect(u, v, 0, "pltr2", cgrid2 ) pl.col0(1) end -- Vector plot of flow through a constricted pipe function constriction() nx = 20 ny = 20 dx = 1 dy = 1 xmin = -nx/2*dx xmax = nx/2*dx ymin = -ny/2*dy ymax = ny/2*dy cgrid2 = {} cgrid2["xg"] = {} cgrid2["yg"] = {} cgrid2["nx"] = nx cgrid2["ny"] = ny u = {} v = {} Q = 2 for i = 1, nx do x = (i-1-nx/2+0.5)*dx cgrid2["xg"][i] = {} cgrid2["yg"][i] = {} u[i] = {} v[i] = {} for j = 1, ny do y = (j-1-ny/2+0.5)*dy cgrid2["xg"][i][j] = x cgrid2["yg"][i][j] = y b = ymax/4*(3-math.cos(math.pi*x/xmax)) if math.abs(y)