Diese Datei stammt aus Wikimedia Commons und kann von anderen Projekten verwendet werden. Die Beschreibung von deren Dateibeschreibungsseite wird unten angezeigt.
BeschreibungObtaining the inverse function by reflection (small).gif
English: This animation shows how to obtain the inverse function's graph visually, by switching the x and y axis, which is equivalent to reflecting the graph across the diagonal.
This is the code used to generate the animations. Play around with it on Shadertoy.
GLSL
# define SIZE 5.# define THICKNESS 0.05# define AXTHICKNESS 0.0165# define MARGIN 0.001# define STARTCHANGE 2.# define ENDCHANGE 4.# define STARTFLIP 5.# define ENDFLIP 7.# define PI 3.1415926538floatmaxcomp(vec2p){returnmax(p.x,p.y);}floatrectangle_sdf(vec2R,vec2p){vec2q=abs(p)-R;returnlength(max(q,vec2(0)))+min(maxcomp(q),0.0);}vec2rotate(vec2p,floatangle){vec2q;q.x=p.x*cos(angle)-p.y*sin(angle);q.y=p.x*sin(angle)+p.y*cos(angle);returnq;}floatxletter_sdf(floatsize,vec2centre,vec2p){vec2rectangle=vec2(size,size/6.);p-=centre;floatangle1=-45.0*PI/180.0;vec2q1=rotate(p,angle1);floatarm1=rectangle_sdf(rectangle,q1);floatangle2=45.0*PI/180.0;vec2q2=rotate(p,angle2);floatarm2=rectangle_sdf(rectangle,q2);returnmin(arm1,arm2);}floatyletter_sdf(floatsize,vec2centre,vec2p){vec2rectangle1=vec2(size,size/6.);vec2rectangle2=vec2(size/3.,size/6.);p-=centre;// Stand the Y letter upright after flipif(iTime>(STARTFLIP+ENDFLIP)/2.){p.x=-p.x;p.y=-p.y;}floatangle1=-45.0*PI/180.0;vec2q1=rotate(p,angle1);floatarm1=rectangle_sdf(rectangle1,q1);floatangle2=45.0*PI/180.0;vec2q2=rotate(p,angle2);q2+=vec2(size/2.,0.);floatarm2=rectangle_sdf(rectangle2,q2);returnmin(arm1,arm2);}vec2stretch_diagonally(vec2p,floatstretching_amount){/** Returns a vector that corresponds to 'p' * strecthed (amount>1) or compressed (amount<1) diagonally * (closer to, or farther away from, the diagonal) * Actually, the behaviour is the opposite, * but this is the effect that is seen */// Change to base {(1/sqrt(2), -1/sqrt(2)), (1/sqrt(2), 1/sqrt(2))}vec2q;q.y=(p.x+p.y)*sqrt(2.)/2.;q.x=(p.x-p.y)*sqrt(2.)/2.;// Stretch along the old base's diagonal, or the new base's horizontalq.x*=1./stretching_amount;// Change back to original base {(1, 0), (0, 1)}vec2r;r.x=q.x/sqrt(2.)+q.y/sqrt(2.);r.y=-q.x/sqrt(2.)+q.y/sqrt(2.);returnr;}voidpaint(inoutvec3col,invec3color,infloatactivation){/** Subtracts from 'col' = vec3(1.) (white) a vector * so that the color 'color' is given * to those pixels with 'activation' == 1 */col-=vec3(1.-color.r,1.-color.g,1.-color.b)*activation;}voidmainImage(outvec4fragColor,invec2fragCoord){//// ---- Defining pixel's position ---- ////vec2p=SIZE*fragCoord.xy/iResolution.xy;// Coordinates from 0 to SIZEp-=vec2(SIZE/2.,SIZE/2.);// Origin in centerp.x*=iResolution.x/iResolution.y;// x coordinate proportional to width//// ---- Stretching pixel's position along the diagonal ---- ////// float stretching_amount = sin(iTime);floatstretching_amount=2.*(smoothstep(ENDFLIP,STARTFLIP,iTime)-0.5);p=stretch_diagonally(p,stretching_amount);//// ---- Establishing pixel's color ---- ////vec3col=vec3(1.);// white background//// Draw functionfloatfunc=sin(p.x);// exp(p.x) OR p.x * p.x OR sin(p.x)// Function color - transition between red (original function) and blue (its inverse)vec3func_color=vec3(smoothstep(STARTCHANGE,ENDCHANGE,iTime),0.,smoothstep(ENDCHANGE,STARTCHANGE,iTime));// Gray for invalid values (e.g. x<0 for sqrt(x), inverse of x^2)if(p.x<-PI/2.||p.x>PI/2.)func_color=vec3(0.5);// Give color if pixel's height is between func - THICKNESS and func + THICKNESSpaint(col,func_color,smoothstep(func-THICKNESS,func-THICKNESS+MARGIN,p.y)*smoothstep(func+THICKNESS+MARGIN,func+THICKNESS,p.y));//// Draw axes// x axis - same as FUNCTION, but with func = 0.paint(col,vec3(0.),// blacksmoothstep(-AXTHICKNESS,-AXTHICKNESS+MARGIN,p.y)*smoothstep(AXTHICKNESS+MARGIN,AXTHICKNESS,p.y));// y axis - same as x axis, but using width instead of heightpaint(col,vec3(0.),smoothstep(-AXTHICKNESS,-AXTHICKNESS+MARGIN,p.x)*smoothstep(AXTHICKNESS+MARGIN,AXTHICKNESS,p.x));//// Draw X and Y labels// initial positionsvec2xpos=vec2(SIZE*0.4,-SIZE*0.075);vec2ypos=vec2(-SIZE*0.075,SIZE*0.4);// x labelvec2px=p-(ypos-xpos)*smoothstep(STARTCHANGE,ENDCHANGE,iTime);floatxd=xletter_sdf(SIZE/17.5,xpos,px);paint(col,vec3(0.),smoothstep(xd,xd+MARGIN,0.));// y labelvec2py=p-(xpos-ypos)*smoothstep(STARTCHANGE,ENDCHANGE,iTime);floatyd=yletter_sdf(SIZE/17.5,ypos,py);paint(col,vec3(0.),smoothstep(yd,yd+MARGIN,0.));fragColor=vec4(col.rgb,1.0);}
Lizenz
Ich, der Urheber dieses Werkes, veröffentliche es unter der folgenden Lizenz:
verbreitet werden – vervielfältigt, verbreitet und öffentlich zugänglich gemacht werden
neu zusammengestellt werden – abgewandelt und bearbeitet werden
Zu den folgenden Bedingungen:
Namensnennung – Du musst angemessene Urheber- und Rechteangaben machen, einen Link zur Lizenz beifügen und angeben, ob Änderungen vorgenommen wurden. Diese Angaben dürfen in jeder angemessenen Art und Weise gemacht werden, allerdings nicht so, dass der Eindruck entsteht, der Lizenzgeber unterstütze gerade dich oder deine Nutzung besonders.
Diese Datei enthält weitere Informationen, die in der Regel von der Digitalkamera oder dem verwendeten Scanner stammen. Durch nachträgliche Bearbeitung der Originaldatei können einige Details verändert worden sein.