A Flash Developer Resource Site

Results 1 to 8 of 8

Thread: Brain Food?

  1. #1
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252

    Wink

    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.


  2. #2
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252

    here's what I have so far, just bones.

    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?
    --------------







  3. #3
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    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.

  4. #4
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252
    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.

    Code:
    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;
    		ball.radius = ball._width/2;
    		
    	}
    }
    function main() {
    	for (i=0; i<b.length; i++) {
    		var ball = b[i];
    		
    			ball.vx *= damp;


  5. #5
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    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.


  6. #6
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252
    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.
    Code:
    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....

  7. #7
    Senior Member ironmallet's Avatar
    Join Date
    Feb 2001
    Posts
    252
    bit-

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

  8. #8
    Senior Member
    Join Date
    Jan 2002
    Posts
    368
    nice!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  




Click Here to Expand Forum to Full Width

HTML5 Development Center