Wednesday, March 28, 2018

FELP.PL - Physics Apps for Kids


  
 http://felp.pl

I recently gave two lectures about physics and computer science in my kids school (2018-02). The lecture covered simple physics experiments plus some software show and self playing.

The kids were very OK with it and - because this is hard for them to type and find internet adresses of those many scattered web toy I made simple linking website, named it felp.pl and published. Enjoy!

I would say these apps are for children at age 2-102. Keep in mind, not all the apps here are mine - some of them I wrote by myself but to some of them I simply link there. Anyway, I will be happy to get some feedback on that and ideas what more to include here!



Wednesday, March 14, 2018

Mean Square Displacement in 1D Random Walk

Mean Square Displacement in 1D Random Walk

by Maciej Matyka

I realized that calculating MSD (mean square displacement) may be a little tricky for students and beginners. Have a look here, this may help to demistify it a little bit. It is a C++ implementation based on simple 1D random walk.

Reference: https://en.wikipedia.org/wiki/Mean_squared_displacement


-------------------------------------------------------------------------------------------


Results:

Exeplary trajectory of particle in 1D
MSD calculated with the code in this post.



-------------------------------------------------------------------------------------------

/**
 * Mean Square Displacement
 * Definition: https://en.wikipedia.org/wiki/Mean_squared_displacement
 * Implementation by Maciej Matyka
 * 14-03-2018 http://panoramix.ift.uni.wroc.pl/~maq/eng/
 **/

#include <iostream>
#include <cstdlib>
#include <ctime>

using namespace std;

int main(void)
{
   srand(time(NULL));

   float x0=0, y0=0;
   float x=x0,y=y0;

   float xn = 0;            // position at step n
   int STEPS = 100000;
   float averagex =0;
   float msd = 0;

   for(int N=0; N<1000; N++)
   {
        averagex =0;
        msd = 0;

        for(int s=0; s<STEPS;s++)
        {
            x=x0;
            for(int t=0; t<N; t++)
            {
                float dx = rand()/float(RAND_MAX);      // 1d random walk
                if(dx>0.5) dx=1; else dx=-1;
                x = x+dx;
            }  
            averagex = averagex + x;
            msd = msd + (x-x0)*(x-x0);
       }
       averagex/=(float)STEPS;
       msd/=(float)STEPS;
       cout << N << "\t" << averagex << "\t" << msd << endl;
   }
}
-------------------------------------------------------------------------------------------

Monday, March 12, 2018

2D Ripple Algorithm

2D Ripple Algorithm

by Maciej Matyka, Wrocław, 2018-03-13

(play here)

Once upon a time... I saw this on the famous Hugo Elias website (bouncy 2d graphics website). It was around 1998. Now I found it's web archived version of the algorithm and quickly done some re-implementation in javascript.

The basic algorithm works on two 2D tables. You ping-pong the data between tables, so you first run from 1 to 2 and then back from 2 to 1.

The main wave propagation goes like this:

      for each particle (x.y) calculate:
                 map2(x,y) = (map(x-1, y) +
                                    map(x+1, y) +
                                    map(x, y+1) +
                                    map(x, y-1)) /2 - map2(x,y)
                 map2(x,y) = map2(x,y) * damping

where damping is a number between 0-1. After one step map becomes map2 and vice-versa.
It is worth to add some smoothing as well (simply average each pixel between rendering).

Note: I discovered that using single pixel as the starting point for the wave gives really ugly picture and, thus I put the 3x3 picel each time I want to seed the wave.

Below is the first result of the model implemented in 2018 by me.


The app will be soon available at http://felp.pl.

Soda Constructor (Revisited)