|
Author |
Topic: Balls connected by a spring, ideas? (Read 741 times) |
|
laytonhayes
|
Balls connected by a spring, ideas?
« on: Apr 8th, 2004, 6:09am » |
|
This is my first attempt at programming interactive visuals. I am attempting to have 2 balls, a main and a satellite connected by a spring. The satellite ball will follow the main ball via the spring, with a set resting distance between the two. Only the main ball can be dragged or come to a clicked position Here is my work so far: http://www.egoproduktions.com/balls Only the main ball moves, I have not found a way to accurately make the satellite follow. Any help will be greatly appreciated.
|
|
|
|
laytonhayes
|
Re: Balls connected by a spring, ideas?
« Reply #2 on: Apr 9th, 2004, 2:19am » |
|
Thanks for the link. I have both balls moving now, the spring draws a little later than the balls, will try to fix that tonight. Here is the updated link: http://www.egoproduktions.com/balls2 I also still need to have the satelite follow with a more spring like motion. Right now it always ends up in the same possition realative to the main ball.
|
|
|
|
skloopy
|
Re: Balls connected by a spring, ideas?
« Reply #3 on: Apr 9th, 2004, 11:19pm » |
|
Hey Ariel I didn't see you site before! I like the stuff you're doing with type, especially the Book of Sand. Except on my comp the type floats in the air instead of resting on the sand like in the screenshot.. Is it supposed to do that? I'm on a mac with safari and the latest java BTW.
|
|
|
|
arielm
|
Re: Balls connected by a spring, ideas?
« Reply #4 on: Apr 10th, 2004, 12:05am » |
|
hey scloopy, well, it's not your mac that suffers from delirium tremens but rather the screenshot which is a photoshop montage the separation between the text and the sand is actually intentional: i wanted to separate the "action" from the "reaction". + it wouldn't have work otherwise anyway: i'm generating a BSpline curve based on the sand pile, and then i use this spline to write the text on (without using a spline, it would be very hard to produce continuous text...) now the generated spline is smoother than the sand pile, so if it were like in the screenshot, the text would not be parallel with the sand at places with "high curvature". if you like, we can continue the discussion in this dedicated thread: http://processing.org/discourse/yabb/board_Events_action_displa_y_num_1080430360.html i remember that you started to play with text on curves a few moons ago... --- to layton, did you look at the Centipede source: http://www.chronotext.org/toys/centipede/Centipede.pde the setTarget() function has the solution to your problem... basically, the idea is that your "main" ball is following the mouse (but with some interpolation in order to avoid big jumps). then, imagine a line between the updated "main" position and the "satellite" position: you want "satellite" to be on this line, but at a specific distance (the "rest" one) from "main" that's exactly what the math stuff is doing there. suggestion: try to implement such a system in 1d, prior to 2d. hth
|
Ariel Malka | www.chronotext.org
|
|
|
miked
|
Re: Balls connected by a spring, ideas?
« Reply #5 on: Apr 13th, 2004, 5:57pm » |
|
laytonhayes, I would approach this as a physics problem. The expression for the force exerted on an object by a spring is given by Hook's Law: Force = -k * x Where "k" is the spring constant (ie. the "stiffness" of the spring) and "x" is the displacement of the object from the "rest length" of the spring (ie. how long the spring is when it is neither stretched nor compressed). Knowing the force on the object(s), you can use some simple numerical integration to "integrate up" to the position of the object(s). The simplest integration scheme is called the Euler method, and basically goes as follows: velocity(new) = velocity(old) + acceleration * timestep position(new) = position(old) + velocity * timestep Also note, of course, that: Force = Mass * Acceleration So, if you keep track of position, velocity, and acceleration (force) at each step, you can evolve the system by a timestep in each frame to get the new position, velocity, acceleration. The Euler method works fine in almost all cases, but there are some alternatives ranging from slightly more complicated (Verlet) to considerably more complicated (Runge-Kutta). I hope that makes sense. If not, I can probably dig up some resources online. cheers, -mike EDIT: This may have been obvious, but I should add that when I say "x" in the Hook's Law, I mean the generalized "position" coordinate. It can be treated as a vector as well, or you can break the position in to it's component dimensions and solve each seperately.
|
« Last Edit: Apr 13th, 2004, 6:02pm by miked » |
|
|
|
|
|