Massassi Forums Logo

This is the static archive of the Massassi Forums. The forums are closed indefinitely. Thanks for all the memories!

You can also download Super Old Archived Message Boards from when Massassi first started.

"View" counts are as of the day the forums were archived, and will no longer increase.

ForumsDiscussion Forum → When coding FINALLY works!
When coding FINALLY works!
2004-12-01, 11:47 AM #1
WOOWOO!

Just felt the need to bounce around and be happy for a change! I've cracked the first part of my DEM problem for my final year project using Matlab. I can model a bouncing ball dropped from a height coming to rest (1 dimensionally for the moment).

It's only taken me about 2 weeks and a complete re-write... :o

But WOOOOWOOOOOOOOO!
2004-12-01, 11:51 AM #2
It took you two weeks to do that? I guess I'm not familiar with Matlab. Did you write the gui?
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2004-12-01, 11:52 AM #3
Woohoo! Congrats! :D
2004-12-01, 12:04 PM #4
Quote:
Originally posted by Freelancer
It took you two weeks to do that? I guess I'm not familiar with Matlab. Did you write the gui?


Nope, but I'm self taught in Matlab, using a mathematical method not in common use, and have nobody to turn to for aid!

In the end, it took me re-writing the whole thing from a different angle to iron out the major bugs.

Code:
%newbounce - a new attempt to model the 'bouncing ball' problem'
%It still has some kinks, but is FAR more well behaved than the 
%previous version - I've moved the contact detection out of the
%original loop. I think this made it easier to see what was
%happening - and finally got the coefficient of restitution to
%take energy OUT of the system.

%Initialisation - quick version - limiting some variables for test speed
e = input('Enter e ::  ');
y_init = input('Starting height? ::  ');
k = input('Spring constant (recommend about 100)? ::  ');
step = 1/2000;
N = 30;
r = 0.2;
deltamax = r/100;
g = 9.81;
m = 1;

y = y_init;
y_dot =0;

delta = y-r;

gravity_force = (-m*g);
contact_force = 0;	%assuming we start off the ground
contact = 0 		%contact detection variable/trigger

Results = zeros(1,(N*1/step));
Delta = zeros(1,(N*1/step));
Y_dot = zeros(1,(N*1/step));
Contact = zeros(1,(N*1/step));
Contact_force = zeros(1,(N*1/step));

disp('Press a key to begin');

for n = 0:step:N

	%Contact detection
	if y <= r
		contact = 1;
	elseif y > r 
		contact = 0;
	end

	%No contact - falling under gravity	
	if contact == 0
		y_dot = y_dot + (gravity_force * (step/m));
		y = y + (step * y_dot);
		contact_force = 0;
		Results(round(n/step + 1)) = y-r;
		
	%Contact - impact and restitution
	elseif contact == 1
		disp('Boing');
			
			if y_dot <= 0					%This should produce
				k_live = k;					%a kind of hysteresis
			elseif y_dot > 0				%using the coefficient
				k_live = (k * (e^2));		%of resititution
			end
			
		
		contact_force = k_live * delta;
		y_dot = y_dot + (contact_force * (step/m));
		y = y + (y_dot * step);
		Results(round(n/step + 1)) = y-r;
	end
	Delta(round(n/step + 1)) = delta;
	Y_dot(round(n/step + 1)) = y_dot;
	Contact(round(n/step + 1)) = contact;
	Contact_force(round(n/step + 1)) = contact_force;
end
hold on
plot(Results);


It looks something like that.
2004-12-01, 2:22 PM #5
I wrote something very similar, except you can control most things with it.


http://www.phoenixcradle.com/bur/projectile.html

Took me two days.

By the way, I made up the spring constant too. I decided it wasn't worth doing a rackload of calculations.

[Note, the styles are only fully correct in IE. In Firefox, you'll have to imagine where the floor is.
2004-12-01, 2:24 PM #6
I want to go back to school so bad now... damn you I have to wait another month before I can learn more about C++... damn you for sparking my interest again... damn you.
2004-12-01, 2:33 PM #7
Quote:
Originally posted by Hebedee
I wrote something very similar, except you can control most things with it.


http://www.phoenixcradle.com/bur/projectile.html

Took me two days.

By the way, I made up the spring constant too. I decided it wasn't worth doing a rackload of calculations.

[Note, the styles are only fully correct in IE. In Firefox, you'll have to imagine where the floor is.


Coolio!

The thing is with mine, this is quite literally the tip of the iceberg...

Next job is defining walls (like yours), but then surfaces with corners, making the particles spin, adding global friction, and adding hundreds of interacting particles and coming up with an efficient collision detection system!!

Nightmare, but at least I can stay at home instad of doing a practical lab project...
2004-12-01, 2:45 PM #8
And if that took you two weeks, then we can expect this by... what? 2010? :p
"it is time to get a credit card to complete my financial independance" — Tibby, Aug. 2009
2004-12-01, 3:17 PM #9
Now implement a gravity gun.
Stuff
2004-12-01, 3:38 PM #10
Quote:
Originally posted by MechWarrior
I want to go back to school so bad now... damn you I have to wait another month before I can learn more about C++... damn you for sparking my interest again... damn you.


[url]www.google.com[/url] has good tutorials, I hear. If you want to learn something, you can always teach yourself.
D E A T H
2004-12-01, 3:46 PM #11
Yeah, someone with an actual knowledge of physics is probably far more capable than I am at making a good looking physics simulation.
2004-12-01, 3:51 PM #12
Ask Mort--he knows physics. I would say I could help, but I've had a semester of it--I'm a n00b.
D E A T H
2004-12-01, 4:01 PM #13
Quote:
Originally posted by MechWarrior
I want to go back to school so bad now... damn you I have to wait another month before I can learn more about C++... damn you for sparking my interest again... damn you.


Uh . . . how bout' . . . teaching yourself.
2004-12-01, 4:44 PM #14
I did! :p

The reason is took so long was (1) the week long party I've been on, and (2) debugging issues and (3) I've never undertaken a solo programming project before.

Oh, and google for Discrete Element Modelling, and you'll see what I'm up against!!

AAAAAAAAAAAAAAAAAAAAAAAAAA!!!

↑ Up to the top!