Mathematics Stack Exchange is a question and answer site for people studying math at any level and professionals in related fields. Join them; it only takes a minute:

Sign up
Here's how it works:
  1. Anybody can ask a question
  2. Anybody can answer
  3. The best answers are voted up and rise to the top

I'm trying to modify a function to create fisheye effect on image (i use a software that permit to modify every single pixel of an image).

At the moment i use this function:

float kk=width*0.5;
float ll=height*0.5;
float dx=(x-kk);
float dy=(y-ll);

float aa=atan2(dy,dx);
float rr=hypot(dy,dx);
float rs=rr*rr/hypot(kk,ll);
int px=kk+rs*cos(aa);
int py=ll+rs*sin(aa);


  • width: image width;
  • height: image height;
  • x and y: original pixel position and px and py are pixel from where i take result.

Using this fonction i substitute pixel at {x,y} with pixel at {px,py}. This work,and create a fisheye effect correctly, but i need to add a variable/parameter to control final effect.

Someone could help me to find how to add this parameter on that function ?

share|cite|improve this question

You could multiply rs by a parameter. This corresponds to changing the scale of how close to the center your original pixel is.

share|cite|improve this answer

Your Answer


By posting your answer, you agree to the privacy policy and terms of service.

Not the answer you're looking for? Browse other questions tagged or ask your own question.