Rotate an object
-
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?
-
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?
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
-
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
-
Hehe ;) You're welcome!
If the brain were so simple we could understand it, we would be so simple we couldn't. — Lyall Watson