PDA

Click to See Complete Forum and Search --> : Brain Food?

ironmallet
03-27-2002, 02:26 AM
Have any of you flashMathMasters out there discovered sims that cover inelastic collisions? I've been working on a gravity sim where the objects collide and stick, and I'd love to here what this forum's elite minds have to post on the subject.

ironmallet
03-27-2002, 01:59 PM
When two particles collide(overlap) the sim will get rid of one, add the two masses together, figure out its new radius and send the new particle on its way with a new vx and vy.

First it has to figure out where this new particle should start. x1,y1,x2,y2, are the positions upon overlap. m1 and m2 are the masses.

---------
first particle:
x1,y1,m1

second particle:
x2,y2,m2

resulting particle's starting position (x3,y3):
x3=(x2*m2+x1*m1)/(m1+m2)
y3=(y2*m2+y1*m1)/(m1+m2)
m3=m1+m2

resultant particle speeds (vx3,vy3):
vx3*m3=vx1*m1+vx2*m2
vy3*m3=vy1*m1+vy2*m2

so...

vx3=(vx1*m1+vx2*m2)/m3
vy3=(vy1*m1+vy2*m2)/m3
-------------
this is all well and good but I can't think of an efficient way to manage the array when particles get absorbed. Any ideas?
--------------

bit-101
03-28-2002, 05:43 PM
don't forget torque/rotation. that's gotta come into play too. i've been doing some pretty fun stuff with elasticity and started to add this factor into it.
your idea is cool. a new direction to explore.

ironmallet
04-06-2002, 02:17 AM
http://www.ironmallet.com/flashkit/accrete2.htm

bit thanks for giving me the tools to make this work, still could play with the parameters a bit (of course)

I can't get it to load into an empty movie clip, the way I'm going to on my home page...

it, like the accrete program, borrows heavily from you.

it has to do with the _root references I'm sure, but I've tried alot of different things to no avail...

you wouldn't want to look at this, esp the ******** parts?
i really don't understand those bits at all!
anyway, thanks again, i've been after this since before I found flash. go bit-101 go.

p.s. the trampoline is killer.

init();
_root.onEnterFrame = main; <*********
function init() {
damp = .99;
max = 30;
grav = 1;
bounce = -.99;
b = new Array();
for (i=0; i<max; i++) {
attachMovie("ball", "b"+i, i);
var ball = b[i]=_root["b"+i]; <********
ball._x = Math.random()*500+20;
ball._y = Math.random()*360+20;
ball.vx = Math.random()*20-10;
ball.vy = Math.random()*10-5;
ball.m = ball._width=ball._height=Math.random()*15+5;
ball.m*=3;

}
}
function main() {
for (i=0; i<b.length; i++) {
var ball = b[i];

ball.vx *= damp;

bit-101
04-06-2002, 09:54 AM
hey, that is way cool! why didn't i think of that??? it makes like a black hole eventually, huh? i just don't get the scaling factor. it gets bigger, then smaller, then starts going up and down.

as far as your paths, you probably want to change most of the _root's to this's if you are going to be loading it into another movie. try that. you just have to kind of learn to visualize the different levels of the movie.

ironmallet
04-07-2002, 03:59 AM
okay it works in an empty movie clip,

can't thank you enough.

it's on april 5th.

btw I changed the code for attraction direction.

var total = Math.abs(dy)+Math.abs(dx)
var ddx = (force*dx)/total;
var ddy = (force*dy)/total;

it just parcels out the force by ratio instead of using trig, possibly faster...but the abs might slow it down who knows...

hey bit, do some more flash mx specific stuff, the green following ball is sweet....

ironmallet
04-12-2002, 04:51 AM
bit-

april 10th, a little control for you...

bit-101
04-12-2002, 08:09 AM
nice! :)