my @tmpl = ( [0,0,0, 'A'], [1,0,0, 'B'], [2,0,0, 'B'], [3,0,0, 'B'], [4,0,0, 'B'], [5,0,0, 'A'] ); #### ... my $axis = [ 0, 0, 1 ]; # may be arbitary axis, always normalized my @ensemble; for my $id (0 .. 999) { my $angle = deg2rad(rand(360)); # rotate around arbitary # axis by .. degrees # make rotation matrix my $m = setrotmatrix($angle, $axis); # make new rigid body instance from template my $p = deepcopy_body( \@tmpl ); # apply rotation (matrix x vector) to rigid body rotate_body( $p, $m ); # apply some translation by a displacemnent vector translate_body( $p, [$dx, $dy, $dz)] ); # store the new body coordinates push @ensemble, $p; } ...