/* @pjs crisp=true */
int dim=300;
// fairly generic setup
void setup()
{
size(dim,dim);
noLoop();
noSmooth();
noFill();
}
// only draw the axes as background, then draw the Fresnel curve
void draw()
{
background(255);
stroke(100,100);
line(0, height/2, width, height/2);
line(width/2, 0, width/2, height);
stroke(0);
drawFresnel();
}
// 'a' essentially acts as scaling factor
float a = 0.5;
float getA() { return a; }
void incA() { a+=0.1; redraw(); }
void decA() { a-=0.1; redraw(); }
// 'n' regulates the acceleration of curvature.
float n = 2.0;
float getN() { return n; }
void incN() { n+=0.1; redraw(); }
void decN() { n-=0.1; redraw(); }
// 'length' directly translates to our maximum value for 't', and
// regulates the interval over which we integrate
float length = 3.0;
float getLength() { return length; }
void incLength() { length+=0.2; redraw(); }
void decLength() { length-=0.2; redraw(); }
/**
* Fun fact: the Fresnel function isn't symbolically solvable.
* However, we can use the idea of the "Riemann sum" to
* solve it anyway, if we're okay with being imprecise. Given
* that our values are all rounded to integers anyway, I would
* say we're perfectly comfortable with that.
*/
void drawFresnel()
{
float stop = width*length;
float xoffset = width/2;
float yoffset = height/2;
/**
* The idea of a Riemann sum is really simple. One amazing thing
* about integrals is that they describe the area covered by a function.
* We can try to compute that using symbolic math, but we can also
* take the engineer's approach, and treat the area under a function as
* a series of thin rectangular strips, with an arbitrarily small width.
* It's really easy to compute the area of a rectangle, so if we add up
* all the strips between x=0 and x=t, then we have a good approximation
* of the area covered by the function. The thinner we make the strips,
* the closer our approximation gets to the real number. It can never
* become that real number, but we can get arbitrarily close by picking
* a width that ensure precision at least as good as what we need.
*
* The downside, of course, is speed. The more precise, the more
* rectangles you'll need to compute the area for, and the more of
* them you need to add together. There are more efficient ways
* to compute values for the Fresnel integral, but these rely on
* knowing which values of 't' one may encounter, and we don't.
*/
float x = 0;
float y = 0;
for(float t = 0; t