To make a 3D plot, you first create a member of the the class figure3d.
fig = figure3d.new();
plot(xf, yf, zf, urange, vrange, meshsize, frontcolor, bgcolor);where xf, yf, and zf are the three parameteric equations that define the surface to be drawn. Each of them is a function of two parameters. For example, the unit sphere can be represented by the following three equations
urange is the range of the first parameter. vrange is the range of the second parameter.
meshsize is a vector of two numbers, which specifies how many points are sampled on urange and vrange. If these numbers are big, the surface will be finer and smoother; otherwise it be more like a polyhedron rather than a smooth surface.
frontcolor and bgcolor are the colors of the front side and the back side of the surface respectively. Here we suppose that the surface is orientable, i.e., it has two sides.
A semisphere can be drawn using this command
fig = figure3d.new(); xf = (u, v) -> cos(u) * cos(v); yf = (u, v) -> cos(u) * sin(v); zf = (u, v) -> sin(u); fig.plot(xf, yf, zf, [-pi/2, 0 ], [0, 2 * pi]); fig.save("semisphere.eps");
In the above meshsize, frontcolor and bgcolor are not specified -- the default values are used.
Draws a smooth curve through a set of points in the space.
fig.curve(x, y, z, color, lw);x, y, and z are three vectors of the same length which are treated as the coordinates of dots in the space; a smooth curve with width lw through the dots will be drawn. Without some background, it is very hard to tell if a curve is in 3D space. So in the following example, we plot three orthogonal planes to reveal the dimension
fig = figure3d.new(); fig.light_direction = [2/3, 1/3, 3/5]; gx = (y, z) -> 0; gy = (x, z) -> 0; gz = (x, y) -> 0; fig.plot(gx, (y,z)->y, (y,z)->z, [0, 30], [0, 30], [4, 4], rand(3), rand(3)); fig.plot((x,y)->x, (x,y)->y, gz, [0, 30], [0, 30], [4, 4], rand(3), rand(3)); fig.plot((x,z)->x, gy, (x,z)->z, [0, 30], [0, 30], [4, 4], rand(3), rand(3)); t = linspace(0, 10 * pi); x = 6 * cos(t) + 10; y = 6 * sin(t) + 10; fig.curve(x, y, t, colors.red, 3); fig.save("spiral.eps");
fig.polygon(x, y, z, nv, frontcolor, bgcolor);
Draws a polygon whose vertices are x, y, and z, normal direction is nv (a 3d vector), colors of front and back are frontcolor and bgcolor.
This is like a uniform discretization of a surface over the rectangle . You only need to provide the z coordinates of the points on the surface.
fig.mesh(v, frontcolor, bgcolor);v is a matrix whose elements are treated as the the z coordinates of a set of points. The x and y coordinates are the and .
oz 2009-12-22