Sie sind auf Seite 1von 2

WRITE UP

Zhiming Zeng (Kate)


CSC 173 C Week 2
1. OVERVIEW
The program creates a tetrahedron structure, containing face, vertex and edge
(FEV) structures. This structure can be printed out in a file. The program can
also read the file and store the file into a tetrahedron structure.
2. DESIGN OF DATA STRUCTURE
My design is the same exact design used by the professor.
The polyhedron consists of a circular list of faces. They are all linked together so
one face can lead to another face till all the faces are traversed.
The face is linked to a circular list of edges, each of which contains data of their
vertices.
So, all the FEV types are linked together in this manner:
1. A FACE has:
an integer type code for FACE.
a face serial number unique to this face.
a pointer to the first of a circular list of EDGEs in order
counterclockwise around the face, as seen "from above".
a pointer to the next face on the circular list of FACEs that define a
polyhedron.
2. An EDGE has:
an integer type code for EDGE.
an edge serial number unique to this edge.
a tail ("from") VERTEX.
a head ("to") VERTEX.
a pointer to the "next EDGE" in a circular edge list (the edges
bounding a face).
3. a VERTEX has:
an integer type code for VERTEX.
a vertex serial number unique to this vertex.
a column 3-vector (a 3x1 matrix) giving (X,Y,Z) spatial location
coordinates.

3. IMPLEMENTATION
3.1 Choice of Array Size and FEV Type Number
I defined the size of all arrays (i.e. constant SIZE) to 50 so that the program can
handle 50 or less edges, faces and vertices each. The size of the array will not
result in null access error because all for loops will stop looping once the array[i] !
= NULL.
Also, size of the array (of pointers) does not determine how much space is
actually taken because memory is allocated to the pointer elements only when the
FEV structure exists. So an array with size 1000 will not result in 1000 memory
units taken up.
I defined the constants FACE, EDGE, VERTEX and MATRIX with numbers (i.e.
1111, 2222, 3333, 4444 respectively) larger than array size 50 so that the program
will not mistake serial numbers with the numbers that define the type (i.e.
fev_type).
I have p_structures (printable structures) that contain integer and double fields
and non-printable structures that contain pointers to make it easier to convert
between printable and non-printable structures.
3.2 Structure to File
I get the FEV structure from new_tetrahedron(), which are FEV p_structures
that contain integer or double fields instead of pointers. Then I converted all the
information into FEV structures that contain pointers.
I use a depth-first search method to fill up all the structure. The head face will
trigger the traversal.
Then I go through each array to find out how many FEV there are. Using these
counts, I use for loops to print the FEV into pgp.data.
3.3 File to Structure
I parsed the file and stored the information in printable structures. Then I
convert the structures to non-printable structure so that the structures are linked
together through pointers.
4. BONUS

My file_to_struct() method reads through the input file once, instead of


twice, making the code more time efficient.
My print methods in fev.c contain error-handling methods to handle null
arguments.

Das könnte Ihnen auch gefallen