Advertisement
fuzzybluerain

Pendulum Bot Circle Simulator

Nov 8th, 2021
261
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.00 KB | None | 0 0
  1. %% Circle Coverage Simulator
  2. % Claire Fredriksson - @fuzzybluerain
  3. % inspired by @pendulum_bot
  4.  
  5. % setting initial positions of the circles
  6. function circles = circlecoverage(x1init,y1init,x2init,y2init)
  7.  
  8. % evaluating length of the pendulums - they're the square of what they need
  9. % to be so that the calculations are easier in later portions of the
  10. % program
  11. length1 = (x1init^2)+(y1init^2);
  12. length2 = ((x2init-x1init)^2)+((y2init-y1init)^2);
  13.  
  14. % giving us 360 points for each given angle - could do more
  15. angles = linspace(0, 2*pi, 360);
  16.  
  17. x1 = length1 * cos(angles);
  18. y1 = length1 * sin(angles);
  19.  
  20. for k = 1:360
  21.     % running the same process at 360 equidistant points along the inner
  22.     % circle, so that we can generate the resultant circles for each point
  23.     x2 = length2 * cos(angles) + (length1 * cos(angles(k)));
  24.     y2 = length2 * sin(angles) + (length1 * sin(angles(k)));
  25.     plot(x2, y2, 'b-', 'LineWidth', 0.5);
  26.     hold on;
  27. end
  28.  
  29. plot(x1, y1, 'r-', 'LineWidth', 4);
  30. hold on;
  31. axis equal;
  32. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement