0

I am applying two equations of rotation to rotate gray scale images easily. It's not rotating, however.

The two equations are:

x' = x *cos (theta) - y *sin (theta)

and

y' = x *sin (theta) + y *cos (theta)

I have visited a number of Q&A's on this site but the explanations are unclear.

IMG imgRotate(IMG output, float deg)
{

  IMG lalo;
  lalo.degree = deg;


  float radian = ((2 *pi*output.degree) / 360);

  float cosine = cos(radian);
  float sine = sin(radian);
  int x1 = (output.height * sine);
  int y1 = (output.height * cosine);
  int x2 = (output.width * cosine + output.height* sine);
  int y2 = (output.height* cosine -output.width * sine);
  int x3 = (output.width * cosine);
  int y3 =(-output.width * sine);
  int minx = min(0, min(x1, min(x2, x3)));
  int miny = min(0, min(y1, min(y2, y3)));
  int maxx = max(0, max(x1, max(x2, x3)));
  int maxy = max(0, max(y1, max(y2, y3)));

  int w = maxx - minx;
  int h = maxy - miny;
  int x, y,nx,ny;


  lalo.pixel = (unsigned char*)calloc(lalo.height*lalo.width, sizeof (unsigned char));

    for (y = 0; y < h; y++)
    {
        for (x = 0; x <w; x++)
        {
            nx = ceilf(x*cos(radian) - y*sin(radian));
            ny = ceilf(x*sin(radian) + y*cos(radian));

            lalo.pixel[w*ny + nx] = output.pixel[w*ny + nx];
        }
    }
    return lalo;

}

I have added the following code but it is giving incomplete image

IMG imgRotate(IMG output,float deg, int height, int width)
{

  IMG lalo;
  lalo.degree = deg;
  lalo.width = width;
  lalo.height = height;
  lalo.pixel=(unsigned char*)calloc (lalo.height*lalo.width, sizeof (unsigned char));

  float radian = ((2 *pi*lalo.degree) / 360);
  int x, y, x1, y1;

  for (y = 0; y < lalo.height; y++)
  {
    for (x = 0; x <lalo.width; x++)
    {
      x1 = ceilf(x*cos(radian)-y*sin(radian));
      y1 = ceilf(x*sin(radian) + y*cos(radian));
      lalo.pixel[lalo.width*y1+x1] = output.pixel[output.width*x1+y1];
    }
  }
  return lalo;
}
1
  • Your question does not seem related to CSS. Please clarify what program you are using and what you are trying to do.
    – Paulie_D
    Commented Jan 12, 2016 at 8:03

1 Answer 1

3

this is the we do with css it may help not sure

.image-class {
   
    /* Rotate div */
    -ms-transform: rotate(45deg); /* IE 9 */
    -webkit-transform: rotate(45deg); /* Chrome, Safari, Opera */
    transform: rotate(45deg);
}
<img class="image-class" src="https://media-mediatemple.netdna-ssl.com/wp-content/uploads/images/behavioral-css/transform_rotate.png"/>

4
  • dear please diagnose my code..and tell me accordingly
    – bxjwxhwdc
    Commented Jan 12, 2016 at 5:28
  • @raja, you should be more than able to piece it together given this information. These rules are how you rotate an image using CSS in all three of the major browser types.
    – Araymer
    Commented Jan 12, 2016 at 5:34
  • why nobody is helping me..?,,,
    – bxjwxhwdc
    Commented Jan 12, 2016 at 6:18
  • when i say i have two arrays ..one input ,other output..i am applying now below code ..but that is not operating..i have been trying for last two days..please help me.. ' void imgCopy(IMG input, IMG output) { int i, j, degree, newx, newy; degree=90; float radian = (( degreepi) / 180); for (i = 0; i < output.height; i++) { for (j = 0; j < output.width; j++) { newx = ceilf(jcos(radian) - isin(radian)); newy = ceilf(jsin(radian) + icos(radian)); output.pixel[output.widthnewx + newy] = input.pixel[input.width*newx + newy]; } } } '
    – bxjwxhwdc
    Commented Jan 12, 2016 at 6:21

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