Guest User

Untitled

a guest
Nov 17th, 2017
77
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.32 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <stdlib.h>
  3. #include "T3D.h"
  4. #define t 1
  5.  
  6. struct mat4x1
  7. {
  8. double Coord[4];
  9. struct mat4x1 *next;
  10. };
  11.  
  12. struct mat4x4
  13. {
  14. double Mat_transf[4][4];
  15. };
  16.  
  17. void Append(double x, double y, double z, double t, int qnt, Mat4x1 **head){
  18. Mat4x1 *temp = *head, *prev, *new;
  19. new = malloc(sizeof(Mat4x1));
  20. new -> Coord[0] = x;
  21. new -> Coord[1] = y;
  22. new -> Coord[2] = z;
  23. new -> Coord[3] = t;
  24. new -> qnt = qnt;
  25. while(temp != NULL){
  26. prev = temp;
  27. temp = temp -> next;
  28. }
  29. new -> next = prev -> next;
  30. prev -> next = new;
  31. }
  32.  
  33. void Cria(Mat4x1 *Obj, char* fName)
  34. {
  35. Mat 4x1 *buffer;
  36. int i, qnt;
  37. double x,y,z;
  38. FILE* arq;
  39.  
  40. buffer = malloc(sizeof(Mat4x1));
  41. arq = fopen(fName,"r");
  42.  
  43. if (arq == NULL) //Módulo de segurança
  44. return NULL;
  45.  
  46. fscanf(arq, "%d", &qnt); //numero de v[4] da matriz
  47.  
  48. //Criando a matriz
  49. while(qnt--){
  50. fscanf(arq, "%lf%lf%lf", &x,&y,&z);
  51. Append(x,y,z,t,qnt,&buffer);
  52. }
  53. fclose(arq);
  54. }
  55.  
  56. void Imprime(Mat4x1 *Obj, char* fName)
  57. {
  58. int i, qnt = 0;
  59. FILE *arq;
  60. Mat4x1 *temp;
  61.  
  62. temp = Obj;
  63. temp = temp -> next;
  64. while(temp != NULL){
  65. ++qnt;
  66. temp = temp -> next;
  67. }
  68.  
  69. arq = fopen(fName,"w");
  70.  
  71. fprintf(arq, "%d\n", qnt);
  72.  
  73. temp = Obj;
  74. temp = temp -> next;
  75. while(temp != NULL){
  76. fprintf(arq,"%.3lf %.3lf %.3lf\n", temp->Coord[0],temp->Coord[1],temp->Coord[2]);
  77. temp = temp -> next;
  78. }
  79. fclose(arq);
  80. }
Add Comment
Please, Sign In to add comment