Message-ID: <331DFE26.5DC0@rangenet.com> Date: Wed, 05 Mar 1997 17:13:43 -0600 From: "Dan M. Hedlund" Reply-To: markiv AT rangenet DOT com Organization: Range Net MIME-Version: 1.0 To: Guess CC: djgpp AT delorie DOT com Subject: Re: Rotation problem References: Content-Type: text/plain; charset=us-ascii Content-Transfer-Encoding: 7bit Guess wrote: > > Hello again! > I have a small (?) problem. I'm plotting 100 points in mode 13h and > rotating them in increments of 1 degree. It works, only the rotating > pixels get smaller and smaller until it becomes a little dot on the > screen. What am I doing wrong? :) I'm figuring it's due to the > rounding error...or am I wrong? It seemed to work fine when i was > rotating a triangle with the line() function. *Shrug* Here is the > code..thank you in advance for any help! > -- > void rotate() > { > int i; > for(i = 0; i < 100; i++) { > pix[i].x = pix[i].x * cos_t[1] - pix[i].y * sin_t[1]; > pix[i].y = pix[i].y * cos_t[1] + pix[i].x * sin_t[1]; > } > } Your changing the pixels value before you have finished using the old one. Try this: void rotate () { int i; float tx, ty; for (i = 0; a < 100; ++i) { tx = pix [i].x; ty = pix [i].y; pix [i].x = tx * cos_t [1] - ty * sin_t [1]; pix [i].y = ty * cos_t [1] + tx * sin_t [1]; } } Also, after a while, rounding errors might appear. If they do, try using one static table to hold the original points, and create another with the rotated points. void rotate () { static int a; int i; ++ a; a %= 360; for (i = 0; a < 100; ++i) { newpix [i].x = pix [i].x * cos_t [a] - pix [i].y * sin_t [a]; newpix [i].y = pix [i].y * cos_t [a] + pix [i].x * sin_t [a]; } } -- ***** *** ** ** Dan M. Hedlund ** ** ***** *** ** ** ** ** ** **** ** http://www.rangenet.com/markiv ** ** ** ** ** ** ** ** ** ******* ** **** ** ** ** ** ** *** ** ** ** ** ** ** ***** ** ** ** **