Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
73
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 2.07 KB | None | 0 0
  1. #include <stdio.h>
  2. #include <graphics.h>
  3. #include <stdlib.h>
  4. #include <math.h>
  5. #define pi 3.14;
  6. //elice simpla
  7. float x1,x2,yy1,yy2;
  8. float alfa=3.1415/8;
  9. int xemax,yemax;
  10.  
  11. int xe(float x)
  12. // normalizarea coocdonatei x
  13. {return((int) floor((x-x1)/(x2-x1)*xemax));}
  14.  
  15. int ye(float y)
  16. // normalizarea coocdonatei y
  17. {return((int) floor((yy2-y)/(yy2-yy1)*yemax));}
  18.  
  19. int ze(float z)
  20. // normalizarea coordonatei z
  21. {return((int) floor((yy2-z)/(yy2-yy1)*yemax));}
  22.  
  23. void putpixel3D(float x, float y, float z, int culoare)
  24. {
  25. putpixel(xe(x-y*cos(alfa)),ze(z-y*sin(alfa)),culoare);
  26. }
  27. void line3D(float x0, float y0, float z0, float x, float y, float z)
  28. {
  29. line(xe(x0-y0*cos(alfa)),ze(z0-y0*sin(alfa)),xe(x-y*cos(alfa)),ze(z-y*sin(alfa)));
  30. }
  31.  
  32. void axe()
  33. {
  34. setcolor(11);
  35. outtextxy(xe(0)-15,ze(0)-15,"O");
  36. outtextxy(xe(x2)-20,ze(0)-20,"x");
  37. outtextxy(xe(x2)-6,ze(0)-7,">");
  38. outtextxy(xe(0)+15,ze(yy2)+5,"z");
  39. outtextxy(xe(0)-1,ze(yy2)+1,"^");
  40. outtextxy(xe(x1*cos(alfa)),ze(x1*sin(alfa)),"y");
  41. line3D(0,0,0,x2,0,0);
  42. line3D(0,0,0,0,x2,0);
  43. line3D(0,0,0,0,0,yy2);
  44. }
  45.  
  46.  
  47.  
  48. void grafic()
  49. {
  50. int i,j,N=4000;
  51. float t,h,beta=3.1415/36;
  52. float x[5000],y[5000],z[5000];
  53. float pie=3.1415;
  54. float xaux,zaux;
  55. t=0;
  56. h=pie/600;
  57. for(i=0;i<N;i++)
  58. {
  59. x[i]=0.2*t*cos(3*t);
  60. y[i]=0.2*t*sin(3*t);
  61. z[i]=0.4*t;
  62. t+=h;
  63. }
  64. for(j=0;j<15;j++)
  65. {
  66. for(i=0;i<N;i++)
  67. putpixel3D(x[i],y[i],z[i],14);
  68. getch();
  69. for(i=0;i<N;i++)
  70. putpixel3D(x[i],y[i],z[i],0);
  71. for(i=0;i<N;i++)
  72. {//rotatie in raport cu axa Y
  73. xaux=x[i]*cos(beta)+z[i]*sin(beta);
  74. zaux=-x[i]*cos(beta)+z[i]*cos(beta);
  75. x[i]=xaux;
  76. z[i]=zaux;
  77. }
  78. }
  79. }
  80. int main()
  81. {
  82. printf("Limitele domeniului orizontal:\n");
  83. printf("x1="); scanf("%f",&x1);
  84. printf("x2="); scanf("%f",&x2);
  85. yy1=x1;
  86. yy2=x2;
  87. initwindow(800,800, "Elice simpla",200,200);
  88. xemax=getmaxx(); yemax=getmaxy();
  89. axe();
  90. setcolor(YELLOW);
  91. grafic();
  92. getch(); getch();
  93. closegraph();
  94. return 0;
  95. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement