 |
 |
|
 |
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
scott wrote:
> Yes, inside the "acceleration" function, which is called from each
> "evaluate" you put your code for calculating the acceleration. This, in
> your case, would presumably call the routine to check for collisions and
> work out the forces for all the particles.
>
> Note that you need to put all the positions and velocities for every
> particle inside some state block and evaluate them in parallel using
> this algorithm - you can't do one at a time it doesn't work like that.
Question: Would it be worth using some kind of space partitioning to
enable you to process only "nearby" particles?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
> Question: Would it be worth using some kind of space partitioning to
> enable you to process only "nearby" particles?
I think he said he was using something like that already.
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
scott wrote:
>> Question: Would it be worth using some kind of space partitioning to
>> enable you to process only "nearby" particles?
>
> I think he said he was using something like that already.
Ah, OK.
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Invisible wrote:
> It's like, a function can only have one body. Nobody would find that
> surprising.
Unless you're using Erlang, I guess. :-)
"This is beyond dynamic binding. This is
make-up-your-mind-after-it's-already-running binding."
--
Darren New / San Diego, CA, USA (PST)
"That's pretty. Where's that?"
"It's the Age of Channelwood."
"We should go there on vacation some time."
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Chambers wrote:
> BTW, that grasshopper thing... does that come from the old TV show "Kung
> Fu"? I could have sworn I saw it in a movie, though. In fact, I asked
> at a couple local video stores what movie it was, and nobody knew... :(
I have no idea. My boss used to call me grasshopper. No idea why...
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
On Tue, 01 Apr 2008 21:04:23 +0100, Orchid XP v8 <voi### [at] dev null>
wrote:
>Chambers wrote:
>
>> BTW, that grasshopper thing... does that come from the old TV show "Kung
>> Fu"? I could have sworn I saw it in a movie, though. In fact, I asked
>> at a couple local video stores what movie it was, and nobody knew... :(
>
>I have no idea. My boss used to call me grasshopper. No idea why...
Walk the rice paper and leave no mark, Grasshopper.
--
Regards
Stephen
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
While we're on the subject... I've managed to get particle systems like
this to work before. (E.g., my chaos pendulum example, and various other
things.) What I haven't ever managed to do is figure out how to build
myself my own wave tank.
I know I've asked this before, but what's the algorithm for this?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Right. Well maybe it would be helpful to fix a few typos...
> evaluate (v,p) t dt (dv,dp) =
> let
> v' = v + dt*dv
> p' = p + dt*dp
> in (v', a (t+dt) v' p')
Err... that's incorrect. The acceleration function ("a") needs to be a
parameter somewhere. Or it needs to be a top-level function. Let's make
it top-level, like in the C++ version:
acceleration t v p = ???
evaluate (v,p) t dt Nothing = (v, acceleration t)
evaluate (v,p) t dt (Just (dv,dp)) =
let
v' = v + dt*dv
p' = p + dt*dp
in (v', acceleration (t+dt) v' p')
[I made the derivatives optional too. Did I get it right?]
> integrate t dt a (v,p) =
> let
> a = evaluate (v,p) t dt -- er... where's the rest?
> b = evaluate (v,p) t (dt/2) a
> c = evaluate (v,p) t (dt/2) b
> d = evaluate (v,p) t dt c
> dv = (fst a + 2 * (fst b + fst c) + fst d) / 6
> dp = (snd a + 2 * (snd b + snd c) + snd d) / 6
> in (v + dt*dv, p + dt*dp)
...and if we're using a top-level acceleration function, you don't need
that "a" parameter there (which incidentally causes a name clash).
integrate t dt (v,p) =
let
a = evaluate (v,p) t dt Nothing
b = evaluate (v,p) t (dt/2) (Just a)
c = evaluate (v,p) t (dt/2) (Just b)
d = evaluate (v,p) t dt (Just c)
dv = (fst a + 2 * (fst b + fst c) + fst d) / 6
dp = (snd a + 2 * (snd b + snd c) + snd d) / 6
in (v + dt*dv, p + dt*dp)
I'll have to try this out later and see if it actually works...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
You know what? Screw it. Let's start again...
data State = State {velocity, position :: !Double}
data Derivative = Derivative {dvelocity, dposition :: !Double}
evaluate :: State -> Double -> Double -> Maybe Derivative -> Derivative
evaluate s t dt Nothing = Derivative {dvelocity = acceleration s t,
dposition = velocity s}
evaluate s t dt (Just d) =
let
s' = State {velocity = velocity s + dvelocity d * dt, position =
position s + dposition d * dt}
in Derivative {dvelocity = acceleration s' (t+dt), dposition =
velocity s'}
integrate :: State -> Double -> Double -> State
integrate s t dt =
let
a = evaluate s t dt Nothing
b = evaluate s t (dt/2) (Just a)
c = evaluate s t (dt/2) (Just b)
d = evaluate s t dt (Just c)
dv = (dvelocity a + 2 * (dvelocity b + dvelocity c) + dvelocity d) / 6
dp = (dposition a + 2 * (dposition b + dposition c) + dposition d) / 6
in State {velocity = velocity s + dv * dt, position = position s +
dp * dt}
acceleration :: State -> Double -> Double
acceleration = error "not implemented yet"
Does that look correct?
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |
|  |
|
 |
Invisible wrote:
> Does that look correct?
Well, I just ran it on a simple harmonic oscilator and got a sine wave,
so that's always a good start...
--
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*
Post a reply to this message
|
 |
|  |
|  |
|
 |
|
 |
|  |