Advertisement
Wojtekd

Animacja

Apr 14th, 2017
95
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
C++ 1.16 KB | None | 0 0
  1. r = 0.1;
  2. x0 = 0;
  3. y0 = 0;
  4. z0 = powierzchnia[x0, y0];
  5. listaKatow = Table[RandomReal[{0, 2 Pi}], {i, 100}];
  6. powierzchnia[x_, y_] = 2 x + 3 y^2;
  7. f[x_, y_, xp_, yp_,
  8.    zp_] = (x - xp)^2 + (y - yp)^2 + (2 x + 3 y^2 - zp)^2 - r^2;
  9.  
  10. i = 1;
  11. points = {};
  12.  
  13. SeedRandom[1234];
  14.  
  15. While[i <= 100, alfa = listaKatow[[i]];
  16.  Result =
  17.   Solve[{x, y} \[Element]
  18.      InfiniteLine[{{x0, y0}, {x0 + Cos[alfa], y0 + Sin[alfa]}}] &&
  19.     f[x, y, x0, y0, z0] == 0, {x, y}];
  20.  
  21.  xPunktu = Result[[1, 1, 2]];
  22.  yPunktu = Result[[1, 2, 2]];
  23.  zPunktu = powierzchnia[xPunktu, yPunktu];
  24.  pointCurrent = {xPunktu, yPunktu, zPunktu};
  25.  
  26.  xPunktu2 = Result[[2, 1, 2]];
  27.  yPunktu2 = Result[[2, 2, 2]];
  28.  zPunktu2 = powierzchnia[xPunktu2, yPunktu2];
  29.  
  30.  pointCurrent =
  31.   RandomChoice[{{xPunktu, yPunktu, zPunktu}, {xPunktu2, yPunktu2,
  32.      zPunktu2}}];
  33.  
  34.  points = Append[points, pointCurrent];
  35.  x0 = pointCurrent[[1]];
  36.  y0 = pointCurrent[[2]];
  37.  z0 = pointCurrent[[3]];
  38.  
  39.  i++;]
  40.  
  41. Animate[Show[
  42.   Plot3D[{2 x + 3 y^2}, {x, -1, 1}, {y, -1, 1},
  43.    BoxRatios -> {1, 1, 1}],
  44.   Graphics3D[{Green, PointSize[.02], Line[points[[;; it]]],
  45.     Point[points[[it]]]}]], {it, 1, 100, 1}]
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement