www.delorie.com/archives/browse.cgi   search  
Mail Archives: djgpp/1996/09/10/14:30:08

Date: Tue, 10 Sep 1996 22:00:52 +0000 ( )
From: Gurunandan R Bhat <grbhat AT aditya DOT unigoa DOT ernet DOT in>
To: Toby Ounsted <Toby AT viglen DOT co DOT uk>
Cc: "djgpp AT delorie DOT com" <djgpp AT delorie DOT com>
Subject: Re: Rotating a point (x,y).
In-Reply-To: <96Sep10.100028bst.26499@spy.viglen.co.uk>
Message-Id: <Pine.LNX.3.91.960910214845.3761A-100000@aditya.unigoa.ernet.in>
Mime-Version: 1.0


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


- Raw text -


  webmaster     delorie software   privacy  
  Copyright © 2019   by DJ Delorie     Updated Jul 2019