Advertisement
Not a member of Pastebin yet?
Sign Up,
it unlocks many cool features!
- function [oSphere1,oSphere2] = elasticCollision(sphere1,sphere2)
- if not(isequal(size(sphere1),[1,5]) && isnumeric(sphere1) && (isequal(size(sphere2),[1,5]) || isequal(size(sphere2),[1,1])) && isnumeric(sphere2)) %error check
- error('Invalid input');
- end
- oSphere1 = sphere1; %everything else stays the same
- oSphere2 = sphere2;
- if isequal(size(sphere2),[1,1]) && (sphere2 == 0 || sphere2 == 1) %0/1 = crashes into left or right boundary
- oSphere1(4) == -sphere1(4);
- elseif isequal(size(sphere2),[1,1]) && (sphere2 == 2 || sphere2 == 3) %2/3 = crashes into top or bottom boundary
- oSphere1(5) == -sphere1(5);
- elseif isequal(size(sphere2),[1,5])
- theta = atan((sphere2(3) - sphere1(3))/(sphere2(2)-sphere1(2)));
- oSphere1(4) = ((sphere1(1)^3-sphere2(1)^3)*sphere1(4)+2*sphere2(1)^3*sphere2(4))/(sphere1(1)^3+sphere2(1)^3);
- oSphere1(5) = ((sphere1(1)^3-sphere2(1)^3)*sphere1(5)+2*sphere2(1)^3*sphere2(5))/(sphere1(1)^3+sphere2(1)^3);
- oSphere2(4) = ((sphere2(1)^3-sphere1(1)^3)*sphere2(4)+2*sphere1(1)^3*sphere1(4))/(sphere1(1)^3+sphere2(1)^3);
- oSphere2(5) = ((sphere2(1)^3-sphere1(1)^3)*sphere2(5)+2*sphere1(1)^3*sphere1(5))/(sphere1(1)^3+sphere2(1)^3);
- end
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement