Date: Tue, 10 Sep 1996 22:00:52 +0000 ( ) From: Gurunandan R Bhat To: Toby Ounsted Cc: "djgpp AT delorie DOT com" Subject: Re: Rotating a point (x,y). In-Reply-To: <96Sep10.100028bst.26499@spy.viglen.co.uk> Message-Id: Mime-Version: 1.0 Content-Type: TEXT/PLAIN; charset=US-ASCII On Tue, 10 Sep 1996, Toby Ounsted wrote: > > > > Hi all, > > Not wishing to go too far off topic, but does anyone have any C code > (and/or formulae) for rotating a point (x,y) around the origin(0,0) by a > fixed number of degrees?? I'm sure I did this in Maths at school, but it was > a _LONG_ time ago... > > Thanks, > > Toby. > if you take a point (x,y) and rotate it anti clockwise about the origin by an angle t, the new point (x',y') is gotten like so: x' = x * cos(t) + y * sin(t) y' = - x * sin(t) + y * cos(t) if you want to rotate it clockwise by the same angle you just replace t by -t. in a program, if you want to rotate it repeatedly by a fixed amount dt, starting from t = 0.0, (to get a cicle or an ellipse say) you could consider the following pseudo-code: dc = cos(dt); ds = sin(dt); x = r; y = 0.0; begin loop { temp = x * dc + y * ds; y = - x * ds + y * dc; x = temp; } end loop this way you can get away by evaluating trignometric functions only once. gurunandan bhat goa, india