Writeup 4.3 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167
  1. TITLE
  2. C Week 2 Project
  3. Esty (Katherine) Thomas
  4. Goal:
  5. The problem in this project was to address the problem that
  6. a data structure full of pointers can't meaningfully be
  7. written to disk and then reconstructed with any guarantee
  8. that each pointer will still refer to the same object. The
  9. specific type of data used was the components of polyhedrons:
  10. faces, edges, and vertices. Each face contains a pointer to
  11. another face and an edge, and each edge contains pointers to two
  12. vertices and another edge.
  13. The general strategy suggested, the one that I took, was to
  14. create 'printable' versions of the face & edge structs (as the
  15. vertices have no pointers), stick them in arrays, and replace
  16. the pointers with array indices.
  17. Methods:
  18. Pointerly edges and faces, and vertices, are implemented as in the
  19. provided code, except instead of a name they have an 'id', which is
  20. incremented with each new face, edge, or vertex (type-specific).
  21. Matrices are mostly implemented as in the provided code, with additions
  22. and modifications from my Week 1 project (but no radical changes).
  23. "Printable" edges and faces are implemented as suggested, with array
  24. indices standing in for pointers. The normal vector for a face is not
  25. calculated; a (0,0,0) vector stands in as default.
  26. When a new printable edge or face is created, and when a new vertex is
  27. created, it is added to an array of its type at the index of its ID number.
  28. These arrays are initialized at 50, as suggested in the assignment.
  29. As previously implied, the pointer fields of the edge and face structs are
  30. replaced by the ID number of the struct pointed to, in the printable version.
  31. The edge and face creation routines are recursive, creating new edges and faces
  32. as needed, checking against the master arrays. These routines do not touch the
  33. vertices, since those are already in their array and are presumed to not change.
  34. The routine which prints everything to a file ('printificate") is iterative,
  35. printing first all the faces and then all the edges. Matrices and vertices are
  36. printed inside the descriptions of the face or edge to which they belong.
  37. My test program creates four vertices describing a quadrilateral, the edges
  38. connecting them, and the face formed by the edges. It calls printificate on this
  39. 2-D figure, which works as desired. It then attempts to call my reconstruct-from-file
  40. function ('readificate') on the output file, which completely fails, because my
  41. understanding of fscanf is evidently insufficient, as is my understanding of what
  42. is going wrong with the program. This lack of understanding means that readificate
  43. is a horribly tangled mess of code, in addition to not working. It is very much non-modular
  44. and generally inferior in every way.
  45. TRANSCRIPT:
  46. esty-thomass-macbook:173C2 esty$ make
  47. gcc -c -g FEV.c
  48. gcc -o runmytest -g mytest.o matrix.o FEV.o
  49. esty-thomass-macbook:173C2 esty$ ./runmytest
  50. Formatting error (matrix, face)
  51. CONTENTS OF OUTTEST:
  52. VERTICES: 4
  53. EDGES: 4
  54. FACES: 1
  55. FACE: Type: 10, ID: 0
  56. MATRIX: Normal Direction Type: 13 , Dims 1, 3
  57. 0.00 0.00 0.00
  58. ~
  59. Next Edge: 0.
  60. Next Face: -1.
  61. ~~~~
  62. EDGE: Type: 11, ID: 0
  63. MATRIX: Edge Direction Type: 13 , Dims 3, 1
  64. 3.00
  65. 0.00
  66. 0.00
  67. ~
  68. VERTEX: From Vertex Type: 12 , ID: 0
  69. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  70. 4.00
  71. 0.00
  72. 0.00
  73. ~
  74. ~~
  75. VERTEX: To Vertex Type: 12 , ID: 1
  76. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  77. 1.00
  78. 0.00
  79. 0.00
  80. ~
  81. ~~
  82. Next Edge: 1.
  83. ~~~
  84. EDGE: Type: 11, ID: 1
  85. MATRIX: Edge Direction Type: 13 , Dims 3, 1
  86. 0.00
  87. -1.00
  88. 0.00
  89. ~
  90. VERTEX: From Vertex Type: 12 , ID: 1
  91. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  92. 1.00
  93. 0.00
  94. 0.00
  95. ~
  96. ~~
  97. VERTEX: To Vertex Type: 12 , ID: 2
  98. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  99. 1.00
  100. 1.00
  101. 0.00
  102. ~
  103. ~~
  104. Next Edge: 2.
  105. ~~~
  106. EDGE: Type: 11, ID: 2
  107. MATRIX: Edge Direction Type: 13 , Dims 3, 1
  108. 1.00
  109. 0.00
  110. 0.00
  111. ~
  112. VERTEX: From Vertex Type: 12 , ID: 2
  113. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  114. 1.00
  115. 1.00
  116. 0.00
  117. ~
  118. ~~
  119. VERTEX: To Vertex Type: 12 , ID: 3
  120. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  121. 0.00
  122. 1.00
  123. 0.00
  124. ~
  125. ~~
  126. Next Edge: 3.
  127. ~~~
  128. EDGE: Type: 11, ID: 3
  129. MATRIX: Edge Direction Type: 13 , Dims 3, 1
  130. -4.00
  131. 1.00
  132. 0.00
  133. ~
  134. VERTEX: From Vertex Type: 12 , ID: 3
  135. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  136. 0.00
  137. 1.00
  138. 0.00
  139. ~
  140. ~~
  141. VERTEX: To Vertex Type: 12 , ID: 0
  142. MATRIX: Vertex Coords Type: 13 , Dims 3, 1
  143. 4.00
  144. 0.00
  145. 0.00
  146. ~
  147. ~~
  148. Next Edge: 0.
  149. ~~~