From: Logan Capaldo Date: 2005-05-06T18:08:51+09:00 Subject: Re: Ruby-tk question On 5/6/05, Logan Capaldo wrote: > On 5/6/05, Joe Van Dyk wrote: > > On 5/5/05, Hidetoshi NAGAI wrote: > > > From: Joe Van Dyk > > > Subject: Re: Ruby-tk question > > > Date: Fri, 6 May 2005 10:41:39 +0900 > > > Message-ID: > > > > > > > On 5/5/05, Hidetoshi NAGAI wrote: > > > > > From: Joe Van Dyk > > > > > Subject: Ruby-tk question > > > > > Date: Fri, 6 May 2005 09:24:01 +0900 > > > > > Message-ID: > > > > > > What's the easiest way to rotate a Tk Canvas Polygon? > > > > > Probably, you'll have to calculate coords by yourself. > > > > Hm, I have no idea how to do that. Trig was so long ago. > > > > > > That is field of Mathematics. :-) > > > I think that is not so difficult. > > > -- > > > Hidetoshi NAGAI (nagai@ai.kyutech.ac.jp) > > > > > > > It's horribly difficult for someone who hasn't done math in years. > > > > > > Well according to a random math site: > > def deg2rad(x) > (x * Math::PI) / 180.0 > end > > def rotate(x, y, deg) > r = Math.sqrt(x**2 + y**2) > theta = Math.atan(y/x) > u = r * Math.cos(theta + deg2rad(deg)) > v = r * Math.sin(theta + deg2rad(deg)) > [u, v] > end > > seems to work pretty well > > rotate(1.0, 0.0, 90.0) #=> [6.12323399573677e-17, 1.0] > > that is of course if you except 6.blah times 10 to the negative 17 is > close enough to zero for governement work. > > This method is SUPPOSED to convert them into polar coordinates and > then rotate them by deg degrees. I don't prentend to know that its > correct > Math site formula was stolen from: > http://mathforum.org/library/drmath/view/63184.html > One last note, this function is gonna rotate like it was on a cartesian plane (origin in the middle), if Tk's Canvas is like every other computer coordinate system i've come across, the coordinates are gonna be only in quadrant IV with the y-value negated, so you may have to keep that in mind before just pasting this code in.