File Exchange

image thumbnail

Bouncing Smiley Face

version 1.2 (4.65 KB) by

Exaggerated and somewhat cartoonish simulation of the physics of a bouncing smiley face.

3 Downloads

Updated

View License

The laws for rotation are probably wrong (I made them up actually), but that's not what this file is about. Shown here is a very simple code that creates a nice animation, which can be quickly edited to suit anyone's needs.

The parameters are ball radius, gravity, initial velocity in the Y direction, initial velocity in the X direction, vertical speed conservation (%), horizontal speed conservation (%) and initial angular velocity.

Please note that the ball may stop moving at different locations for different trials, even with the same input parameters. This is due to the slight randomization of the deformations of the ball and the ground, which could lead to the ball getting "stuck" to the ground at times and stopping there. This is normal and deliberate.

Set the vertical speed conservation as a value larger than 100 (e.g. 130) for a small bonus ;)

Comments and Ratings (8)

Amelia

Amelia (view profile)

Yes, great program Husam!

David

David (view profile)

Great program.

NOUR

NOUR (view profile)

John D'Errico

John D'Errico (view profile)

The appropriate review would just be this.

8-)

Husam Aldahiyat

Wow, too easy. Thanks.

Kenneth Eaton

Kenneth Eaton (view profile)

One solution to the dependence on the Image Processing Toolbox... you could plot a square surface object, then texture map the smiley-face image onto it. Then you can simply rotate the surface object yourself, without a need for the IPT.

Husam Aldahiyat

Ah, sorry about that. Will send an update that brings notice to this. Also, you're to be mentioned as inspiration in the code. Forgot to include that in before.

As for getting around the problem, I don't think there's a simple way to do it, so anyone without the Image Processing Toolbox should comment out lines 278 and 282. The result is missing out on the smiley face bit altogether.

John D'Errico

John D'Errico (view profile)

Looks very nice. I was disappointed that no mention was made of the requirements for use. NO image processing toolbox, no go.

??? Undefined function or method 'imrotate' for input arguments of type 'uint8'.

Error in ==> bb2>go at 282
iii=image(imrotate(uint8(flipud(am)),ll,'bilinear','crop'),'xdata',[ccc2-r/2,ccc2+r/2],'ydata',[ccc-r/2
ccc+r/2]);

??? Error while evaluating uicontrol Callback

Updates

1.2

Code now works on systems without the Image Processing Toolbox.

1.1

Fixed eccentricity error, horizontal conservation error.

MATLAB Release
MATLAB 7.4 (R2007a)
Acknowledgements

Inspired by: Bouncing Ball Physics

Download apps, toolboxes, and other File Exchange content using Add-On Explorer in MATLAB.

» Watch video