The basic idea of animation of a rigid body motion is the same as that of animation of a moving point discussed in Section 2 and 3. The only difference is that in the case of a rigid body motion the object to draw and erase is a three-dimensional shape.
Let us make an animation of a moving block as an example. This can be done based on the script developed in Section 6 for drawing a block shape in a general configuration.
First, in order to make the script concise let us define a function that returns patches data needed to draw a block shape by plot3d
as in Code 1.
function patches = calcBlock(r, R, Lx, Ly, Lz) // Return patches data of a block geometry // Vertices vertices_0 = [ 0, 0, 0; // #1 Lx, 0, 0; // #2 0, Ly, 0; // #3 0, 0, Lz; // #4 Lx, Ly, 0; // #5 0, Ly, Lz; // #6 Lx, 0, Lz; // #7 Lx, Ly, Lz]; // #8 vertices = transver(vertices_0, r, R); // Faces faces = [ 1, 2, 5, 3; // #1 1, 3, 6, 4; // #2 1, 4, 7, 2; // #3 4, 7, 8, 6; // #4 2, 5, 8, 7; // #5 3, 6, 8, 5]; // #6 // Patches patches = genpat(vertices, faces); endfunction
Using the calcBlock()
function in Code 1, we can rewrite the script developed in Section 6 for drawing a block shape in a general configuration concisely as in Code 2 below.
// make_block.sce clear; xdel(winsid()); exec('eulerXYZ.sci', -1); exec('transver.sci', -1); exec('genpat.sci', -1); exec('calcBlock.sci', -1); // Reference position r = [1; 1; 1]; // Reference orientation R = eulerXYZ(-%pi/3, 0, %pi/6); // Side lengths Lx = 0.15; Ly = 0.05; Lz = 0.30; // Patches patches = calcBlock(r, R, Lx, Ly, Lz); // Draw patches h_fig = figure; h_fig.background = 8; h_pat = plot3d(patches.x, patches.y, patches.z); h_pat.color_mode = 4; h_pat.foreground = 1; h_pat.hiddencolor = 4; // Axes settings xlabel("x"); ylabel("y"); zlabel("z"); h_axes = gca(); h_axes.isoview = "on"; h_axes.box = "off"; h_axes.rotation_angles = [63.5, -127]; h_axes.data_bounds = [0.8, 0.9, 0.8; 1.3, 1.4, 1.3]; xgrid;