All non-deforming motion of objects can be described entirely as a series of translations and rotations. Translations are simply movements in the X or Y direction (in the case of 2D graphics). Rotations are exactly what they sound like, motion around some axis. Translations are easy and we have already dealt with some in Section 2.9. Input Devices. Rotations are just as easy once you get the hang of them but they can be confusing at first due to the requirement of a little trigonometry. Just in case you have never covered trigonometry or you need a refresher, we'll go over the basics here. Trigonometry is the study of triangles and the relationships between their angles and sides. Here we will discuss only right trangles (triangles with one right (90 degree) angle). The longest side of a right triangle is known as its hypotenuse and it is always opposite the right angle. The two other sides are known as the legs. Angles in trigonometry are usually denoted using greek letters such as theta and phi . They can have several types of units (including degrees and radians) but for starters we use degrees (denoted by the symbol). Consider the triangle below:
The leg of the triangle that is opposite is known as the opposite leg and the leg that borders (other than the hypotenuse) is known as the adjacent leg. At this point, you are probably wondering what triangles have to do with rotations. Just imagine what happens if you keep the hypotenuse constant and begin to increase :
As is increased, the far tip of the hypotenuse begins to trace out a circle. In fact, the hypotenuse is the radius of the circle. When is at 0, the triangle is flat (i.e., it's more of a line than a triangle). At , the triangle is isosceles (both legs are equal in length). At , the triangle is a vertical line (because a triangle cannot have two right angles on a flat plane). At , the triangle is again flat, but this time it points in the opposite direction. At , it points straight down. At , it's back where it started.
It is easy to keep the hypotenuse constant conceptually, but how do we trace out a circle with the hypotenuse with a program. The functions sine and cosine define the ratios of the opposite leg to the hypotenuse and the adjacent leg to the hypotenuse given any angle :
  There are plenty of mnemonics that people use to remember these formulas (like SOHCAH for example), but we suggest you do not use them. Sine and cosine are some of the most important formulas in mathematics so trying to recall a mnemonic every time you see a triangle is almost like counting on your fingers to add 4+3. Instead, try to remember them graphically. If you think about it, the angle symbol almost looks like an eye. If it were an eye, the first side it would see when looking straight ahead is the opposite side. Sine sounds like it should come first before cosine, right? To see the adjacent side, the eye would have to look away from the hypotenuse (in this case down). This is the second thing the eye would see so it's cosine.
By remembering it graphically instead of in words, you'll find that your brain will instantly pick out sine for the opposite side and cosine for the adjacent side without your even having to think about it (trust us, you will thank this book when you get to physics classes).

Since we know that the hypotenuse is the radius, it is easy to draw a circle by rearranging the formulas above:
  If we define the x-axis as the adjacent leg then the y-axis must be the opposite leg. Thus, given an angle and a radius, we can calculate the x and y coordinates of any point on a circle.  Object Pascal defines sin and cos functions for sine and cosine. The only difference between these functions and the functions we have been describing is that they take angles in radians instead of degrees. Many people have trouble understanding radians, but they are actually quite simple. Imagine the radius of a circle as a string. Now imagine placing this string along the circumfrence of a circle (the circumference is the outer boundary of the circle). 
This string is said to form an arc or a fraction of the total circle. If we draw lines from the endpoints of this arc on the circumfrence to the center of the circle, we have an angle. The size of this angle is 1 radian because the arc it subtends is equal in length to the radius of the circle.
Excercise 3-1.
Solve the following problems (these are math problems not programming problems).
  1. As we saw above, an angle measuring 1 radian subtends only part of the circumfrence of a circle. How many radians must an angle be to cover exactly half the circle? Hint: What is the formula for the circumference of the circle given its radius?
  2. How many radians are equivalent to ?
  3. How many radians are equivalent to ?
  4. How many radians are equivalent to ?
  5. How many radians are equivalent to ?
  6. How many radians are equivalent to ?
  7. How many radians are equivalent to ?
  8. Write a formula to convert degrees to radians. Hint: Use the solution to the previous problem.
Excercise 3-2.
Solve the following problems (these are programming problems).
  1. Given that the functions "sin" and "cos" in ObjectPascal expect angles in radians, if we want to pass something in degrees we have to multiply the degree value by PI/180 to convert to radians. Using this, write a program that draws a right triangle with a hypotenuse length of 1 and an angle with the x-axis of 30 degrees. Hint: You'll need MoveTo and LineTo and you'll have to calculate the X and Y coordinates of the far end of the hypotenuse using sin and cos.
  2. Now, using the code from the previous problem, make the hypotenuse have length 5.
  3. Instead of having a triangle that makes an angle of with the x-axis, draw a triangle that makes an angle of with a line parallel to the y-axis. Keep the hypotenuse at 5.
  4. Using a for loop, draw the first 45 degrees of an circle arc starting from the positive x-axis. Assume the circle has radius 5. Hint: You will need to vary Theta.
  5. Using a for loop, draw 180 degrees of a circle arc starting on the positive y-axis and ending on the negative y-axis.
  6. Make a spiral that starts at the origin and expands out for 10 full loops.
  7. Make the spiral rotate. Hint: A variable called FrameCount is declared in FTGraphics that you can use to keep track of what frame you are on. You could also declare your own global variable (initialized to 0) and increment it on each frame.
  8. Make the rotation of the spiral speed up or slow down based on pressing the right or left arrow keys. Hint: Create a variable called Speed and vary it using the Keyboard[VK_LEFT].Press and Keyboard[VK_RIGHT].Press key states.
As you can see, sin and cos can be very usefule and versatile functions. Just for fun you should run the program below which shows how sin and cos are related to triangles, circles, and waves.
program Rotations;
uses SysUtils, FTGraphics;

procedure Initialize;
begin
end;

var
  Theta : Integer = 0;

procedure OnEnterFrame;
var
  Radius : Double;
  K : Integer;
  V : TVector2D;
  O : TVector2D;
begin
  Radius := 2;
  O.X := -10; O.Y := 0;

  {Draw the outline of the circle}
  FrameEllipse(O.X-Radius,O.Y+Radius,O.X+Radius,O.Y-Radius,clRed);

  {Determine the coordinates on the circle given an angle Theta}
  V.X := cos(Theta*PI/180)*Radius;
  V.Y := sin(Theta*PI/180)*Radius;

  {Draw a triangle inside the circle using these coordinates}
  MoveTo(O.X,O.Y); LineTo(O.X+V.X,O.Y+V.Y);
  MoveTo(O.X+V.X,O.Y); LineTo(O.X+V.X,O.Y+V.Y);
  MoveTo(O.X,O.Y); LineTo(O.X+V.X,O.Y);

  {Draw the sine wave}
  SetPen(clLime);
  MoveTo(-7,0);
  For K := 0 to Theta do
    LineTo(-7+K/100,sin(K*PI/180)*Radius);
  SetPen(clYellow);
  MoveTo(O.X+V.X,O.Y+V.Y); LineTo(-7+Theta/100,sin(Theta*PI/180)*Radius);

  {Write the current value of theta}
  SetFont('Arial',clWhite,16);
  TextOut(0,-6.5,'Theta = '+IntToStr(Theta mod 360));

  {Increment theta for the next frame}
  Inc(Theta,5);

  if Theta > 360*6 then Theta := 0;
end;

begin
  RunGraphicalApp(@Initialize,@OnEnterFrame);
end.