Basic Mathematics for IT

Chapter 4
Geometry, Coordinate Systems and Trigonometry

Bachelors Program in IT
Basic Mathematics for IT   •   Bachelor

Geometry, Coordinate Systems and Trigonometry

Introduction

Geometry and trigonometry provide the mathematical language for representing shape, position, orientation, distance, and movement. In information technology, these ideas support computer graphics, user-interface layout, geographic information systems, robotics, animation, simulation, computer vision, game development, and spatial computing. A screen is a geometric coordinate plane; a robot arm is a system of linked vectors and angles; a 3D model is a collection of points, edges, surfaces, and transformations.

This chapter develops the essential geometric and trigonometric tools required to model such systems. It emphasizes not only calculation, but also coordinate conventions, units, assumptions, numerical interpretation, and implementation choices.

Learning Objectives

By the end of this chapter, you should be able to:

  1. Explain points, lines, angles, polygons, circles, and solids using precise terminology.
  2. Calculate perimeter, area, surface area, and volume in appropriate units.
  3. Use Cartesian, polar, cylindrical, and spherical coordinate systems.
  4. Calculate slopes, distances, midpoints, intersections, and equations of lines.
  5. Represent and manipulate two- and three-dimensional vectors.
  6. Apply trigonometric ratios, the law of sines, and the law of cosines.
  7. Use transformations and homogeneous coordinates in graphics and interfaces.
  8. Analyze a practical spatial-computing problem and identify limitations and implementation risks.

1. Geometric Foundations

A point identifies a location and has no dimensions. A line extends infinitely in two directions, while a line segment has two endpoints. A ray begins at one endpoint and extends infinitely in one direction. A plane is a flat two-dimensional surface extending without boundary.

An angle is formed by two rays with a common endpoint, called the vertex. Angles are commonly measured in degrees or radians. A complete revolution is 360° or 2π radians. The conversion relationships are:

180° = π radians

Thus, to convert degrees to radians, multiply by π/180; to convert radians to degrees, multiply by 180/π. Most programming libraries use radians for trigonometric functions.

A polygon is a closed plane figure made of line segments. A triangle has three sides, a quadrilateral four, and an n-gon n sides. The interior-angle sum of a simple n-sided polygon is:

S = (n − 2) × 180°

where n ≥ 3. For a regular polygon, in which all sides and angles are equal, each interior angle is:

α = ((n − 2) × 180°) / n

A circle is the set of points at a fixed distance r from a center. Its circumference and area are:

C = 2πr
A = πr²

Here r is the radius, C has linear units, and A has square units. These formulas assume a Euclidean plane and a true circle rather than a screen approximation.

Measurement and Units

Length may be measured in pixels, millimetres, metres, or other units. Area must use squared units and volume cubed units. A frequent programming error is mixing physical and display units. For example, a 100-pixel distance is not necessarily 100 millimetres; the relationship depends on display density and calibration.

Important formulas for common shapes are shown below.

ShapePerimeter or circumferenceAreaVolume
Rectangle, sides w and h2(w + h)wh—
Triangle, base b and height hsum of sides½bh—
Circle, radius r2πrπr²—
Rectangular box, dimensions l, w, h—surface area 2(lw + lh + wh)lwh
Cylinder, radius r and height h——πr²h
Sphere, radius r—surface area 4πr²4πr³/3

2. Coordinate Systems

A coordinate system assigns numbers to locations. The choice of system affects the simplicity of calculations and the interpretation of data.

Cartesian Coordinates

In a two-dimensional Cartesian system, a point is written (x, y). The x-axis is usually horizontal and the y-axis vertical. Their intersection is the origin (0, 0). In three dimensions, a point is (x, y, z), where z represents depth or height according to the application.

Computer graphics often use a screen coordinate system in which the origin is at the top-left, x increases to the right, and y increases downward. This differs from the conventional mathematical plane, where y usually increases upward. Neither convention is inherently incorrect, but transformations between them must be explicit.

Cartesian coordinate plane with a point and vector xy P(x, y)position vector O(0,0)
Cartesian coordinate plane with a point and vector
Figure: Cartesian coordinate plane with a point and vector

Figure: A Cartesian coordinate system representing a point and its position vector.

Polar Coordinates

A point can also be described by its distance r from the origin and angle θ measured from the positive x-axis. The notation is (r, θ). Conversion between polar and Cartesian coordinates is:

x = r cos θ
y = r sin θ
r = √(x² + y²)
θ = atan2(y, x)

The function atan2(y, x) is preferable to ordinary arctan(y/x) in software because it considers the signs of both coordinates and identifies the correct quadrant. The angle convention and units must be documented.

Cylindrical and Spherical Coordinates

Cylindrical coordinates describe a 3D point as (r, θ, z), combining polar coordinates in the xy-plane with height z. Spherical coordinates commonly use (ρ, θ, φ), but conventions differ. One widely used convention defines ρ as distance from the origin, θ as azimuth in the xy-plane, and φ as angle down from the positive z-axis:

x = ρ sin φ cos θ
y = ρ sin φ sin θ
z = ρ cos φ

A software system must state its convention because some fields use φ for azimuth and θ for inclination. Coordinate systems are not merely notation: inconsistent conventions can mirror, rotate, or misplace objects.

3. Coordinate Geometry

Distance and Midpoint

For points P₁(x₁, y₁) and P₂(x₂, y₂), the Euclidean distance is derived from the Pythagorean theorem:

d = √((x₂ − x₁)² + (y₂ − y₁)²)

The formula assumes a flat Euclidean plane and Cartesian coordinates. In three dimensions:

d = √((x₂ − x₁)² + (y₂ − y₁)² + (z₂ − z₁)²)

The midpoint is:

M = ((x₁ + x₂)/2, (y₁ + y₂)/2)

For weighted interpolation, a point fraction t of the way from A to B is:

P(t) = (1 − t)A + tB

where 0 ≤ t ≤ 1 gives a point on the segment. This operation, called linear interpolation or lerp, is widely used in animation and interface transitions.

Worked example. Let A(2, 3) and B(8, 11). The displacement is (6, 8), so the distance is √(6² + 8²) = √100 = 10 units. The midpoint is ((2 + 8)/2, (3 + 11)/2) = (5, 7). At t = 0.25, the interpolated point is (0.75)(2,3) + (0.25)(8,11) = (3.5,5).

Slope and Lines

For two distinct points, the slope is:

m = (y₂ − y₁)/(x₂ − x₁)

This formula applies only when x₂ ≠ x₁. A vertical line has undefined slope. A nonvertical line can be written in point-slope form:

y − y₁ = m(x − x₁)

or slope-intercept form y = mx + b, where b is the y-intercept. Parallel nonvertical lines have equal slopes. Perpendicular nonvertical lines have slopes whose product is −1, provided both slopes are defined.

For robust software, the implicit line equation is often useful:

Ax + By + C = 0

It avoids special treatment of vertical lines. The signed distance from point (x₀, y₀) to this line is:

d = (Ax₀ + By₀ + C) / √(A² + B²)

The absolute value gives ordinary distance; the sign identifies the side of the line.

Circles and Intersections

A circle centered at (h, k) with radius r has equation:

(x − h)² + (y − k)² = r²

Intersections between geometric objects are central to collision detection, hit testing, and computer-aided design. For example, a point lies inside or on a circle when its squared distance from the center is at most r². Comparing squared distances avoids a square-root operation and is usually more efficient in real-time code.

4. Vectors

A scalar has magnitude only; a vector has magnitude and direction. A 2D vector may be represented as v = (vₓ, vᵧ), and a 3D vector as v = (vₓ, vᵧ, v_z). A position is not always a vector conceptually, but the displacement from one position to another is a vector.

The magnitude, or norm, of a vector is:

‖v‖ = √(vₓ² + vᵧ²)

and in 3D:

‖v‖ = √(vₓ² + vᵧ² + vz²)

A unit vector in the direction of nonzero v is:

û = v / ‖v‖

Vector addition is componentwise. Scalar multiplication changes magnitude and possibly direction if the scalar is negative.

The dot product of a = (aₓ, aᵧ, a_z) and b = (bₓ, bᵧ, b_z) is:

a · b = aₓbₓ + aᵧbᵧ + azbz = ‖a‖‖b‖ cos θ

where θ is the angle between nonzero vectors. Therefore:

θ = arccos((a · b)/(‖a‖‖b‖))

The dot product supports lighting calculations, surface orientation, projection, and determining whether two directions are perpendicular. Numerical implementations should clamp the computed ratio to [−1, 1] before arccos because rounding may produce a value slightly outside this interval.

The 3D cross product is:

a × b = (aᵧbz − azbᵧ, azbₓ − aₓbz, aₓbᵧ − aᵧbₓ)

It produces a vector perpendicular to both a and b, with magnitude ‖a‖‖b‖sin θ. Its direction follows the right-hand rule. The cross product is defined in the usual useful form for 3D vectors; it is not a general 2D operation.

Projection of a onto nonzero b is:

projb(a) = ((a · b)/(b · b))b

This separates a vector into components parallel and perpendicular to a chosen direction.

5. Trigonometry

A right triangle has one 90° angle. For an acute angle θ, the basic ratios are:

sin θ = opposite / hypotenuse
cos θ = adjacent / hypotenuse
tan θ = opposite / adjacent

These definitions require a right triangle. The reciprocal functions are cosecant, secant, and cotangent, where defined. The identity:

sin² θ + cos² θ = 1

holds for all real θ when sine and cosine are defined using the unit circle.

For non-right triangles, the law of sines is:

a/sin A = b/sin B = c/sin C

where a, b, and c are opposite angles A, B, and C respectively. The law of cosines is:

c² = a² + b² − 2ab cos C

It generalizes the Pythagorean theorem. When C = 90°, cos C = 0 and c² = a² + b². The law of cosines is particularly useful when two sides and their included angle are known, or when all three sides are known and an angle is required.

Worked example. Suppose a drone moves 12 m east and 5 m north. Its displacement magnitude is √(12² + 5²) = 13 m. Its direction above east is tan-1(5/12) ≈ 22.62°. A program using atan2(5,12) obtains the same quadrant-correct direction. If the coordinate unit is metres, the result is a physical displacement; if it is pixels, it is a screen displacement.

6. Transformations in IT

A transformation maps geometric coordinates to new coordinates. Common 2D transformations are translation, scaling, rotation, and reflection.

Translation by (tₓ, tᵧ) is:

(x′, y′) = (x + tₓ, y + tᵧ)

Scaling about the origin by factors sₓ and sᵧ is:

(x′, y′) = (sₓx, sᵧy)

Rotation counterclockwise by θ about the origin is:

x′ = x cos θ − y sin θ
y′ = x sin θ + y cos θ

These formulas assume a Cartesian system with y upward and positive counterclockwise angles. In a screen system with y downward, the visual orientation may appear reversed unless the coordinate convention is incorporated.

Homogeneous coordinates represent a 2D point as (x, y, 1), allowing translation and other transformations to be expressed as matrix multiplication:

[x′, y′, 1]ᵀ =
[cos θ −sin θ tₓ;
sin θ cos θ tᵧ;
0 0 1][x, y, 1]ᵀ

The matrix combines rotation and translation. Transformations are generally non-commutative: rotating and then translating usually produces a different result from translating and then rotating. This is a major source of graphics errors. In 3D, 4×4 homogeneous matrices represent translation, rotation, scaling, camera transformations, and projection.

7. Applied Case: Interface Map and Robot Alignment

This is an illustrative case. A warehouse application displays a robot’s position on a 2D map. The physical warehouse uses metres with an origin at its southwest corner. The screen uses pixels with an origin at the top-left and y increasing downward.

Background and Problem

A robot reports position (6, 4) metres. The map covers 12 m by 8 m and is displayed in a 900 × 600 pixel panel. The interface must place the robot accurately and draw its heading.

Analysis

The horizontal scale is 900/12 = 75 pixels per metre, and the vertical scale is 600/8 = 75 pixels per metre. Thus the map has uniform scale, which avoids geometric distortion. The physical y-coordinate must be inverted for the screen:

xscreen = 75x
yscreen = 600 − 75y

For (6, 4), the screen position is (450, 300). If the robot heading is 30° above the physical east direction and its displayed arrow has length 45 pixels, the screen displacement is:

Δx = 45 cos 30° ≈ 38.97
Δy = −45 sin 30° = −22.5

The negative screen y-component is necessary because upward physical motion corresponds to decreasing pixel row numbers.

Approach and Solution

The implementation should:

  1. Define the physical origin, axes, units, and positive angle direction.
  2. Convert metres to pixels using a documented affine transformation.
  3. Invert y when mapping from a bottom-up physical coordinate system to a top-down screen system.
  4. Use atan2 for measured headings and normalize angles consistently.
  5. Test known landmarks, boundary positions, and mirrored-coordinate failures.
  6. Keep geometric data in physical units and convert only at the rendering boundary.

Outcome

The robot is rendered at pixel (450, 300), and its arrow ends approximately at (488.97, 277.5). The map remains proportional because both scale factors are equal.

Learning Points

The principal difficulty is not arithmetic but convention management. A correct formula applied to the wrong axis direction creates a plausible but incorrect interface. Explicit units, coordinate documentation, and test cases are therefore part of mathematical correctness.

8. Limitations, Reliability, and Professional Practice

Real systems rarely use exact real numbers. Floating-point representation introduces small errors, especially after repeated transformations. Use tolerances when testing equality. Instead of asking whether two values are exactly equal, test whether their absolute difference is below an application-appropriate tolerance.

Angles require special care. Degrees are convenient for explanation, but most software functions expect radians. Normalize angles only when the application requires a particular interval, such as [0, 2π) or (−π, π].

Coordinate transformations should be centralized rather than repeated inconsistently throughout an application. Every geometric data structure should document its coordinate frame, units, handedness, axis directions, and reference origin. In robotics and spatial computing, transformations between frames should be named and validated.

Geometric data may also raise privacy and governance concerns. Location traces, camera-based spatial maps, and indoor positioning data can identify people or sensitive facilities. Systems should minimize collection, protect stored coordinates, control access, and communicate how spatial data is used. AI-based vision and mapping systems should be tested for bias, calibration failure, and unsafe behavior; mathematical confidence does not guarantee physical correctness.

Contemporary Applications

Geometry and trigonometry remain foundational in:

  • 2D and 3D rendering, where vertices, normals, camera rays, and projections are calculated.
  • User interfaces, where bounding boxes, alignment, hit testing, and responsive layouts depend on coordinates.
  • Robotics, where forward and inverse kinematics relate joint angles to end-effector positions.
  • Geographic information systems, where coordinate reference systems and map projections affect distance and area.
  • Augmented and virtual reality, where sensor frames, head pose, field of view, and spatial anchors must be aligned.
  • Computer vision, where image points are transformed between camera, world, and object coordinates.
  • Simulation and games, where vectors control velocity, forces, collision response, and interpolation.

Best practice is to select the simplest coordinate system for the operation, preserve units, distinguish points from vectors, use numerically stable functions such as atan2, and validate transformations with visual and numerical tests.

Chapter Summary

Geometry describes form, measurement, and spatial relationships. Cartesian coordinates provide a direct representation of position, while polar, cylindrical, and spherical systems can simplify radial and 3D problems. Distance, midpoint, slope, line, and circle equations support layout, collision detection, mapping, and analysis.

Vectors represent magnitude and direction. Their magnitude, dot product, cross product, projection, and normalization are central to graphics, robotics, and simulation. Trigonometric ratios apply to right triangles, while the laws of sines and cosines extend analysis to general triangles. Transformations translate, scale, rotate, and reflect objects; homogeneous coordinates combine these operations in matrix form.

Reliable IT implementations require explicit coordinate conventions, consistent units, careful angle handling, attention to floating-point error, and testing across coordinate frames. These mathematical practices are also important for safe and ethical use of location and spatial data.

Key Terms

Point: A dimensionless location in space.

Line segment: A portion of a line bounded by two endpoints.

Angle: A figure formed by two rays sharing a vertex.

Polygon: A closed plane figure made from line segments.

Cartesian coordinates: Coordinates measured along perpendicular axes.

Polar coordinates: A radius and angle used to locate a point.

Cylindrical coordinates: Polar coordinates combined with a height coordinate.

Spherical coordinates: A radial distance and two angles locating a 3D point.

Slope: The change in y divided by the change in x.

Euclidean distance: Straight-line distance in a flat space.

Vector: A quantity with magnitude and direction.

Unit vector: A vector with magnitude one.

Dot product: A scalar product measuring directional alignment.

Cross product: A 3D vector perpendicular to two input vectors.

Interpolation: Estimation of a value between known values.

Radians: An angular unit based on arc length and radius.

Transformation: A mapping that changes geometric coordinates.

Homogeneous coordinates: An augmented coordinate representation enabling matrix-based affine transformations.

Coordinate frame: A defined origin, axis orientation, unit system, and handedness.

Review Questions

Short Answer Questions

  1. Distinguish a point, a line segment, and a ray.
  2. Convert 90° to radians and explain why programming libraries commonly use radians.
  3. State the distance formula for two points in three-dimensional Cartesian space.
  4. What information does the dot product provide about two nonzero vectors?
  5. Why is atan2 generally safer than arctan(y/x) for computing a direction?

Long Answer Questions

  1. Explain Cartesian, polar, cylindrical, and spherical coordinate systems, including one suitable IT application for each.
  2. Derive the 2D distance formula from the Pythagorean theorem and discuss its assumptions.
  3. Explain translation, scaling, and rotation and show how homogeneous coordinates combine rotation with translation.
  4. Compare the law of sines and the law of cosines, including the types of triangle information for which each is useful.
  5. Discuss how inconsistent coordinate conventions can create errors in graphics or robotics systems and propose testing practices.

Analytical / Application Questions

  1. A 2D game object moves from (−3, 4) to (5, 10). Calculate its displacement vector, distance, midpoint, and direction measured from the positive x-axis.
  2. A rectangular map represents 20 m by 12 m in a 1000 × 600 pixel panel. Design the coordinate conversion from a bottom-left physical origin to a top-left screen origin, and explain how you would test it.
  3. Two unit direction vectors have dot product 0.6. Determine their angle in degrees and explain what this implies about their directional alignment.

Multiple Choice Questions with Answers

Question 1

A point moves from (2, 3) to (8, 11). What is the Euclidean distance between the points?

A. 8 units

B. 10 units

C. 12 units

D. 14 units

Correct Answer: B. 10 units

Question 2

Which function is generally preferred for finding the quadrant-correct angle of a vector (x, y)?

A. sin(x/y)

B. cos(y/x)

C. atan2(y, x)

D. √(x² + y²)

Correct Answer: C. atan2(y, x)

Question 3

What is the polar-coordinate representation of the Cartesian point (3, 4), using a positive radius?

A. (5, approximately 53.13°)

B. (7, approximately 36.87°)

C. (5, approximately 36.87°)

D. (4, approximately 53.13°)

Correct Answer: A. (5, approximately 53.13°)

Question 4

If two nonzero vectors have a dot product of zero, they are:

A. parallel

B. perpendicular

C. equal in magnitude

D. opposite in direction

Correct Answer: B. perpendicular

Question 5

Which formula gives the area of a circle of radius r?

A. 2πr

B. πr

C. πr²

D. 4πr²

Correct Answer: C. πr²

Question 6

In a screen coordinate system where y increases downward, physical upward motion generally maps to:

A. increasing screen y

B. decreasing screen y

C. zero screen y

D. reversing screen x only

Correct Answer: B. decreasing screen y

Question 7

What is the result of rotating the point (1, 0) counterclockwise by 90° about the origin?

A. (0, 1)

B. (0, −1)

C. (1, 1)

D. (−1, 0)

Correct Answer: A. (0, 1)

Question 8

Which law is most directly suited to finding a side when two sides and their included angle are known?

A. Law of sines

B. Law of cosines

C. Polygon-angle formula

D. Distance-to-line formula

Correct Answer: B. Law of cosines

Question 9

A vector (6, 8) has magnitude:

A. 8

B. 10

C. 12

D. 14

Correct Answer: B. 10

Question 10

Why are squared distances often compared in collision detection?

A. They change the geometry into polar coordinates

B. They eliminate the need for a square-root operation

C. They convert metres into pixels automatically

D. They work only for vertical lines

Correct Answer: B. They eliminate the need for a square-root operation

Basic Mathematics for IT
Chapter 4 of 15