function draw_book(R,d,rW,rL,rT,bookcolor) %Draw a book just like in 'Tossing a Book in the Air' example. Reference %orientation is eye(3,3) and reference position is origin. %R: 3x3 rotation matrix %d: 3x1 array which are vector components (position of the center of mass) rCM = d; e1 = R(:,1); e2 = R(:,2); e3 = R(:,3); %We need to animate 6 planes to form a cuboid. Track 8 material points of %one of the plane of the object: r1 = rCM + 0.5*rL*e1 + 0.5*rW*e2 + 0.5*rT*e3; r2 = rCM - 0.5*rL*e1 + 0.5*rW*e2 + 0.5*rT*e3; r3 = rCM - 0.5*rL*e1 - 0.5*rW*e2 + 0.5*rT*e3; r4 = rCM + 0.5*rL*e1 - 0.5*rW*e2 + 0.5*rT*e3; r5 = rCM + 0.5*rL*e1 + 0.5*rW*e2 - 0.5*rT*e3; r6 = rCM - 0.5*rL*e1 + 0.5*rW*e2 - 0.5*rT*e3; r7 = rCM - 0.5*rL*e1 - 0.5*rW*e2 - 0.5*rT*e3; r8 = rCM + 0.5*rL*e1 - 0.5*rW*e2 - 0.5*rT*e3; hold on; CM = line(rCM(1), rCM(2), rCM(3), 'Color', bookcolor, 'LineWidth', 3); %Plane 1, 2, 3, 4, 5, 6's vertices over time: vertices1_x = [r1(1,:); r2(1,:); r3(1,:); r4(1,:)]; vertices1_y = [r1(2,:); r2(2,:); r3(2,:); r4(2,:)]; vertices1_z = [r1(3,:); r2(3,:); r3(3,:); r4(3,:)]; surf_1 = patch(vertices1_x(:,1), vertices1_y(:,1), vertices1_z(:,1), bookcolor, 'FaceAlpha', 0.3); vertices2_x = [r5(1,:); r6(1,:); r7(1,:); r8(1,:)]; vertices2_y = [r5(2,:); r6(2,:); r7(2,:); r8(2,:)]; vertices2_z = [r5(3,:); r6(3,:); r7(3,:); r8(3,:)]; surf_2 = patch(vertices2_x(:,1), vertices2_y(:,1), vertices2_z(:,1), bookcolor, 'FaceAlpha', 0.3); vertices3_x = [r3(1,:); r4(1,:); r8(1,:); r7(1,:)]; vertices3_y = [r3(2,:); r4(2,:); r8(2,:); r7(2,:)]; vertices3_z = [r3(3,:); r4(3,:); r8(3,:); r7(3,:)]; surf_3 = patch(vertices3_x(:,1), vertices3_y(:,1), vertices3_z(:,1), bookcolor, 'FaceAlpha', 0.3); vertices4_x = [r1(1,:); r2(1,:); r6(1,:); r5(1,:)]; vertices4_y = [r1(2,:); r2(2,:); r6(2,:); r5(2,:)]; vertices4_z = [r1(3,:); r2(3,:); r6(3,:); r5(3,:)]; surf_4 = patch(vertices4_x(:,1), vertices4_y(:,1), vertices4_z(:,1), bookcolor, 'FaceAlpha', 0.3); vertices5_x = [r1(1,:); r4(1,:); r8(1,:); r5(1,:)]; vertices5_y = [r1(2,:); r4(2,:); r8(2,:); r5(2,:)]; vertices5_z = [r1(3,:); r4(3,:); r8(3,:); r5(3,:)]; surf_5 = patch(vertices5_x(:,1), vertices5_y(:,1), vertices5_z(:,1), bookcolor, 'FaceAlpha', 0.3); vertices6_x = [r2(1,:); r3(1,:); r7(1,:); r6(1,:)]; vertices6_y = [r2(2,:); r3(2,:); r7(2,:); r6(2,:)]; vertices6_z = [r2(3,:); r3(3,:); r7(3,:); r6(3,:)]; surf_6 = patch(vertices6_x(:,1), vertices6_y(:,1), vertices6_z(:,1), bookcolor, 'FaceAlpha', 0.3);