Professional Documents
Culture Documents
5
6
In CP2Contact, we need to draw the box that the particle is bouncing around
in. The question is, how can I do that in MATLAB? As a visualization task, the
only thing we can see are the edges and vertices of the box, so those become the
primary geometric descriptors of the box.
The first step is to input (or compute) the coordinates of the vertices of the box.
There are 8 vertices, which we will number 1, 2, 3, , 8 (because we will need
those numbers later). We can store the coordinates of the vertices in an array x
with each row containing the x, y, z coordinates of the 8 vertices, in order as
numbered
x1
x
x= 2
x8
y1
y2
y8
z1
z2
z8
8
7
4
3
MATLAB code
The array x has dimensions 8 by 3
The second step is, essentially, the act of tracing the edges from vertex to vertex
without lifting the pencil from the paper. It is not possible to do that without
retracing some of the lines, but all we need to do is give a list of the vertices in
order of visitation. One possible order is
for i = 1: N
box(i, : ) = x(ord (i ), : )
end
or
box = x(ord , : )
The last step is to simply plot the box. In MATLAB the command is
clear; clc;