Forum Rule: Always post complete source code & details to reproduce any issue!
Results 1 to 8 of 8

Thread: play with image rotations in degrees ILI9341_t3n

  1. #1
    Junior Member
    Join Date
    May 2021
    Posts
    13

    play with image rotations in degrees ILI9341_t3n

    sorry for english translation online
    I'm currently having fun playing with ILI9341_t3n on a 240 x 320px screen, I shift an image of width X and height Y from left to right and from top to bottom see diagonally.
    I would like to make rotations with the axis of rotation positioned on the screen so random on the image.

    I understood that it was necessary to make a matice, to define the point of arrival and to go to seek the corresponding point in the starting image to avoid the holes.

    do you think this can be interesting?

  2. #2
    Senior Member
    Join Date
    Nov 2015
    Location
    Cold hollow VT
    Posts
    204
    That would be a really challenging project. Lots of matrix math with SIN() & COS() to move the image points around.

  3. #3
    Junior Member
    Join Date
    May 2021
    Posts
    13
    hello grease_lighting, yes it can do a lot of calculation ... probably for this reason nobody does it but I told myself to see the speed of this library and the asynchronous mode ... why not.
    Actually I have an image of 720X866 pixels which moves without any problem, see even too fast

  4. #4
    Senior Member
    Join Date
    Jul 2020
    Posts
    1,234
    Arbitrary image rotation can be done without any trig, you decompose the rotation into 3 othogonal shear transforms
    and implement these shears directly on the pixel data, snapping to the nearest grid point.
    https://www.ocf.berkeley.edu/~fricke..._shearing.html

    This sort of pixel manipulation is in principle lossless when undone (the complexity is what to do about clipping/cropping)

  5. #5
    Junior Member
    Join Date
    May 2021
    Posts
    13
    Hello MarkT ,
    thank you for this information, I did not know, I will watch it with passion this weekend, moreover, with this method, we must be able to keep a certain fluidity.

  6. #6
    Junior Member
    Join Date
    May 2021
    Posts
    13
    Hello, here is my little help function of the web but I have two problems.
    1 / I have the impression that it does not turn degree by degree.
    2 / how should I proceed to read the image I have in the program?
    Code:
    void rotation_image(){
        int largeur = 720 / 2; //taille de limage et centre
        int hauteur = 866 / 2; //taille de limage et centre
        int x =0;
        int y =0;
        int x2 = 0;
        int y2 = 0;
        double anglevariable=0;
        double sin2 = 0;
        double cos2 = 0;
      for(int i=0; i<360;i++){//faire une rotation de 360 degres
      display.fillScreen(BLACK); 
      //Serial.println(i);
    anglevariable=i;
    sin2 = sin(-anglevariable);
    cos2 = cos(-anglevariable);
    for(int x = 0; x < 720; x++) {
      for(int y = 0; y < 866; y++) {
        
       x2 = x - largeur;
       y2 = y - hauteur;
        int nouveaux = (int)round((cos2 * x2 - sin2 * y2) + largeur);
        int nouveauy = (int)round((sin2 * x2 + cos2 * y2) + hauteur);
    
        if(nouveaux >= 0 && nouveaux < 720 && nouveauy >= 0 && nouveauy < 866) {
          display.drawPixel(nouveaux,nouveauy,RED);
          //display.writeRect(0, 0, 720, 866, (uint16_t*)ecran2); ???????
             } else {
          display.drawPixel(nouveaux,nouveauy,ORANGE);
         
         }
       }
      }delay(1000);
     }
    }
    or how to implement the function which is in pascal?
    https://www.ocf.berkeley.edu/~fricke..._shearing.html

  7. #7
    Junior Member
    Join Date
    May 2020
    Location
    UK
    Posts
    3

    Lightbulb

    It doesn't rotate by degrees because the trig functions you are calling take their input in radians. Try anglevariable = i * PI / 180.;

    As for reading a texture, perhaps it's easier to point you at some code which does that. Every 2 seconds that swaps between nearest-neighbour and bilinear sampling. I did everything using fixed-point maths because that code targets AVR, but on Teensy 4 I would probably use floats.

    By multiplying the rotation matrix by a scaling factor, you get what is often called a rotzoomer. Searching that term may lead to articles that help with your understanding.

    And, yes, I find this kind of thing very interesting.

  8. #8
    Junior Member
    Join Date
    May 2021
    Posts
    13
    Hi sutaburosu,
    thank you for your help
    yes indeed, it works better in degrees rather when radian, that's already a good thing
    Mais je suis encore loin du resultat rechercher, il y a encore du boulot mais peut de temps de libre en ce moment.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •