Live data from Hacker News

Web GL Ocean Simulation

david.li

41–50 of 138 posts

Re: Web GL Ocean Simulation

#41
post #33

Earlier quoted context omitted.

I wonder if it was all handwritten. Esp. functions like invertMatrix or premultiplyMatrix. Or what he used to generate the code. I once used WolframAlpha to get me some complicated formulas and wrote a custom WA-plaintext-output-to-C translator for that output to use it in my code. Here is the script: https://github.com/albertz/helpers/blob/master/wolframalpha_... Example input: http://www.wolframalpha.com/input/?i=s…

It's worth pointing out that you should rarely, if ever, use exact formulas since there are a lot of problems with numerical stability amongst other things. Often it is faster to just numerically solve the system. For example, in your case you are solving Ax=b which you can easily solve by a simple LU decomposition. Plus if your A changes, your exact formula is wrong, so using an LU decomposition just makes sense. Pl…

In case that the exact formulas for this solution would be numerically unstable, why would the LU decomposition improve the numerical stability? Also, why should it be faster?

Well, to be fair, in that example, if the compiler does those `pow(x2 - x1, 3.)` calls multiple times, this would not be optimal, but otherwise, it should be ok.

I did this because I will probably never ever change the matrix A here and I wanted to make that code very fast. Otherwise, it's of course a good idea to use some more generic solution.

Re: Web GL Ocean Simulation

#42
post #36

The code is quite cool to look at. Love seeing the extensive use of matrices and mathematics to create such a beautiful and mesmerizing display. If anyone is interested in playing around with it, I threw it up at JSFiddle here: http://jsfiddle.net/zyAzg/ Excellent demo.

I'm not sure how I'd feel about a repost to jsfiddle without my permission if I were the original author. How is this any different than reposting xkcd or other webcomics on alternate hosting without the author's permission?

because it's code in a browser. if the author didn't want us to look at the code, why would they let us download it?

Re: Web GL Ocean Simulation

#43

This runs at about 7 frames per second in Chrome on my 10-month-old 13" Macbook Pro at work. Are people with better graphics cards seeing 60 (or even 30) fps? I'd love to be able to see this in all its glory.

It's definitely performing better than that on my 2nd gen 13" MBP on Chrome. Could it be struggling with retina?

60fps in Chrome on MBP 15"

Re: Web GL Ocean Simulation

#44
post #42
post #36

Earlier quoted context omitted.

I'm not sure how I'd feel about a repost to jsfiddle without my permission if I were the original author. How is this any different than reposting xkcd or other webcomics on alternate hosting without the author's permission?

because it's code in a browser. if the author didn't want us to look at the code, why would they let us download it?

Nobody's talking about looking at the code — the issue here is redistributing it on a platform outside of the author's control.

Re: Web GL Ocean Simulation

#45
post #42
post #36

Earlier quoted context omitted.

I'm not sure how I'd feel about a repost to jsfiddle without my permission if I were the original author. How is this any different than reposting xkcd or other webcomics on alternate hosting without the author's permission?

because it's code in a browser. if the author didn't want us to look at the code, why would they let us download it?

via reductio ad absurdum, do you also think it's alright to reappropriate swaths of CSS, HTML, and images from other people's web designs?

Re: Web GL Ocean Simulation

#46
post #38
post #33

Earlier quoted context omitted.

It's worth pointing out that you should rarely, if ever, use exact formulas since there are a lot of problems with numerical stability amongst other things. Often it is faster to just numerically solve the system. For example, in your case you are solving Ax=b which you can easily solve by a simple LU decomposition. Plus if your A changes, your exact formula is wrong, so using an LU decomposition just makes sense. Pl…

His system of equations is not linear so vanilla Ax=b won't work.

It is actually linear. a,b,c,d are the unknowns and x1 and x2 are the inputs.

A bit confusing since normally x1,x2 denote the unknowns.

Re: Web GL Ocean Simulation

#47

This runs at about 7 frames per second in Chrome on my 10-month-old 13" Macbook Pro at work. Are people with better graphics cards seeing 60 (or even 30) fps? I'd love to be able to see this in all its glory.

I don't know how to check the FPS, but it looks perfectly smooth to me on a 2010-era 15" MBP.

Re: Web GL Ocean Simulation

#48
post #33

Earlier quoted context omitted.

It's worth pointing out that you should rarely, if ever, use exact formulas since there are a lot of problems with numerical stability amongst other things. Often it is faster to just numerically solve the system. For example, in your case you are solving Ax=b which you can easily solve by a simple LU decomposition. Plus if your A changes, your exact formula is wrong, so using an LU decomposition just makes sense. Pl…

In case that the exact formulas for this solution would be numerically unstable, why would the LU decomposition improve the numerical stability? Also, why should it be faster? Well, to be fair, in that example, if the compiler does those `pow(x2 - x1, 3.)` calls multiple times, this would not be optimal, but otherwise, it should be ok. I did this because I will probably never ever change the matrix A here and I wante…

I'm not implying yours are not unstable, it's just there is a chance it might be. Typically exact formulas exhibit such properties.

LU decomposition is numerically stable, for the most part. You can run into problems with floating point arithmetic if you're not careful. This just has to do with the way you solve the problem. By breaking up the matrix into an upper and lower triangular part and solving the resulting triangular system, you often avoid things like powers or square roots and just reduce everything to basic addition and multiplication which tend to have more stable numerical properties.

As for speed, well in this small case of N=4 there is probably very little speed increase since LU is O(N^{3}), although this can be improved depending on symmetries of the matrix. Maybe for N=5 I might write out the exact formulas but beyond that I would just a LU solver since the amount of code for an LU solver is fairly compact.

But, as you correctly point out, if you are never changing the matrix A then you are probably safe with writing it out this way.

I just come from a numerical fluids background so seeing exact formulas makes me uneasy. And in my work since the number of grid points N tends to be variable so general formulas are not available. Plus I've noticed a lot of programmers tend to not know numerical algorithms. In fairness, I don't blame them. All the numerical computations courses I've taken and TAed are very boring and don't make you do anything fun and numerical analysis has this reputation of being dry. If you actually made them write stuff like a Navier-Stokes solver, you would get them interested.

By the way if you want to learn more about numerical linear algebra, which is the cornerstone of most scientific and high performance computing, I personally enjoy Trefethen and Bau's book. Although it's aimed at a mathematical audience and assumes such.

Re: Web GL Ocean Simulation

#49
post #38
post #33

Earlier quoted context omitted.

It's worth pointing out that you should rarely, if ever, use exact formulas since there are a lot of problems with numerical stability amongst other things. Often it is faster to just numerically solve the system. For example, in your case you are solving Ax=b which you can easily solve by a simple LU decomposition. Plus if your A changes, your exact formula is wrong, so using an LU decomposition just makes sense. Pl…

His system of equations is not linear so vanilla Ax=b won't work.

He's solving for abcd, which is linear in powers of x. I'm not going to argue for what's the correct solution, but it's certainly not that mess.

Re: Web GL Ocean Simulation

#50
post #42
post #36

Earlier quoted context omitted.

I'm not sure how I'd feel about a repost to jsfiddle without my permission if I were the original author. How is this any different than reposting xkcd or other webcomics on alternate hosting without the author's permission?

because it's code in a browser. if the author didn't want us to look at the code, why would they let us download it?

if a person didn't want his car stolen, why would he leave his car door unlocked?

just because it's viewable, does not mean you are granted the rights to do whatever you want with it.

Post reply on HN