Advertisement
marwanpro

revision final

Jan 11th, 2017
417
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 3.46 KB | None | 0 0
  1. f(x) == f(a)(1-t)+f(b)*t
  2. t == (x-a)/(b-a)
  3.  
  4.  
  5. // **************************************************
  6. // ***** TD Question 1
  7. // **************************************************
  8.  
  9. struct Complex
  10. {
  11. float x,y;
  12. };
  13.  
  14.  
  15. // **************************************************
  16. // ***** TD Question 2
  17. // **************************************************
  18.  
  19. Complex make_complex(float r, float i)
  20. {
  21. Complex c;
  22. c.x = r;
  23. c.y = i;
  24. return c;
  25. }
  26.  
  27. Complex make_complex_expo(float r, float theta)
  28. {
  29. Complex c;
  30. c.x = r*cos(theta);
  31. c.y = r*sin(theta);
  32. return c;
  33. }
  34.  
  35.  
  36. // **************************************************
  37. // ***** TD Question 3
  38. // **************************************************
  39.  
  40. Complex operator+(Complex a, Complex b)
  41. {
  42. Complex c = { a.x+b.x, a.y+b.y };
  43. return c;
  44. }
  45.  
  46. Complex operator-(Complex a, Complex b)
  47. {
  48. Complex c = { a.x-b.x, a.y-b.y };
  49. return c;
  50. }
  51.  
  52. Complex translate(Complex p, float dx, float dy)
  53. {
  54. return p + make_complex(dx,dy);
  55. }
  56.  
  57.  
  58. // **************************************************
  59. // ***** TD Question 4
  60. // **************************************************
  61. //A( 1,-1) = 1 -1.i = 1-i
  62. //B( 0, 1) = 0 +1.i = i
  63. //C(-1,-1) = -1 -1.i = -1-i
  64. //
  65. //lambda=2
  66. //A' = lambda * A = 2*(1-i) = 2-2i = (2,-2)
  67. //B' = lambda * B = 2*i = (0, 2)
  68. //C' = lambda * C = 2*(-1-i) = -2-2i = (-2,-2)
  69. // ==> faire le dessin
  70. //
  71. //lambda=0.5
  72. //A' = lambda * A = (0.5, -0.5)
  73. //B' = lambda * B = (0, 0.5)
  74. //C' = lambda * C = (-0.5, -0.5)
  75. // ==> faire le dessin
  76. //
  77. // Multiplication d'un complexe par un réel = une homothétie de centre O = approche (lambda<1) ou éloigne (lambda>1) le point
  78.  
  79.  
  80.  
  81. // **************************************************
  82. // ***** TD Question 5
  83. // **************************************************
  84.  
  85. Complex operator*(float a, Complex b)
  86. {
  87. Complex c = { a*b.x, a*b.y };
  88. return c;
  89. }
  90. Complex operator/(Complex b, float d)
  91. {
  92. Complex c = { b.x/d, b.y/d };
  93. return c;
  94. }
  95.  
  96. Complex scale(Complex p, float cx, float cy, float sc)
  97. {
  98. Complex tr = make_complex( cx, cy);
  99. return (sc*(p-tr))+tr;
  100. }
  101.  
  102.  
  103.  
  104. // **************************************************
  105. // ***** TD Question 6 et 7
  106. // **************************************************
  107.  
  108. // A( 1,-1) = 1 -1.i = 1-i
  109. // B( 0, 1) = 0 +1.i = i
  110. // C(-1,-1) = -1 -1.i = -1-i
  111. //
  112. // r = e^(i.theta) avec theta = PI/2 donc une rotation de 90°
  113. // r = cos(PI/2) + i.sin(PI/2) = 0+i = i
  114. //A' = r * A = i*(1-i) = 1+i = (1,1)
  115. //B' = r * B = i*i = -1 = (-1, 0)
  116. //C' = r * C = i*(-1-i) = 1-i = (1,-1)
  117. // ==> faire le dessin
  118. // ==> rotation de 90°
  119. //
  120. // ==> ca marche avec n'importe quel theta
  121. // par exemple avec theta=0 r= cos(0)+i.sin(0) = 1 => identite
  122. // par exemple avec theta=PI r= cos(PI)+i.sin(PI) = -1
  123. //
  124. // Multiplié un complexe par un complexe imaginaire pure (r=e^(i.theta) ==> rotation de theta°
  125.  
  126.  
  127.  
  128. // **************************************************
  129. // ***** TD Question 8
  130. // **************************************************
  131.  
  132. float to_degree(float rad)
  133. {
  134. return 180.f * rad/M_PI;
  135. }
  136.  
  137. float to_rad(float deg)
  138. {
  139. return M_PI*deg/180.f;
  140. }
  141.  
  142. Complex operator*(Complex a, Complex b)
  143. {
  144. Complex c = make_complex( a.x*b.x - a.y*b.y, a.x*b.y + a.y*b.x );
  145. return c;
  146. }
  147.  
  148. Complex rotate(Complex p, float cx, float cy, float theta_deg)
  149. {
  150. Complex rot = make_complex_expo( 1, to_rad(theta_deg));
  151. Complex tr = make_complex( cx, cy);
  152. return ((p-tr)*rot)+tr;
  153. }
  154.  
  155.  
  156. float norm(Complex c)
  157. {
  158. return sqrt( c.x*c.x + c.y*c.y);
  159. }
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement