Re: rotateing
- Posted by Tommy Carlier <tommy.carlier at telenet.be> Mar 02, 2005
- 487 views
Hayden McKay wrote: > I'm looking for formulars to rotate 2d and 3d points arround an objects centre > (x,y) (x,y,z) respectively. > > I've tried: > deg/=100 > new_x=(cos(deg)*x)-(sin(deg)*y) > new_y=(sin(deg)*x)+(cos(deg)*y) > > seems to rotate O.K. but it's not what I'm looking for. > ie: the origen here is assumed to be at 0:0. > > could some please point me in the right direction. To rotate around a point, just subtract the coordinates from {x, y} before rotating, and add it again after rotating.
integer origin_x, origin_y, x, y, new_x, new_y atom deg ... deg /= 100 new_x = cos(deg) * (x - origin_x) - sin(deg) * (y - origin_y) + origin_x new_y = sin(deg) * (x - origin_x) + cos(deg) * (y - origin_y) + origin_y
-- The Internet combines the excitement of typing with the reliability of anonymous hearsay. tommy online: http://users.telenet.be/tommycarlier tommy.blog: http://tommycarlier.blogspot.com