Thread Rating:
  • 0 Vote(s) - 0 Average
  • 1
  • 2
  • 3
  • 4
  • 5
Java 2d physics
#1
[Image: springmotion4wr8.jpg]


I've been putting this together just for fun, but I'm not completely happy with how it works.


The balls are point masses, the lines act like ideal springs (F = -xk) and I'd got a bit of a workaround for the damping coefficient so I'm kinda looking for physics / programming advice.


Currently the damping pseudocode looks kinda like this
Code:
get velocity of 2 end points
project both onto the direction of the spring
use that component to find a weighted average
  end1 = c*(end2-end1) type thing
subtract this from each end velocity so they get closer to each other

It seems to work out pretty well (as seen above) I'm just not sure how physically accurate it is.

I know the damping on a spring drops velocity by a constant, but that's taking 1 end to be fixed, which I can't really do with multiple linked springs.

Also I'm in need of an efficient intersection algorithm (to test when 2 balls collide) so any advice there would be nice too.


And if there's some way to somehow render these to a seperate layer instead of the background so it doesn't keep every iteration that would be helpful too. Right now (aside from screenshot above, where I disabled it to show how it animates) I'm overwriting the entire panel with a white rectangle between every iteration and this is kinda slow.
Reply


Messages In This Thread
Java 2d physics - by Stereo - 2009-02-05, 10:23 PM
Java 2d physics - by Spaz - 2009-02-06, 08:31 PM
Java 2d physics - by Stereo - 2009-02-06, 11:04 PM
Java 2d physics - by Spaz - 2009-02-07, 03:13 AM
Java 2d physics - by Stereo - 2009-02-07, 01:57 PM
Java 2d physics - by DeadHead - 2009-02-08, 08:42 PM
Java 2d physics - by Stereo - 2009-02-09, 10:30 AM
Java 2d physics - by DeadHead - 2009-02-10, 03:40 AM
Java 2d physics - by Stereo - 2009-02-10, 10:25 AM

Forum Jump:


Users browsing this thread: 1 Guest(s)