Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. Rotate an object

Rotate an object

Scheduled Pinned Locked Moved C#
linuxhelpquestion
4 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • I Offline
    I Offline
    Isawyouoo
    wrote on last edited by
    #1

    hi! I'm trying to rotate a simple point over another one, here is the code: x = (x - x1) * (Math.Cos(1)) - (y - y1) * Math.Sin(1) + x1; y =(x - x1)*(Math.Sin(1)) + (y - y1)*Math.Cos(1) + y1; Point1.Location = new Point((int)x,(int)y); but it's seem that the rotation go like a shell of snail to direction of the origin(x1,y1) and then stops; maybe I should round the double x and y and convert them to int, because when converting directly, I'm just close that make the number degrade is that the problem?

    S 1 Reply Last reply
    0
    • I Isawyouoo

      hi! I'm trying to rotate a simple point over another one, here is the code: x = (x - x1) * (Math.Cos(1)) - (y - y1) * Math.Sin(1) + x1; y =(x - x1)*(Math.Sin(1)) + (y - y1)*Math.Cos(1) + y1; Point1.Location = new Point((int)x,(int)y); but it's seem that the rotation go like a shell of snail to direction of the origin(x1,y1) and then stops; maybe I should round the double x and y and convert them to int, because when converting directly, I'm just close that make the number degrade is that the problem?

      S Offline
      S Offline
      Sascha Lefevre
      wrote on last edited by
      #2

      You should store the points coordinates in doubles, calculate everything in doubles and only convert to integer for displaying (and don't feed these integers back into the calculation). For even more accuracy (if needed) you could, instead of incrementally changing the points coordinates, calculate the to-display-coordinates always from the points origin by incrementing the rotation angle.

      If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

      I 1 Reply Last reply
      0
      • S Sascha Lefevre

        You should store the points coordinates in doubles, calculate everything in doubles and only convert to integer for displaying (and don't feed these integers back into the calculation). For even more accuracy (if needed) you could, instead of incrementally changing the points coordinates, calculate the to-display-coordinates always from the points origin by incrementing the rotation angle.

        If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

        I Offline
        I Offline
        Isawyouoo
        wrote on last edited by
        #3

        Thanks man, you saved my life, all the day of hopeless X| , I feel a king now :laugh:

        S 1 Reply Last reply
        0
        • I Isawyouoo

          Thanks man, you saved my life, all the day of hopeless X| , I feel a king now :laugh:

          S Offline
          S Offline
          Sascha Lefevre
          wrote on last edited by
          #4

          Hehe ;) You're welcome!

          If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson

          1 Reply Last reply
          0
          Reply
          • Reply as topic
          Log in to reply
          • Oldest to Newest
          • Newest to Oldest
          • Most Votes


          • Login

          • Don't have an account? Register

          • Login or register to search.
          • First post
            Last post
          0
          • Categories
          • Recent
          • Tags
          • Popular
          • World
          • Users
          • Groups