Advertisement
Guest User

Cam Gear shapes for parametric curves

a guest
Apr 2nd, 2018
458
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
MatLab 1.72 KB | None | 0 0
  1. function [M] = erraticSpin(R,n,xo,yo,f,a,b)
  2. %erraticSpin - Calculates the shape of cams required to form a parametric
  3. %curve.
  4. %%
  5. %   R = Radius of center disk
  6. %   n = # line divisions
  7. %   xo/yo = origin of function
  8. %   f = function
  9. %   a/b vectors which describe positions of cams
  10. %%
  11. figure('rend','painters','pos',[10 10 900 900])
  12. myVideo = VideoWriter('Para7.avi');
  13. myVideo.Quality = 100;
  14. myVideo.FrameRate = 60;
  15. open(myVideo);
  16. hold on;
  17. grid on;
  18. axis equal;
  19.  
  20. circle=linspace(0,8*pi,n); %change this range to do more loops
  21. T=reshape(circle,[n,1]);
  22. numcams=size(a);
  23. vals= f(T);
  24. X = xo+vals(:,1);
  25. Y = yo+vals(:,2);
  26. %Now we have X and Y coords of the center of the disk.
  27.  
  28. for i=1:n
  29.     for j=1:numcams(2)
  30.         THETA(i,j) = atan((Y(i)-b(j))/(X(i)-a(j)));
  31.         %
  32.         if THETA(i,j)<0
  33.             THETA(i,j) = pi + atan((Y(i)-b(j))/(X(i)-a(j)));
  34.         end
  35.         x(i,j) = (X(i)-R*cos(THETA(i,j)));
  36.         y(i,j) = (Y(i)-R*sin(THETA(i,j)));
  37.         r(i,j) = sqrt((x(i,j)-a(j))^2+(y(i,j)-b(j))^2);
  38.     end
  39. end
  40.  
  41. for i=1:n
  42.     hold on;grid on;axis square;
  43.     xlim([-20,20]);
  44.     ylim([-15,25]);
  45.     plot(X,Y,'r');%plot of the function F(T)
  46.     plot(a,b,'ro');%cam centers
  47.     plot(X(i)+R*cos(T),Y(i)+R*sin(T),'b'); %plot the disk
  48.     for j=1:numcams(2)
  49.         plot([a(j),x(i,j)],[b(j),y(i,j)],'g');
  50.         %Plots a line going from the cam to the closest point on the disk
  51.         plot( a(j)+r(:,j).*cos( -T(i) + T + THETA(i,j) ) , b(j)+r(:,j).*sin(-T(i)+T+THETA(i,j)),'k');
  52.         %Angle is an increment of 2pi/n + initial angle THETA + the element
  53.         %by element addition of T
  54.     end
  55.     M(i) = getframe;
  56.     clf;
  57. end
  58. %writeVideo(myVideo,M);
  59. close(myVideo);
  60. %movie(M,30,60);
  61.  
  62. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement