Shop OBEX P1 Docs P2 Docs Learn Events
Image Rotation — Parallax Forums

Image Rotation

TJHJTJHJ Posts: 243
edited 2008-06-13 01:34 in Propeller 1
So I have a UOled 128 display and a Uoled Prop 96, I have been plotting a series of points on the screen derived from GPS data, I store the ploted pixels into an array for X and Y. I couldnt find much searching, so here I am.
Here is the big question Can anyone think of a good method to rotate the image on the screen?

How I have been trying to do it was with float math32Full.
Take Point 1, Find L and Theta from pixel 64, 64(Middle of Screen) For L find using the Distance Forumla. ((Ox-X)^2(Oy-y)^2)^(1/2) = L then find theta ArcSin((Y-64)/L)
Now Regenerate the data points for one angle offset - X = L*Sin(Theta+Offset) Y= L*Cos(Theta+offset)

Other than it doesnt work how it should, this is aweful. So if anyone knows of an object that rotates an image, or how to do it easily it would be greatly appricated.

Thank you
TJ

·

Comments

  • RaymanRayman Posts: 14,162
    edited 2008-06-10 02:10
    Image rotation can be done as a series of shifts in x and y... No need for higher math.
  • TJHJTJHJ Posts: 243
    edited 2008-06-10 03:38
    Can you elaborate? I cant seem to work out in my mind how to pull this off.

    So lots of time on google I came up with this.
    http://homepages.inf.ed.ac.uk/rbf/HIPR2/rotate.htm
    Which defines the·rotation as the following
    eqnro1.gif
    eqnro2.gif
    repeat i from 0 to TrackL
        Cx[noparse][[/noparse]i]:= F.FRound(F.Fadd(F.Fsub(F.FMul(F.Cos(F.FFloat(F.Degrees(Anglenew))),F.Fsub(Mapx[noparse][[/noparse]i],Fox)), F.FMul(F.Sin(F.FFloat(F.Degrees(Anglenew))),F.Fsub(Mapy[noparse][[/noparse]i], Foy))),Fox))
        Cy[noparse][[/noparse]i]:= F.FRound(F.Fadd(F.Fsub(F.FMul(F.Sin(F.FFloat(F.Degrees(Anglenew))),F.Fsub(Mapx[noparse][[/noparse]i],Fox)), F.FMul(F.Cos(F.FFloat(F.Degrees(Anglenew))),F.Fsub(Mapy[noparse][[/noparse]i], Foy))),Fox))
          
    

    So I ended up with the above but Im not getting anywhere? Did I miss something obvious?

    Post Edited (TJHJ) : 6/10/2008 5:05:32 AM GMT
  • Lord SteveLord Steve Posts: 206
    edited 2008-06-10 04:36
    Just to clarify:· Do you want to rotate an image (bitmap)?· Or do you want to rotate the points before drawing them?
  • TJHJTJHJ Posts: 243
    edited 2008-06-10 05:08
    Im 50-50 on that, I think it would be easier to rotate the points 1st then drawn them, Becuase it actually draws lines connecting the dots.
    So I have a maxium of 500 byte points, into a variable array.
    Defined as so
    Mapx[noparse][[/noparse]500]
    Mapy[noparse][[/noparse]500]

    So I would like to do it with a repeat command, but If I made it a bitmap, I think it would calc out faster when it was close to the maxium of the 500 points, but I am horriable at Bitmaps, I have a hard time keeping up with them. But IM open to learn and try anything.
    ·
  • LeonLeon Posts: 7,620
    edited 2008-06-10 09:58
    Standard techniques are quaternions and rotation matrices, if you need high performance.

    Leon

    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Amateur radio callsign: G1HSM
    Suzuki SV1000S motorcycle
  • RaymanRayman Posts: 14,162
    edited 2008-06-10 12:23
    TJHJ said...
    Can you elaborate? I cant seem to work out in my mind how to pull this off.
    Look here (for example):

    http://www.leptonica.com/rotation.html

    under "rotation by shear".

    This is the fast way to rotate images.
  • VIRANDVIRAND Posts: 656
    edited 2008-06-11 08:29
    I don't have code handy but I see what you are doing and you are very close to making it work well.

    Basically your rotation method is converting to polar coordinates
    and then after that conversion you can plot any angle of rotation you want with your method to
    "Regenerate your data points".

    There is a missing + in your distance formula and another problem is that you are losing your
    quadrant information (X and Y offset signs +/-) with the distance formula and the theta formula.
    Maybe you need an arccos also. Without the lost information you can only rotate points from
    one fourth of the screen.
  • Don DDon D Posts: 27
    edited 2008-06-11 13:41
    TJHJ
    No need to repeat the sin and cos functions for every point in the loop. Calculate as much as you can outside the loop and use them as constants inside the loop.
  • Paul BakerPaul Baker Posts: 6,351
    edited 2008-06-11 19:03
    Another method is by using cordic:

    http://forums.parallax.com/showthread.php?p=609053

    http://forums.parallax.com/showthread.php?p=642142


    ▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔▔
    Paul Baker
    Propeller Applications Engineer

    Parallax, Inc.
  • rjo_rjo_ Posts: 1,825
    edited 2008-06-13 01:34
    TJ

    Is this a fixed angle or a variable angle?

    Rich
Sign In or Register to comment.