ADUG
Home
About Us
Services
Meetings
Fees
Mailing List
Rules
Reference Papers
Downloads
Apply to Join
Links
Delphi Jobs
Special Offers
Maths Corner

 

by Glenn Crouch

 

Glenn’s Maths Corner

Angles - Part I

This issue we start our look at Angles. We will begin by looking at the different ways Angles are measured, thus this issue will be a Geometry Lesson but we will try not to make it too painful.

The Right Angle

Probably the best place to start is with the Right Angle - which can be drawn as follows:

Right Angle:

We then define an Acute Angle as one that is less than a Right Angle and an Obtuse Angle as one that is greater than a Right Angle:

Acute:   Obtuse:

And we can show that a Circle is made up of Four Right Angles:

Circle = 4 Right Angles:

And similarly a Straight line is said to be two right Angles.

Angles are normally measured in a counter clockwise direction:

We can thus divide the plane into 4 quadrants:

The Degree

One of the most common ways to measure angles is in Degrees, where a Degree is defined such that there is 90 Degrees (normally written 90°) in a right angle. Thus there are 360° in a Circle and 180° in a straight line. 

So when we say an Angle is 30°, we are defining an Acute Angle in the first quadrant:

Whereas an Angle of 250° would be in the third quadrant:

Since Angles are measured in a circular fashion, once we go past 360° we start to repeat, thus 370° is the same as 10° (since 370 - 360 = 10) and in fact 360° is the same as 0°.

If we measure in a Clockwise direction then the angle becomes negative, but the same principle applies. Thus -30° is the same as 330° since (360 - 30 = 330)

So to convert an Angle in Degrees to one that is between 0 and 360:

{ Returns the Angle as the equivalent angle between 0 and 360 Degrees }
function AdjustAngle360 (const Angle: Extended): Extended;
begin
  Result := Angle - Int (Angle / 360) * 360;
  if Result < 0 then
    Result := Result + 360;
end;

The Radian

Whilst Degrees are probably the most popular way to measure an Angle, by measuring in Radians we do get much nicer Mathematical properties, especially in Calculus (though we won't be going into that here). One of the traps that many new programmers fall into with the Trigonometric functions (like Sin and Cos - more on them in a later lesson) is that they pass these functions angles measured in Degrees, whereas Computer Languages work in Radians by default. This is due to Computer Science and Programming having strong ties with Mathematics.

Anyway so what is a Radian???

Well I could say that 1 Radian = 57.295779513082320877 Degrees - which it is but that isn't very helpful. If we think again about Circles, and in particular the Unit Circle - i.e. the one where the Radius is 1:

The circumference of a circle is computed as 2 * Pi * Radius and since the Radius is 1, then the Circumference is 2 * Pi - and thus we say that a Circle contains 2 * Pi Radians - so 1 Radian is the angle starting from the X Axis and measured counter clockwise such that the circumference transcribed on a unit circle equals one.

We noted earlier that there were 360 Degrees in a Circle, thus:

360° = 2 * Pi Radians

So to convert between Radians and Degrees we come up with the following two functions:

{ Converts an Angle in Radians into one in Degrees }
function
Rad2Deg (const Angle: Extended): Extended;
begin
  Result := Angle * 180 / Pi;
end;

{ Converts an Angle in Degrees into one in Radians }
function Deg2Rad (const Angle: Extended): Extended;
begin
  Result := Angle * Pi / 180;
end;

The Grad

Whilst not used that often these days, if you have a Scientific or Engineering Calculator, you may notice that you can put it into Degrees, Radians or Grads. So what is a Grad?

Well you can think of it like a "metric degree". A Grad is defined such that there is 100 Grads in a Right Angle, thus one Degree = 100 / 90 Grads.

So we can thus have the following conversions:

function Grad2Deg (const Angle: Extended): Extended;
begin
  Result := 0.9 * Angle;
end;

function Deg2Grad (const Angle: Extended): Extended;
begin
  Result := (100 / 90) * Angle;
end;

function Rad2Grad (const Angle: Extended): Extended;
begin
  Result := Angle * 200 / Pi;
end;

function Grad2Rad (const Angle: Extended): Extended;
begin
  Result := Angle * Pi / 200;
end;

MathRtns and Demo

MathsCorner.Zip  has been updated with this issue. It contains a Unit called MathRtns.Pas which contains all the routines so far covered in the Maths Corner as well as some extras.

You will also find Angles1 Project which demonstrates the above routines.

Conclusion

Next Issue we will continue our look at Angles, and in particular we are going to see where Minutes and Seconds come into things and how Latitude and Longitude work.

 

Maths Corner Home

 Copyright © 2001 Australian Delphi User Group and respective copyright owners.
All Rights Reserved | Disclaimer