POV-Ray : Newsgroups : povray.off-topic : Liquid Physics : Re: Liquid Physics Server Time
1 Oct 2024 09:26:26 EDT (-0400)
  Re: Liquid Physics  
From: Invisible
Date: 31 Mar 2008 10:17:24
Message: <47f10084$1@news.povray.org>
>> It's news to me that C++ supports optional function arguments.
> 
> Of course it does (see printf) but you don't use that here.  You just 
> define two functions with the same name but with different arguments 
> (this is where the article text is a bit misleading IMO).  The compiler 
> knows which one to actually call because it matches up the arguments.

Ah, right, so it's overloaded but that's not shown in the article?

(BTW, I thought printf() was only for C, not C++?)

>> [And while we're on the subject, this is the first example of C++ code 
>> I've ever seen which appears to be comprehensible. Usually it just 
>> looks like gibberish...]
> 
> Maybe because it's written for the purpose of clarity rather than trying 
> to make it look "clever" by being totally unreadable.

Did the Haskell version look "readable"?

> When I first wrote my RK4 code for the thing I'm currently working on, I 
> accidentally updated the initial state for each of the 4 derivative 
> calculations.  It was only when I noticed that the velocities being 
> reported didn't match up with the actual distances being covered (like 
> covering 1km in 10 seconds at a speed of 20 m/s!) that I found the bug.

One of the nice things about Haskell is that you can't make that 
mistake. Since you never update anything in-place, you can't 
accidentally destroy a result you need to use again later, and by left 
wondering where this "wrong" data is coming from.

...unfortunately you *can* still accidentally return the wrong damn 
varible from your function. :-S

> A common method used in car simulations (where the tyres are very stiff 
> and hence need a very small time step or the thing explodes easily) is 
> to check that energy is (almost) conserved.  Going back to the simple 
> mass/spring model, if you keep track of the kinetic energy in the mass 
> and the spring energy stored, it should be fairly trivial to include a 
> check if the total energy has suddenly spiked.  If so you could then do 
> some smaller time steps.  Of course if you are getting input from 
> outside the system you need to account for this too.

Mmm, it has a flavour...

-- 
http://blog.orphi.me.uk/
http://www.zazzle.com/MathematicalOrchid*


Post a reply to this message

Copyright 2003-2023 Persistence of Vision Raytracer Pty. Ltd.