Advertisement
Guest User

Untitled

a guest
Mar 20th, 2019
61
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
text 1.17 KB | None | 0 0
  1. function [oSphere1,oSphere2] = elasticCollision(sphere1,sphere2)
  2. if not(isequal(size(sphere1),[1,5]) && isnumeric(sphere1) && (isequal(size(sphere2),[1,5]) || isequal(size(sphere2),[1,1])) && isnumeric(sphere2)) %error check
  3. error('Invalid input');
  4. end
  5. oSphere1 = sphere1; %everything else stays the same
  6. oSphere2 = sphere2;
  7. if isequal(size(sphere2),[1,1]) && (sphere2 == 0 || sphere2 == 1) %0/1 = crashes into left or right boundary
  8. oSphere1(4) == -sphere1(4);
  9. elseif isequal(size(sphere2),[1,1]) && (sphere2 == 2 || sphere2 == 3) %2/3 = crashes into top or bottom boundary
  10. oSphere1(5) == -sphere1(5);
  11. elseif isequal(size(sphere2),[1,5])
  12. theta = atan((sphere2(3) - sphere1(3))/(sphere2(2)-sphere1(2)));
  13. oSphere1(4) = ((sphere1(1)^3-sphere2(1)^3)*sphere1(4)+2*sphere2(1)^3*sphere2(4))/(sphere1(1)^3+sphere2(1)^3);
  14. oSphere1(5) = ((sphere1(1)^3-sphere2(1)^3)*sphere1(5)+2*sphere2(1)^3*sphere2(5))/(sphere1(1)^3+sphere2(1)^3);
  15. oSphere2(4) = ((sphere2(1)^3-sphere1(1)^3)*sphere2(4)+2*sphere1(1)^3*sphere1(4))/(sphere1(1)^3+sphere2(1)^3);
  16. oSphere2(5) = ((sphere2(1)^3-sphere1(1)^3)*sphere2(5)+2*sphere1(1)^3*sphere1(5))/(sphere1(1)^3+sphere2(1)^3);
  17. end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement