Undergraduate Topics in Computer Science

Series Editor

Ian Mackie

University of Sussex, Brighton, France

Advisory Editors

Samson Abramsky

Department of Computer Science, University of Oxford, Oxford, UK

Chris Hankin

Department of Computing, Imperial College London, London, UK

Mike Hinchey

Lero—The Irish Software Research Centre, University of Limerick, Limerick, Ireland

Dexter C. Kozen

Department of Computer Science, Cornell University, Ithaca, USA

Hanne Riis Nielson

Department of Applied Mathematics and Computer Science, Technical University of Denmark, Kongens Lyngby, Denmark

Steven S. Skiena

Department of Computer Science, Stony Brook University, Stony Brook, USA

Iain Stewart

Department of Computer Science, Durham University, Durham, UK

Joseph Migga Kizza

Engineering and Computer Science, University of Tennessee at Chattanooga, Chattanooga, USA

Roy Crole

School of Computing and Mathematics Sciences, University of Leicester, Leicester, UK

Elizabeth Scott

Department of Computer Science, Royal Holloway University of London, Egham, UK

‘Undergraduate Topics in Computer Science’ (UTiCS) delivers high-quality instructional content for undergraduates studying in all areas of computing and information science. From core foundational and theoretical material to final-year topics and applications, UTiCS books take a fresh, concise, and modern approach and are ideal for self-study or for a one- or two-semester course. The texts are authored by established experts in their fields, reviewed by an international advisory board, and contain numerous examples and problems, many of which include fully worked solutions.

The UTiCS concept centers on high-quality, ideally and generally quite concise books in softback format. For advanced undergraduate textbooks that are likely to be longer and more expository, Springer continues to offer the highly regarded Texts in Computer Science series, to which we refer potential authors.

John Vince

Mathematics for Computer Graphics

Seventh Edition 2025

John Vince

Breinton, UK

ISSN 1863-7310e-ISSN 2197-1781

Undergraduate Topics in Computer Science

ISBN 978-1-4471-7549-0e-ISBN 978-1-4471-7550-6

https://doi.org/10.1007/978-1-4471-7550-6

© The Editor(s) (if applicable) and The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2001, 2006, 2010, 2014, 2017, 2022, 2025

The author(s) has/have asserted their right(s) to be identified as the author(s) of this work in accordance with the Copyright, Designs and Patents Act 1988.

This work is subject to copyright. All rights are solely and exclusively licensed by the Publisher, whether the whole or part of the material is concerned, specifically the rights of translation, reprinting, reuse of illustrations, recitation, broadcasting, reproduction on microfilms or in any other physical way, and transmission or information storage and retrieval, electronic adaptation, computer software, or by similar or dissimilar methodology now known or hereafter developed.

The use of general descriptive names, registered names, trademarks, service marks, etc. in this publication does not imply, even in the absence of a specific statement, that such names are exempt from the relevant protective laws and regulations and therefore free for general use.

The publisher, the authors and the editors are safe to assume that the advice and information in this book are believed to be true and accurate at the date of publication. Neither the publisher nor the authors or the editors give a warranty, expressed or implied, with respect to the material contained herein or for any errors or omissions that may have been made. The publisher remains neutral with regard to jurisdictional claims in published maps and institutional affiliations.

This Springer imprint is published by the registered company Springer-Verlag London Ltd., part of Springer Nature.

The registered company address is: The Campus, 4 Crinan Street, London, N1 9XW, United Kingdom

This book is dedicated currently, to three women in my life: Marie, Emily and Heidi.

Preface

The first edition of this book began life as part of Springer’s Essential series, and contained ten chapters and approximately 220 pages. The sixth edition had 20 chapters and approximately 600 pages, and this seventh, and really the last edition, contains a two extra chapters. Over the intervening editions I have revised and extended previous descriptions, introduced new chapters on subjects that I believe are relevant to computer graphics, such as differential calculus and interpolation, and new subjects that I had to learn about, such as quaternions, statistics, Fourier analysis, and geometric algebra. Hopefully, this edition explores enough mathematical ideas to satisfy most people working in computer graphics.

Although the first edition of this book was produced on a humble PC using WORD, subsequent editions were produced on an Apple iMac using LATEX. I recommend to any budding authors that they should learn LATEX, and use Springer’s templates to create their first manuscript. Furthermore, today’s computers are so fast that I often compile the entire book for the sake of changing a single character—it only takes 5 or 6 seconds!

I have used colour in the text to emphasise the patterns behind certain numbers, and in the illustrations to clarify the mathematics.

It is extremely difficult to ensure that there are no spelling mistakes, missing brackets, spurious punctuation marks, and above all, mathematical errors. I truly have done my best to correct the text and associated equations, but if I have missed some, then I apologise now.

In all of my books I try to mention the names of important mathematicians associated with an invention or discovery, and the period over which they were alive. In this book I mention 50 such people, and the relevant dates are attached to the first citation.

Whilst writing this book I have borne in mind what it was like for me when I was studying different areas of mathematics for the first time. In spite of reading and rereading an explanation several times it could take days before ‘the penny dropped’ and a concept became apparent. Hopefully, the reader will find the following explanations useful in developing their understanding of these specific areas of mathematics, and enjoy the sound of various pennies dropping!

I would like to thank Helen Desmond, Editor for Computer Science, for allowing me to give up holidays and hobbies in order to complete another book!

John Vince

Breinton, UK

October 2024

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_1

1. Introduction

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

1.1 Mathematics for Computer Graphics

Computer graphics contains many areas of specialism such as data visualisation, computer animation, film special effects, computer games and virtual reality. Fortunately, not everyone working in computer graphics requires a knowledge of mathematics, but those that do, often look for a book that introduces them to some basic ideas of mathematics, without turning them into mathematicians. This is the objective of this book. Over the following chapters I introduce the reader to some useful mathematical topics that will help them understand the software they work with, and how to solve a wide variety of geometric and algebraic problems. These topics include numbers systems, algebra, trigonometry, 2D and 3D geometry, vectors, equations, matrices, complex numbers, determinants, transforms, quaternions, interpolation, curves, patches and calculus. I have written about some of these topics to a greater level of detail in other books, which you may be interested in exploring.

1.2 Understanding Mathematics

One of the problems with mathematics is its incredible breadth and depth. It embraces everything from geometry, calculus, topology, statistics, complex functions to number theory and propositional calculus. All of these subjects can be studied superficially or to a mind-numbing complexity. Fortunately, no one is required to understand everything, which is why mathematicians tend to specialise in one or two areas and develop a specialist knowledge. If it’s any comfort, even Einstein asked friends and colleagues to explain branches of mathematics to help him with his theories.

1.3 What Makes Mathematics Difficult?

‘What makes mathematics difficult?’ is a difficult question to answer, but one that has to be asked and answered. There are many answers to this question, and I believe that problems begin with mathematical notation and how to read it; how to analyse a problem and express a solution using mathematical statements. Unlike learning a foreign language–which I find very difficult–mathematics is a language that needs to be learned by discovering facts and building upon them to discover new facts. Consequently, a good memory is always an advantage, as well as a sense of logic.

Mathematics can be difficult for anyone, including mathematicians. For example, when the idea of -1 was originally proposed, it was criticised and looked down upon by mathematicians, mainly because its purpose was not fully understood. Eventually, it transformed the entire mathematical landscape, including physics. Similarly, when the German mathematician Georg Cantor (1845–1919), published his papers on set theory and transfinite sets, some mathematicians hounded him in a disgraceful manner. The German mathematician Leopold Kronecker (1823–1891), called Cantor a ‘scientific charlatan’, a ‘renegade’, and a ‘corrupter of youth’, and did everything to hinder Cantor’s academic career [1]. Similarly, the French mathematician and physicist Henri Poincaré (1854–1912), called Cantor’s ideas a ‘grave disease’, [2] whilst the Austrian-British philosopher and logician Ludwig Wittgenstein (1889–1951), complained that mathematics is ‘ridden through and through with the pernicious idioms of set theory’ [3]. How wrong they all were. Today, set theory is a major branch of mathematics and has found its way into every math curriculum. So don’t be surprised to discover that some mathematical ideas are initially difficult to understand–you are in good company.

1.4 Background to this Book

During my working life in computer animation I came across a wide range of students with an equally wide range of mathematical knowledge. Some students possessed a rudimentary background in mathematics, while others had been taught calculus and supporting subjects. Teaching such a cohort the mathematics of computer graphics was a challenge, to say the least, but somehow I did. By the end of a three-year undergraduate course they were competent programmers and could program a wide variety of mathematical techniques. The first-edition of this book employed much of my teaching material and has been revised and extended.

1.5 How to Use this Book

Initially, I’d recommend to any reader to start at the beginning and start reading chapters on subjects with which they are familiar. One never knows what may be learnt from reading about a familiar subject by a non-mathematician. For those readers with a good background in mathematics, should quick read chapters on topics covered else-where, and settle down on new topics. However you approach this book, I sincerely hope that you discover something new that increases your knowledge of the subject.

1.6 Symbols and Notation

One of the reasons why many people find mathematics inaccessible is due to its symbols and notation. Let’s look at symbols first. The English alphabet possesses a reasonable range of familiar character shapes:

a,b,c,d,e,f,g,h,i,j,k,l,m,n,o,p,q,r,s,t,u,v,w,x,y,z

A,B,C,D,E,F,G,H,I,J,K,L,M,N,O,P,Q,R,S,T,U,V,W,X,Y,Z

which find their way into every branch of mathematics and physics, and permit us to write equations such as:

E=mc2

and

A=πr2

It is important that when we see an equation, we are able to read it as part of the text. In the case of E=mc2, this is read as ‘E equals m, c squared’, where E stands for energy, m for mass, c the speed of light, which is multiplied by itself. In the case of A=πr2, this is read as ‘A equals pi, r squared’, where A stands for area, π the ratio of a circle’s circumference to its diameter, and r the circle’s radius. Greek symbols, which happen to look nice and impressive, have also found their way into many equations, and often disrupt the flow of reading, simply because we don’t know their English names. For example, the English theoretical physicist Paul Dirac (1902–1984), derived an equation for a moving electron using the symbols αi and β, which are 4×4 matrices, where:

αiβ+βαi=0

and is read as:

‘the sum of the products alpha-i beta, and beta alpha-i, equals zero.’

Although we do not come across moving electrons in this book, we do have to be familiar with the following Greek symbols:

and some upper-case symbols:

Being able to read an equation does not mean that we understand it–but we are a little closer than just being able to stare at a jumble of symbols! Therefore, in future, when I introduce a new mathematical object, I will tell you how it should be read.

References

1.

Dauben JW (1979) Georg Cantor his mathematics and philosophy of the infinite. Princeton University Press

2.

Dauben JW (2004) Georg Cantor and the battle for transfinite set theory (PDF). In: Proceedings of the 9th ACMS conference. Westmont College, Santa Barbara, Calif., p 122

3.

Rodych V (2007) Wittgenstein’s philosophy of mathematics. In: Zalta EN (ed) The stanford encyclopedia of philosophy. Metaphysics Research Lab, Stanford University

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_2

2. Numbers

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

2.1 Introduction

This chapter revises sets, and the sets of numbers employed in mathematics such as natural, integer, rational, irrational, real, algebraic, transcendental, imaginary, complex, quaternions and octonions. It also describes how these numbers behave in the context of three laws: commutative, associative and the distributive law.

As prime numbers find their way into all aspects of cryptography, and who knows what else, the chapter introduces the fundamental theorem of arithmetic, prime number distribution, perfect numbers and Mersenne numbers. The chapter concludes with the concept of infinity and some worked examples.

2.2 Sets

In  mathematics, a collection of elements or members is a set. For example, if S is the set containing the elements A, B, C, D, E, we can state that:

A∈SB∈SC∈SD∈SE∈S

where ∈ stands for ‘is a member of’ whereas:

F∉S

∉ stands for ‘is not a member of’.

The set S is written S={A,B,C,D,E}, and to isolate the elements A, B, C, we can say that the set {A,B,C} is a subset of S.

2.3 Counting

To    count the members of a set we perform a one-to-one correspondence {bijection}, with the subset of positive integers {1,2,3,⋯,n}. Thus, if we reach 23 in the one-to-one correspondence with the positive integers, there are 23 members. This is counting in mathematics.

Our parents normally teach us to count by first memorising the counting words one, two, three, four, five, six, seven, eight, nine, ten, etc., and second, associating them with our fingers, so that when asked to count the number of elements in a picture book, each element is associated with a counting word. When the process is complete, the number of elements equals the last counting word reached. However, this still assumes that we know the meaning of one, two, three, four, etc. Memorising these counting words is only part of the problem–getting them in the correct sequence is the real challenge! Later on in this chapter we discover alternative sets of positive integers to the base of 10 employed in every-day mathematics.

A well-ordered set possesses a unique order, such as the set of natural numbers N. Therefore, if P is the well-ordered set of prime numbers and N is the well-ordered set of natural numbers, we can write:

P={2,3,5,7,11,13,17,19,23,29,31,37,41,43,47,⋯}N={1,2,3,4,5,6,7,8,9,10,11,12,13,14,15,16,17,⋯}

By pairing the prime numbers in P with the numbers in N, we have:

{2,1},{3,2},{5,3},{7,4},{11,5},{13,6},{17,7},{19,8},{23,9},⋯

and we can reason that 2 is the 1st prime, and 3 is the 2nd prime, etc. However, we still have to declare what we mean by 1,2,3,4,5, etc., and without getting too philosophical, I like the idea of defining them as follows. The word one, represented by 1, stands for one-ness of anything: one finger, one house, one tree, one donkey, etc. The word two, represented by 2, is ‘one more than one.’ The word three, represented by 3, is ‘one more than two,’ and so on.

We are now in a position to associate some mathematical notation with our numbers by introducing the + and = signs. We know that + means add, but it also can stand for more. We also know that = means equal, and it can also stand for is the same as. Thus the statement:

2=1+1

is read as ‘two equals one more than one’.

We can also write:

3=1+2

which is read as ‘three equals one more than two.’ But as we already have a definition for 2, we can write:

3=1+2=1+1+1

Developing this idea, and including some extra combinations, we have:

2=1+13=1+24=1+3=2+25=1+4=2+36=1+5=2+4=3+37=1+6=2+5=3+4etc.

and can be continued without limit.

2.4 Zero

The  concept of zero has a well-documented history, which shows that it has been used by different cultures over a period of two-thousand years or more. It was the Indian mathematician and astronomer Brahmagupta (598-c.–670), who argued that zero was just as valid as any natural number, with the definition: the result of subtracting any number from itself. However, even today, there is no universal agreement as to whether zero belongs to the set N, consequently, the set N0 stands for the set of natural numbers including zero.

In today’s positional decimal system, which is a place value system, the digit 0 is a placeholder. For example, 203 stands for: two hundreds, no tens and three units. Although 0∈N0, it does have special properties that distinguish it from other members of the set, and Brahmagupta also gave rules showing this interaction.

If x∈N0, then the following rules apply:

additionx+0=xsubtractionx-0=xmultiplicationx×0=0×x=0division0/x=0undefineddivisionx/0

The expression 0/0 is called an indeterminate form, as it is possible to show that under different conditions, especially limiting conditions, it can equal anything. So for the moment, we will avoid using it until we cover calculus.

2.5 Negative Numbers

When  negative numbers were first proposed, they were not accepted with open arms, as it was difficult to visualise -5 of something. For instance, if there are 5 donkeys in a field, and they are all stolen, the field is now empty, and there is nothing we can do in the arithmetic of donkeys to create a field of -3 donkeys. But may be we should be using natural numbers to represent the number of donkeys. However, in applied mathematics, numbers have to represent all sorts of quantities such as temperature, displacement, angular rotation, speed, acceleration, etc., and we also need to incorporate ideas such as left and right, up and down, before and after, forwards and backwards, etc. Fortunately, negative numbers are perfect for representing all of the above quantities and ideas.

Consider the expression 4-x, where x∈N0. When x takes on certain values, we have:

4-1=34-2=24-3=14-4=0

and unless we introduce negative numbers, we are unable to express the result of 4-5. Consequently, negative numbers are visualised as shown in Fig. 2.1, where the number line shows negative numbers to the left of the natural numbers, which are positive, although the + sign is omitted for  clarity.

Fig. 2.1

The number line

Moving from left to right, the number line provides a numerical continuum from large negative numbers, through zero, towards large positive numbers. In any calculation we could agree that angles above the horizon are positive, and angles below the horizon, negative. Similarly, a movement forwards is positive, and a movement backwards is negative. So now we are able to write:

4-5=-14-6=-24-7=-3etc.

without worrying about creating impossible conditions.

2.5.1 The Arithmetic of Positive and Negative Numbers

Once       again, Brahmagupta compiled all the rules, Tables 2.1 and 2.2, supporting the addition, subtraction, multiplication and division of positive and negative numbers. The real fly in the ointment, being negative numbers, which cause problems for children, math teachers and occasional accidents for mathematicians. Perhaps, the one rule we all remember from our school days is that ‘two negatives make a positive.’ We can show that this is true by first assuming that two negatives make a negative:

-2×-3=(4-6)(4-7)-6≠16-24-28-42

which is nonsense. However, if we assume that two negatives make a positive:

-2×-3=(4-6)(4-7)6=16-24-28+42

which is true. Naturally, there is a formal way of proving this.

Another problem with negative numbers arises when we employ the square-root function. As the product of two positive or negative numbers results in a positive result, the square-root of a positive number gives rise to a positive and a negative answer. For example, 4=±2. This means that the square-root function only applies to positive numbers. Nevertheless, it did not stop the invention of the imaginary unit i, where i2=-1. However, i is not a number, but an operator, and is described later.

Table 2.1

Rules for adding and subtracting positive and negative numbers

+

b

-b

−

b

-b

a

a+b

a-b

a

a-b

a+b

-a

b-a

-(a+b)

-a

-(a+b)

b-a

Table 2.2

Rules for multiplying and dividing positive and negative numbers

×

b

-b

/

b

-b

a

ab

-ab

a

a/b

-a/b

-a

-ab

ab

-a

-a/b

a/b

2.6 Axioms

The following axioms or laws provide a formal basis for mathematics, and in the descriptions a binary operation is an arithmetic operation such as: +,-,×,/ which operate on two operands.

2.6.1 Commutative Law

The commutative law in algebra states that when two elements are linked through some binary operation, the result is independent of the order of the elements.

The commutative law of addition is:

a+b=b+ae.g.1+2=2+1

The commutative law of multiplication is:

a×b=b×ae.g.1×2=2×1

Note that subtraction is not commutative:

a-b≠b-ae.g.1-2≠2-1

2.6.2 Associative Law

The associative law in algebra states that when three or more elements are linked together through a binary operation, the result is independent of how each pair of elements is grouped.

The associative law of addition is:

a+(b+c)=(a+b)+ce.g.1+(2+3)=(1+2)+3

The associative law of multiplication is:

a×(b×c)=(a×b)×ce.g.1×(2×3)=(1×2)×3

However, note that subtraction is not associative:

a-(b-c)≠(a-b)-ce.g.1-(2-3)≠(1-2)-3

Which may seem surprising, but at the same time confirms the need for clear axioms.

2.6.3 Distributive Law

The distributive law in algebra describes an operation which when performed on a combination of elements is the same as performing the operation on the individual elements. The distributive law does not work in all cases of arithmetic. For example, multiplication over addition holds:

a(b+c)=ab+ace.g.2(3+4)=6+8

Whereas addition over multiplication does not:

a+(b×c)≠(a+b)×(a+c)e.g.3+(4×5)≠(3+4)×(3+5)

Although these laws are natural for numbers, they do not necessarily apply to all mathematical objects. For instance, the vector product, which multiplies two vectors together, is not generally commutative. The same applies for matrix multiplication.

2.7 The Base of a Number System

2.7.1 Background

Over recent millennia, mankind has invented and discarded many systems for representing number. People have counted on their fingers and toes, used pictures (hieroglyphics), cut marks on clay tablets (cuneiform symbols), employed Greek symbols (Ionic system) and struggled with, and abandoned Roman numerals (I, V, X, L, C, D, M, etc.), until we reach today’s decimal place system, which has Hindu-Arabic and Chinese origins. And since the invention of computers we have witnessed the emergence of binary, octal and hexadecimal number systems, where 2, 8 and 16 respectively, replace the 10 in our decimal system.

The decimal number 23 stands for ‘two tens and three units’, and in English is written ‘twenty-three’, in French ‘vingt-trois’ (twenty-three), and in German ‘dreiundzwanzig’ (three and twenty). Let’s investigate the algebra behind the decimal system and see how it can be used to represent numbers to any base. The expression:

a×1000+b×100+c×10+d×1

where a, b, c, d take on any value between 0 and 9, describes any whole number between 0 and 9999. By including:

e×0.1+f×0.01+g×0.001+h×0.0001

where e, f, g, h take on any value between 0 and 9, any decimal number between 0 and 9999.9999 can be represented.

Indices bring the notation alive and reveal the true underlying pattern:

⋯a103+b102+c101+d100+e10-1+f10-2+g10-3+h10-4⋯

Remember that any number raised to the power 0 equals 1. By adding extra terms both left and right, any number can be accommodated.

In this example, 10 is the base, which means that the values of a to h range between 0 and 9, 1 less than the base. Therefore, by substituting B for the base we have:

⋯aB3+bB2+cB1+dB0+eB-1+fB-2+gB-3+hB-4⋯

where the values of a to h range between 0 and B-1.

2.7.2 Octal Numbers

The  octal number system has B=8, and a to h range between 0 and 7:

⋯a83+b82+c81+d80+e8-1+f8-2+g8-3+h8-4⋯

and the first 17 octal numbers are:

18,28,38,48,58,68,78,108,118,128,138,148,158,168,178,208,218

The subscript 8 reminds us that although we may continue to use the words ‘twenty-one’, it is an octal number, and not a decimal. But what is 148 in decimal? Well, it stands for:

1×81+4×80=12

Thus 356.48 is converted to decimal as follows:

(3×82)+(5×81)+(6×80)+(4×8-1)(3×64)+(5×8)+(6×1)+(4×0.125)(192+40+6)+(0.5)238.5

Counting in octal appears difficult, simply because we have never been exposed to it, like the decimal system. If we had evolved with 8 fingers, instead of 10, we would be counting in octal!

2.7.3 Binary Numbers

The  binary number system has B=2, and a to h are 0 or 1:

⋯a23+b22+c21+d20+e2-1+f2-2+g2-3+h2-4⋯

and the first 13 binary numbers are:

12,102,112,1002,1012,1102,1112,10002,10012,10102,10112,11002,11012

Thus 11011.112 is converted to decimal as follows:

1×24+1×23+0×22+1×21+1×20+1×2-1+1×2-2(1×16)+(1×8)+(0×4)+(1×2)+(1×0.5)+(1×0.25)(16+8+2)+(0.5+0.25)26.75

The reason why computers work with binary numbers–rather than decimal–is due to the difficulty of designing electrical circuits that can store decimal numbers in a stable fashion. A switch, where the open state represents 0, and the closed state represents 1, is the simplest electrical component to emulate. No matter how often it is used, or how old it becomes, it will always, generally, behave like a switch. The main advantage of electrical circuits is that they can be switched on and off trillions of times a second, and the only disadvantage is that the encoded binary numbers and characters contain a large number of bits, and humans are not familiar with binary.

2.7.4 Hexadecimal Numbers

The  hexadecimal number system has B=16, and a to h can be 0 to 15, which presents a slight problem, as we don’t have 15 different numerical characters. Consequently, we use 0 to 9, and the letters A, B, C, D, E, F to represent 10, 11, 12, 13, 14, 15 respectively:

⋯a163+b162+c161+d160+e16-1+f16-2+g16-3+h16-4⋯

and the first 17 hexadecimal numbers are:

116,216,316,416,516,616,716,816,916,A16,B16,C16,D16,E16,F16,1016,1116

Thus 1E.816 is converted to decimal as follows:

(1×16)+(E×1)+(8×16-1)(16+14)+(8/16)30.5

Although it is not obvious, binary, octal and hexadecimal numbers are closely related, which is why they are part of a programmer’s toolkit. Even though computers work with binary, it’s the last thing a programmer wants to use. So to simplify the man-machine interface, binary is converted into octal or hexadecimal. To illustrate this, let’s convert the 16-bit binary code 1101011000110001 into octal.

Using the following general binary integer:

a28+b27+c26+d25+e24+f23+g22+h21+i20

we group the terms into threes, starting from the right, because 23=8:

a28+b27+c26+d25+e24+f23+g22+h21+i20

Simplifying:

26a22+b21+c20+23d22+e21+f20+20g22+h21+i2082a22+b21+c21+81d22+e21+f20+80g22+h21+i2082R+81S+80T

where:

R=a22+b21+cS=d22+e21+fT=g22+h21+i

and the values of R, S, T vary between 0 and 7. Therefore, given 1101011000110001, we divide the binary code into groups of three, starting at the right, and adding two leading zeros:

(001)(101)(011)(000)(110)(001)

For each group, multiply the zeros and ones by 4, 2, 1, right to left:

(0+0+1)(4+0+1)(0+2+1)(0+0+0)(4+2+0)(0+0+1)(1)(5)(3)(0)(6)(1)1530618

Therefore, 11010110001100012≡1530618, (≡ stands for ‘equivalent to’) which is much more compact. The secret of this technique is to memorise these patterns:

0002≡080012≡180102≡280112≡381002≡481012≡581102≡681112≡78

Here are a few more examples, with the binary digits grouped in threes:

1112≡781011012≡5581000002≡4081110001110001112≡707078

It’s just as easy to reverse the process, and convert octal into binary. Here are some examples:

5678≡1011101112238≡010011217418≡0011111000012

A similar technique is used to convert binary to hexadecimal, but this time we divide the binary code into groups of four, because 24=16, starting at the right, and adding leading zeros, if necessary. To illustrate this, let’s convert the 16-bit binary code 1101011000110001 into hexadecimal.

Using the following general binary integer number:

a211+b210+c29+d28+e27+f26+g25+h24+i23+j22+k21+l20

from the right, we divide the binary code into groups of four:

a211+b210+c29+d28+e27+f26+g25+h24+i23+j22+k21+l20

Simplifying:

28a23+b22+c21+d20+24e23+f22+g21+h20+20i23+j22+k21+l20162a23+b22+c21+d+161e23+f22+g21+h+160i23+j22+k21+l162R+161S+160T

where:

R=a23+b22+c21+dS=e23+f22+g21+hT=i23+j22+k21+l

and the values of R, S, T vary between 0 and 15. Therefore, given 11010110001100012, we divide the binary code into groups of fours, starting at the right:

(1101)(0110)(0011)(0001)

For each group, multiply the zeros and ones by 8, 4, 2, 1 respectively, right to left:

(8+4+0+1)(0+4+2+0)(0+0+2+1)(0+0+0+1)(13)(6)(3)(1)D63116

Therefore, 11010110001100012≡D63116, which is even more compact than its octal value 1530618.

I have deliberately used whole numbers in the above examples, but they can all be extended to include a fractional part. For example, when converting a binary number such as 11.11012 to octal, the groups are formed about the binary point:

(011).(110)(100)≡3.648

Similarly, when converting a binary number such as 101010.1001102 to hexadecimal, the groups are also formed about the binary point:

(0010)(1010).(1001)(1000)≡2A.9816

Table 2.3 shows the first twenty decimal, binary, octal and hexadecimal numbers.

Table 2.3

The first twenty decimal, binary, octal, and hexadecimal numbers

Decimal

Binary

Octal

Hex

Decimal

Binary

Octal

Hex

1

1

1

1

11

1011

13

B

2

10

2

2

12

1100

14

C

3

11

3

3

13

1101

15

D

4

100

4

4

14

1110

16

E

5

101

5

5

15

1111

17

F

6

110

6

6

16

10000

20

10

7

111

7

7

17

10001

21

11

8

1000

10

8

18

10010

22

12

9

1001

11

9

19

10011

23

13

10

1010

12

A

20

10100

24

14

2.7.5 Adding Binary Numbers

When we are first taught the addition of integers containing several digits, we are advised to solve the problem digit by digit, working from right to left. For example, to add 254 to 561 we write:

561

254

815

where 4+1=5, 5+6=1 with a carry=1, 2+5+carry=8.

Table 2.4 shows all the arrangements for adding two digits with the carry shown as carryn. However, when adding binary numbers, the possible arrangements collapse to the four shown in Table 2.5, which greatly simplifies the process.

Table 2.4

Addition of two decimal integers showing the carry

+

0

1

2

3

4

5

6

7

8

9

0

0

1

2

3

4

5

6

7

8

9

1

1

2

3

4

5

6

7

8

9

10

2

2

3

4

5

6

7

8

9

10

11

3

3

4

5

6

7

8

9

10

11

12

4

4

5

6

7

8

9

10

11

12

13

5

5

6

7

8

9

10

11

12

13

14

6

6

7

8

9

10

11

12

13

14

15

7

7

8

9

10

11

12

13

14

15

16

8

8

9

10

11

12

13

14

15

16

17

9

9

10

11

12

13

14

15

16

17

18

Table 2.5

Addition of two binary integers showing the carry

+

0

1

0

0

1

1

1

10

For example, to add 124 to 188 as two 16-bit binary integers, we write, showing the status of the carry bit:

0000000011111000

carry

0000000010111100

=188

0000000001111100

=124

0000000100111000

=312

Such addition is easily undertaken by digital electronic circuits, and instead of having separate circuitry for subtraction, it is possible to perform subtraction using the technique of two’s complement.

2.7.6 Subtracting Binary Numbers

Two’s  complement is a technique for subtracting binary numbers. There are two stages to the conversion: inversion, followed by the addition of 1. For example, 24 in binary is 00 00000000110000, and is inverted by switching every 1 to 0, and vice versa: 1111111111100111. Next, we add 1: 1111111111101000, which now represents -24. If this is added to binary 36: 0000000000100100, we have:

0000000000100100

= +36

1111111111101000

= -24

0000000000001100

= +12

Note that the last high-order addition creates a carry of 1, which is ignored. Here is another example, 100-30:

0000000000011110

= +30

inversion

1111111111100001

add 1

0000000000000001

1111111111100010

= -30

add 100

0000000001100100

= +100

0000000001000110

= +70

2.8 Types of Numbers

As mathematics evolved, mathematicians introduced different types of numbers to help classify equations and simplify the language employed to describe their work. These are the various types and their set names.

2.8.1 Natural Numbers

The   natural numbers {1,2,3,4,…} are used for counting, ordering and labelling and represented by the set N. When zero is included, N0 or N0 is used:

N0=N0={0,1,2,…}

Note that negative numbers are not included. Natural numbers are used to subscript a quantity to distinguish one element from another, e.g. x1,x2,x3,x4,⋯

Very often, we are interested in whether a natural number is divisible by another number, without leaving a remainder. Here are some divisibility tests, some of which, are very obvious.

Divisible by 2: if the number ends with 0, 2, 4, 6, or 8.

This is because the number abc=100a+10b+c, where 100a and 10b are both divisible by 2, therefore, abc is divisible by 2, iff (if and only if) c is divisible by 2, i.e. is 0, 2, 4, 6, 8.

Divisible by 3: if the number’s digits sum to a multiple of 3. For instance, 135 is divisible by 3, as 1+3+5=9, so too, is 16254, because 1+6+2+5+4=18, and 1+8=9. This is because the number abc=99a+9b+a+b+c, where 99a+9b is divisible by 3, therefore, abc is divisible by 3, iff a+b+c is divisible by 3.

Divisible by 4: if the number formed from the last two digits is divisible by 4. For instance, 1324 is divisible by 4, as 24 is divisible by 4. This is because the number abc=100a+10b+c, where 100a, and all higher numbers, are divisible by 4, therefore, abc is divisible by 4, iff 10b+c is divisible by 4. If the number is c, the test only applies to c.

Divisible by 5: if the number ends with a 0 or 5.

Divisible by 6: if the number passes the divisibility test for 2 and 3. For instance, 1464/6=244, and 1464 is an even number and is divisible by 3, because 1+4+6+4=15.

Divisible by 7: There is no simple test for divisibility by 7, but here is a starting point. Starting with a three-digit number, isolate the right-hand digit, and double it. Subtract this result from the two-digit number formed from the left-most digits. If this result is divisible by 7, so is the original number. For instance, to test 231 we remove the 1, and double it, making 2. We then subtract 2 from 23, which makes 21, which is divisible by 7, and 231. This is because every number can be written 10a+b where b is the right-hand digit. This is isolated and doubled, 2b, leaving behind a. Subtracting 2b from a gives a-2b. We double 10a+b making 20a+2b, as this does not interfere with the original test, and 20a+2b=21a-(a-2b), where 21a is divisible by 7. Therefore, 10a+b is divisible by 7, iff a-2b is divisible by 7. Sometimes it is quicker to divide by 7!

Divisible by 8: This is the same test as 4, but the last three digits are examined. For instance, 25136 is divisible by 8, (25136/8=3142) as 136/8=17. This is because the number abcd=1000a+100b+10c+d, where 1000a and higher digits are divisible by 8, therefore, abcd is divisible by 8, iff 100b+10c+d is divisible by 8. As 10000 is divisible by 16, the technique is extended to four digits.

Divisible by 9: This is the same test as 3. For instance, 123453 is divisible by 9, as 1+2+3+4+5+3=18 is divisible by 9. This is because the number abc=99a+9b+a+b+c, where 99a+9b is divisible by 9, therefore, abc is divisible by 9, iff a+b+c is divisible by 9.

2.8.2 Integer Numbers

Integer numbers include     the natural numbers, both positive and negative, and zero, and are represented by the set Z:

Z={…,-2,-1,0,1,2,3,…}

Z is used because the word integer in German is ganzen Zahlen. Leopold Kronecker apparently criticised Georg Cantor for his work on set theory with the jibe: ‘Die ganzen Zahlen hat der liebe Gott gemacht, alles andere ist Menschenwerk’ [1]. Which translates: ‘God made the integers, and all the rest is man’s work.’ implying that the rest are artificial. However, Cantor’s work on set theory and transfinite numbers proved to be far from artificial.

2.8.3 Rational Numbers

Any   number that equals the quotient of one integer divided by another non-zero integer, is a rational number, and represented by the set Q. For example, 2, 16, 0.25 are rational numbers because:

2=4/216=4=8/20.25=1/4

Some rational numbers can be stored accurately inside a computer, but many others can only be stored approximately. For example, 4/3 produces an infinite sequence of threes, and written 1.3¯, and is truncated when stored as a binary number.

2.8.4 Irrational Numbers

An irrational number cannot   be expressed as the quotient of two integers. Irrational numbers never terminate, nor contain repeated sequences of digits, consequently, they are always subject to a small error when stored within a computer. Examples are:

2=1.41421356⋯(square-rootof2)φ=1.61803398⋯(goldensection)e=2.71828182⋯(naturale)π=3.14159265⋯(pi)

2.8.5 Real Numbers

Rational  and irrational numbers comprise the set of real numbers R. Examples are 1.5, 0.004, 12.999 and 23.0. We often use t∈R to mean ‘t is a real number.’

2.8.6 Algebraic and Transcendental Numbers

Polynomial       equations with rational coefficients have the form:

f(x)=axn+bxn-1+cxn-2+…+C

such as:

y=3x2+2x-1

and their roots (solutions) belong to the set of algebraic numbers A. A consequence of this definition implies that all rational numbers are algebraic, since if:

x=pq

then:

0=qx-p

which is a polynomial. Numbers that are not roots to polynomial equations are transcendental numbers   and include most irrational numbers, but not 2, since if:

x=2

then:

0=x2-2

which is a polynomial in x.

Given a polynomial built from integers, for example:

y=3x3-4x2+x+23

if the result is an integer, it is called an algebraic number, otherwise it is a transcendental number. Familiar examples of the latter being π=3.141592653⋯, and e=2.718281828⋯, which are represented by the following continued fractions:

π=41+122+322+522+722+⋯

e=2+11+12+11+11+14+⋯

2.8.7 Imaginary Numbers

Imaginary numbers  employ the symbol i to represent the impossible operation -1. When combined with a real number they form a complex number which possesses vector-like properties. An imaginary number such as bi is defined as:

b∈R,i2=-1

Imaginary numbers obey all the axioms associated with real numbers: they can be added, subtracted, multiplied and divided. For example, given:

x=-6iy=3i

therefore:

x+y=-6i+3i=-3ix-y=-6i-3i=-9ixy=-6i·3i=-18i2=18xy=-6i3i=-2

Imaginary numbers appear to be an abstract idea created by mathematicians, just because it is possible. However, they play a very important role in mathematics, and are used to reveal patterns that would otherwise remain unnoticed. But apart from this, they are used in the design of electronic circuits, number theory, quantum mechanics, power distribution, and anything where waves are involved.

2.8.8 Complex Numbers

A   complex number has a real and imaginary part: z=a+bi, and represented by the set C:

z=a+bi,z∈C,a,b∈R,i2=-1

Examples are:

z=1+iz=3-2iz=-23+23i

Complex numbers obey all the axioms associated with real numbers. For example, if we multiply a+bi by c+di we have:

(a+bi)(c+di)=ac+adi+bci+bdi2

Collecting up like terms and substituting -1 for i2 we get:

(a+bi)(c+di)=ac+(ad+bc)i-bd

which simplifies to:

(a+bi)(c+di)=ac-bd+(ad+bc)i

which is another complex number.

For example, given:

x=2+3iy=3+4i

then:

x+y=(2+3i)+(3+4i)=5+7ix-y=(2+3i)-(3+4i)=-1-ixy=(2+3i)(3+4i)=6+8i+9i+12i2=-6+17i

Something interesting happens when we multiply a complex number by its complex conjugate, which is the same complex number but with the sign of the imaginary part reversed:

(a+bi)(a-bi)=a2-abi+abi-b2i2

Collecting up like terms and simplifying we obtain:

(a+bi)(a-bi)=a2+b2

which is a real number, as the imaginary part is cancelled out by the action of the complex conjugate. Given a complex number y, its complex conjugate is represented by y¯. This permits us to divide one complex number by another as follows:

x=2+3iy=3+4iy¯=3-4ixy=xyy¯y¯=(2+3i)(3+4i)·(3-4i)(3-4i)=6-8i+9i+129+16=18+i25=1825+125i

Chapter 9 provides more information on complex numbers.

2.8.9 Quaternions and Octonions

In  1843, the brilliant Irish mathematician and physicist Sir William Rowan Hamilton (1805–1865), invented quaternions, represented by the set H, in honour of its inventor, and became the first non-commutative algebra:

q=a+bi+cj+dk

where:

q∈H,a,b,c,d∈R,i2=j2=k2=-1

ij=k,ji=-k,jk=i,kj=-i,ki=j,ik=-j,ijk=-1

The imaginary products are shown in Table 2.6.

Table 2.6

The quaternion’s imaginary products

×

i

j

k

i

-1

k

−j

j

−k

-1

i

k

j

−i

-1

Given two quaternions:

x=a+bi+cj+dky=e+fi+gj+hk

the product xy is:

xy=(ae-bf-cg-dh)+(af+be+ch-dg)i+(ag+ce+df-bh)j+(ah+de+bg-cf)k

The American mathematician Josiah Willard Gibbs (1839–1903), realised that a quaternion’s imaginary part could be isolated and represent quantities with magnitude and direction, and 3D vectors were born:

v=ai+bj+ck

Almost immediately quaternions were invented, the hunt began for the next complex algebra, which was discovered simultaneously in 1843 by a colleague of Hamilton, John Thomas Graves (1806–1870), who called them octaves, and by the young English mathematician Arthur Cayley (1821–1895), who called them Cayley Numbers:

z=a+bi+cj+dk+ep+fq+gr+hs

a,b,c,d,e,f,g,h∈R,i2=j2=k2=p2=q2=r2=s2=-1

They are now called octonions, and are not only non-commutative, but non-associative , which means that in general, given three octonions A,B,C, then (AB)C≠A(BC). In 1898, the German mathematician Adolf Hurwitz (1859–1919), proved that there are only four algebras where it is possible to multiply and divide in the accepted sense: R,C,H,O. Figure 2.2 shows the sets of numbers diagrammatically.

Quaternions are used to rotate points about a 3D axis, and if you wish to learn more about this subject refer to the author’s books [2–4].

Fig. 2.2

The nested sets of numbers

2.9 Prime Numbers

A   prime number is defined as a natural number greater than 1 that is not a product of two smaller natural numbers The first five prime numbers are 2,3,5,7,11. We can prove that any positive integer must either be a prime, or the product of two or more primes, using the following reasoning:

The set of natural numbers comprises two sets: primes and non-primes. A prime, by definition, has no factors, apart from 1 and itself. A non-prime has factors and is called composite . However, these factors are natural numbers, which must either be prime or non-prime. Eventually, the composite factors must decompose into composite primes.

For example, 72=8×9, but 8=23 and 9=32, therefore, 72=23×32. Even starting with 72=6×12, but 6=2×3 and 12=22×3, therefore, 72=23×32. Table 2.7 shows the prime factors for the first 30 numbers.

Table 2.7

The prime factors for the first 30 numbers

Number

Factors

Number

Factors

Number

Factors

1

11

11

21

3×7

2

2

12

22×3

22

2×11

3

3

13

13

23

23

4

22

14

2×7

24

23×3

5

5

15

3×5

25

52

6

2×3

16

24

26

2×13

7

7

17

17

27

33

8

23

18

2×32

28

22×7

9

32

19

19

29

29

10

2×5

20

22×5

30

2×3×5

2.9.1 The Fundamental Theorem of Arithmetic

Original   work by the Greek mathematician Euclid (Mid-4th to mid-3rd century BC), revealed the Fundamental Theorem of Arithmetic (FTAr), also called the Unique Factorisation Theorem, which states that every integer greater than 1, is either prime or the unique product of primes, and is expressed symbolically as follows. Let p1,p2,p3,⋯,pk be prime numbers, and α1,α2,α3,⋯,αk be their associated positive integer powers: p1α1,p2α2,p3α3,⋯,pkαk. We now use the product function ∏ (Pi) to create the product: p1α1p2α2p3α3,⋯,pkαk, and introduce the variable i with a range of 1 to k, which permits the FTAr to be written as:

n=p1α1p2α2p3α3⋯pkαk=∏i=1kpiαi

where ∏ is shorthand for ‘multiply together the associated terms.’

For example, 2250 equals the unique product: 213253, and 245=5172. To prove that these prime products are unique, let’s first assume that they are not, and show that this leads to a contradiction.

Let n>1 and equals the product of two prime numbers: n=p1p2. Now let’s assume that n also equals the product of two other prime numbers: q1q2. Therefore:

p1p2=q1q2

and

p1=q1q2p2

which implies that either q1/p2 or q2/p2 factorises. However, this is impossible as q1 and q2 are prime, therefore, the original assumption was incorrect. The same reasoning may be generalised to any number of prime factors.

2.9.2 Is 1 a Prime?

You may notice in Table 2.7 showing factors that 1 is not a prime number, which has not always been the case. The reason is due to maintaining the logical integrity of the FTAr, which emphasises the uniqueness of the product of primes. If 1 was a prime, we would have the following non-unique products:

24=23×324=1×23×3

and it doesn’t seem satisfying to make 1 a prime number, and then qualify the FTAr with the rider: ‘This only applies for primes greater than 1’.

2.9.3 The Goldbach Conjecture

In  1742, the German mathematician Christian Goldbach (1690–1764), conjectured that every even, positive integer greater than 2 could be written as the sum of two primes:

4=2+214=11+318=11+720=13+7etc.

Today, this has become known as the Goldbach conjecture. No one has ever found an exception to this conjecture, and no one has ever confirmed it. If you want to know more about this topic then consider [5].

2.9.4 Prime Number Distribution

As one moves higher through the set of natural numbers, new primes are uncovered. But every prime discovered increases the possibility for more composite numbers, which overall, creates a falling prime number distribution. Table 2.8 shows that there are 10 primes in the first 30 numbers, and further analysis reveals 25 primes in the first 100 numbers, after which, they slowly decline, but never disappear.

The German mathematician Carl Gauss (1777–1855), proved, at the age of fourteen, that as x→∞, (‘x moves towards infinity’), the function π(x), which estimates the number of primes up to x, is given by:

π(x)∼xlnx

where ∼ stands for ‘similar to’.

Testing this for x=100:

π(100)∼100ln100≈1004.60517≈22

which is lower than the actual value of 25. However, the French mathematician Adrien-Marie Legendre (1752–1833), conjectured the following relationship:

π(x)∼xlnx-B

where B=1.08366. But it appears that the best result is when B=1. Testing this for x=100:

π(100)∼100ln100-1≈1003.605≈28

which is higher than the actual value of 25.

2.9.5 Infinite Number of Primes

Euclid  also showed that there are is an infinite number of primes. As we know that the number of primes is either finite or infinite, we begin by assuming that the number is finite, and proving that the assumption is contradicted by an example. We begin by declaring that there are n primes: p1,p2,p3,⋯,pn-1,pn. Next, we form the operation N=p1×p2×p3×⋯×pn-1×pn+1, which can also be written using the product operation:

N=∏i=1npi+1

Now, N must be prime or have factors:

1: If N is prime, then pn is not the largest prime, as assumed.

2: If N has factors, it must be divisible by some prime factor. But this prime factor cannot include any of the original primes as there is a remainder of 1. Therefore, pn is not the largest prime, as assumed. Either way, the original assumption is incorrect; therefore, there must be an infinite number of primes. Table 2.8 lists some examples of these primes and prime factors.

Table 2.8

Examples of primes and prime factors

2

3

5

7

11

13

17

19

23

29

31

N

2

3

2

3

7

2

3

5

31

2

3

5

7

211

2

3

5

7

11

2,311

2

3

5

7

11

13

30,031=59×509

2

3

5

7

11

13

17

510,511=19×97×277

2

3

5

7

11

13

17

19

9,699,691=347×27,953

2

3

5

7

11

13

17

19

23

223,092,871=317×703,763

2

3

5

7

11

13

17

19

23

29

6,469,693,231=331×571×34,231

2

3

5

7

11

13

17

19

23

29

31

200,560,490,131

See [6] for an amazing list of prime numbers and related features. Also, readers interested in learning more about prime numbers should investigate [7].

2.9.6 Mersenne Numbers

Numbers   of the form 2k-1 are called Mersenne numbers, some of which, are also prime. The French theologian and mathematician Marin Mersenne (1588–1648), became interested in them towards the end of his life, and today they are known as Mersenne primes.

By the end of the 16th-century, the highest Mersenne prime was 524,287 which equals 219-1. At the start of the 21st-century, 243,112,609-1 was the highest, containing approximately 13 million digits!

Apart from the fact that prime numbers are so mysterious, they are very important in public key cryptography, which is central to today’s Internet security systems.

2.10 Perfect Numbers

A perfect number equals the sum of its factors. For example, the factors of 6 are 1, 2 and 3, whose sum is also 6. One would imagine that there would be a large quantity of small perfect numbers, but the first five are: 6, 28, 496, 8,128 and 33,550,336, which are all even. And as the search continues to discover higher values, using computers, no odd perfect number has emerged.  Euclid proved that if m is prime, and of the form 2k-1, then m(m+1)/2 is an even perfect number. For example, 3 is prime and:

3=22-1and3×42=6

Similarly, 7 is prime and:

7=23-1and7×82=28.

2.11 Triangular Numbers

Triangular numbers  are best visualised as shown in Fig. 2.3, where successive triangular numbers are constructed from equilateral triangles of circles. Thus, the sequence is 1,3,6,10,15,⋯,∞.

This sequence is generated by n(n+1)/2, for the nth triangular number.

The same numbers are found in the binomial theorem n2, covered in Chap. 3.

Fig. 2.3

First five triangular numbers

2.12 Highest Common Factor

The highest common factor (hcf) of two natural numbers is the largest natural number that divides into both numbers. For example, the hcf of 42 and 28 is 14, as 42=2×3×7 and 28=2×2×7. A technique for finding the hcf is to represent each number as the product of prime numbers, and then find the string of prime products common to both numbers. For example, to find the hcf of 770 and 165 is to represent them as 770=2×5×7×11 and 165=3×5×11, therefore, the hcf is 5×11=55.

2.13 Lowest Common Multiple

The lowest common multiple (lcm) or lowest common denominator of two natural numbers is the smallest natural number into which they both divide. For example, the lcm of 18 and 24 is 72, because 18=2×3×3 and 24=2×2×2×3, and 18×24/6=72. The technique used, is to multiply the two numbers in question, and divide by their hcf.

2.14 Infinity

Infinity  is used to describe the size of unbounded systems. For example, prime numbers are infinite, so, too, are the sets of other numbers. Consequently, no matter how we try, it is impossible to visualise the size of infinity. Nevertheless, this did not stop Georg Cantor from showing that one infinite set could be infinitely larger than another.

Cantor distinguished between those infinite number sets that could be counted, and those that could not. For Cantor, counting meant the one-to-one correspondence of a natural number with the members of another infinite set. If there is a clear correspondence, without leaving any gaps, then the two sets shared a common infinite size, called its cardinality using the first letter of the Hebrew alphabet aleph: ℵ. The cardinality of the natural numbers N is ℵ0, called aleph-zero.

Cantor discovered a way of representing the rational numbers as a grid, which is traversed diagonally, back and forth, as shown in Fig. 2.4. Some ratios appear several times, such as 22,33, etc., which are not counted. Nevertheless, the one-to-one correspondence with the natural numbers means that the cardinality of rational numbers is also ℵ0.

A real surprise was that there are infinitely more transcendental numbers than natural numbers. Furthermore, there are an infinite number of cardinalities rising to ℵℵ. Cantor had been alone working in this esoteric area, and as he published his results, he shook the very foundations of mathematics, which is why he was treated so badly by his fellow mathematicians.

Fig. 2.4

Rational number grid

2.15 Worked Examples

2.15.1 Algebraic Expansion

Expand (a+b)(c+d), (a-b)(c+d) and (a-b)(c-d).

Solution

(a+b)(c+d)=a(c+d)+b(c+d)=ac+ad+bc+bd(a-b)(c+d)=a(c+d)-b(c+d)=ac+ad-bc-bd(a-b)(c-d)=a(c-d)-b(c-d)=ac-ad-bc+bd

2.15.2 Complex Numbers

Compute (3+2i)+(2+2i)+(5-3i) and (3+2i)(2+2i)(5-3i).

Solution

(3+2i)+(2+2i)+(5-3i)=10+i

(3+2i)(2+2i)(5-3i)=(3+2i)(10-6i+10i+6)=(3+2i)(16+4i)=48+12i+32i-8=40+44i

2.15.3 Highest Common Factor

Find the hcf of 760 and 330.

Solution

The hcf of 760 and 330 is to represent them as their prime products 760=2×2×2×5×19 and 330=2×3×5×11, therefore, the hcf is 2×5=10.

2.15.4 Lowest Common Multiple

Find the lcm of 36 and 96.

Solution

The lcm of 36 and 96 is 288, because 36=2×2×3×3 and 96=2×2×2×2×2×3, and 36×96/12=288.

2.15.5 Quaternions

Compute (2+3i+4j+k)+(6+2i+j+2k) and (2+3i+4j+k)(6+2i+j+2k).

Solution

(2+3i+4j+k)+(6+2i+j+2k)=8+5i+5j+3k

(2+3i+4j+k)(6+2i+j+2k)=12+4i+2j+4k+18i+6i2+3ij+6ik+24j+8ji+4j2+8jk+6k+2ki+kj+2k2=12+4i+2j+4k+18i-6+3k-6j+24j-8k-4+8i+6k+2j-i-2=0+29i+22j+5k

References

1.

Weber H (1893) Leopol kronnecker (PDF) mathematische annalen. Springer, Berlin

2.

Vince JA (2022) Mathematics for computer graphics, 6th edn. Springer, Berlin

3.

Vince JA (2021) Quaternions for computer graphics, 2nd edn. Springer, Berlin

4.

Vince JA (2018) Imaginary mathematics for computer science. Springer, Berlin

5.

https://​en.​wikipedia.​org/​wiki/​Goldbach%27s_​conjecture

6.

https://​compoasso.​free.​fr

7.

Crandall R, Pomerance R (eds) (2005) Prime numbers: a computational perspective. Springer, Berlin

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_3

3. Algebra

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

3.1 Introduction

This chapter revises the elements of algebra such as notation, rules, indices, logarithms, explicit and implicit functions, intervals, function domains and ranges, odd and even functions and power series. The chapter concludes with some worked examples.

3.2 Background

Some people, including me, find learning a foreign language a real challenge; one of the reasons being the inconsistent rules associated with its syntax. For example, why is a table feminine in French, ‘la table’, and a bed masculine, ‘le lit’? They both have four legs! The rules governing natural language are continuously being changed by each generation, whereas mathematics appears to be logical and consistent. The reason for this consistency is due to the rules associated with numbers and the way they are combined together and manipulated at an abstract level. Such rules, or axioms, generally make our life easy, however, as we saw with the invention of negative numbers, extra rules have to be introduced, such as ‘two negatives make a positive’, which is easily remembered. However, as we explore mathematics, we discover all sorts of inconsistencies, such as there is no real value associated with the square-root of a negative number. It’s forbidden to divide a number by zero. Zero divided by zero gives inconsistent results. Nevertheless, such conditions are easy to recognise and avoided. At least in mathematics, we don’t have to worry about masculine and feminine numbers!

As a student, I discovered Principia Mathematica [1], a three-volume work written by the British philosopher, logician, mathematician and historian Bertrand Russell (1872–1970), and the British mathematician and philosopher Alfred North Whitehead (1861–1947), in which the authors attempted to deduce all of mathematics using the axiomatic system developed by the Italian mathematician Giuseppe Peano (1858–1932). The first volume established type theory, the second was devoted to numbers, and the third to higher mathematics. The authors did intend a fourth volume on geometry, but it was too much effort to complete. It made extremely intense reading. In fact, I never managed to get pass the first page! It took the authors almost 100 pages of deep logical analysis in the second volume to prove that 1+1=2!

Russell wrote in his Principles of Mathematics [2]:

The fact that all Mathematics is Symbolic Logic is one of the greatest discoveries of our age; and when this fact has been established, the remainder of the principles of mathematics consists in the analysis of Symbolic Logic itself.

Unfortunately, this dream cannot be realised, for in 1931, the Austrian-born, and later American logician and mathematician Kurt Gödel (1906–1978), showed that even though mathematics is based upon a formal set of axioms, there will always be statements involving natural numbers that cannot be proved or disproved. Furthermore, a consistent axiomatic system cannot demonstrate its own consistency. These theorems are known as Gödel’s Incompleteness theorems.

Even though we start off with some simple axioms, it does not mean that everything discovered in mathematics is provable, which does not mean that we cannot continue our every-day studies using algebra to solve problems. So let’s examine the basic rules of algebra and prepare ourselves for the following chapters.

3.3 Notation

Modern algebraic notation has evolved over thousands of years where different civilisations developed ways of annotating mathematical and logical problems. The word algebra comes from the Arabic al-jabr w’al-muqabal meaning ‘restoration and reduction.’ In retrospect, it does seem strange that centuries passed before the ‘equals’ sign (=) was invented, and concepts such as ‘zero’ (CE 876) were introduced, especially as they now seem so important. But we are not at the end of this evolution, because new forms of annotation and manipulation will continue to emerge as new mathematical objects are invented.

One fundamental concept of algebra is the idea of giving a name to an unknown quantity. For example, m is often used to represent the slope of a 2D line, and c is the line’s y-coordinate where it intersects the y-axis. The French mathematician René Descartes (1596–1650), formalised the idea of using letters from the beginning of the alphabet (a,b,c,⋯) to represent arbitrary quantities, and letters at the end of the alphabet (p,q,r,s,t,⋯,x,y,z) to represent quantities such as pressure (p), time (t) and coordinates (x,y,z).

With the aid of the basic arithmetic operators: +,-,×,/ we can develop expressions that describe the behaviour of a physical process or a logical computation. For example, the expression ax+by-d equals zero for a straight line. The variables x and y are the coordinates of any point on the line and the values of a, b and d determine the position and orientation of the line. The = sign permits the line equation to be expressed as a self-evident statement:

0=ax+by-d

Such a statement implies that the expressions on the left- and right-hand sides of the = sign are ‘equal’ or ‘balanced’, and in order to maintain equality or balance, whatever is done to one side, must also be done to the other. For example, adding d to both sides, the straight-line equation becomes:

d=ax+by

Similarly, we could double or treble both expressions, divide them by 4, or add 6, without disturbing the underlying relationship. When we are first taught algebra, we are often given the task of rearranging a statement to make different variables the subject. For example, (3.1) can be rearranged such that x is the subject:

y=x+42-1z

(3.1)

Multiply both sides by 2-1z:

y2-1z=x+4

Subtract 4 from both sides, and swap sides:

x=y2-1z-4

Making z the subject requires more effort:

y=x+42-1z

Multiply both sides by 2-1z:

y2-1z=x+4

Expand the left-hand side:

2y-yz=x+4

Subtract 4 from both sides, and rearrange:

2y-x-4=yz

Multiply both sides by z/(2y-x-4):

z=y2y-x-4

Parentheses are used to isolate part of an expression in order to select a sub-expression that is manipulated in a particular way. For example, the parentheses in c(a+b)+d ensure that the variables a and b are added together before being multiplied by c, and finally added to d.

Occasionally, we have to divide a pair of numbers such as 56/3≈18.6667, where the remainder 6 is repeated indefinitely. To remind the reader this is written 18.6¯.

3.3.1 Solving the Roots of a Quadratic Equation

  Problem solving is greatly simplified if one has solved it before, and having a good memory is always an advantage. In mathematics, we keep coming across problems that have been encountered before, apart from different numbers. For example, (a+b)(a-b) always equals a2-b2, therefore factorising the following is a trivial exercise:

a2-16=(a+4)(a-4)x2-49=(x+7)(x-7)x2-2=x+2x-2

A perfect square has the form:

a2+2ab+b2=(a+b)2

Consequently, factorising the following is also a trivial exercise:

a2+4ab+4b2=(a+2b)2x2+14x+49=(x+7)2x2-20x+100=(x-10)2

Now let’s solve the roots of a quadratic equation ax2+bx+c=0, i.e. those values of x that make the equation equal zero. As the equation involves an x2 term, we will exploit any opportunity to factorise it. We begin with the quadratic where a≠0:

ax2+bx+c=0

Subtract c from both sides to begin the process of creating a perfect square:

ax2+bx=-c

Divide both sides by a to create an x2 term:

x2+bax=-ca

Add b2/4a2 to both sides to create a perfect square on the left side:

x2+bax+b24a2=b24a2-ca

Factorise the left side:

x+b2a2=b24a2-ca

Make 4a2 the common denominator for the right side:

x+b2a2=b2-4ac4a2

Take the square root of both sides:

x+b2a=±b2-4ac2a

Subtract b/2a from both sides:

x=±b2-4ac2a-b2a

Rearrange the right side:

x=-b±b2-4ac2a

which provides the roots for any quadratic equation.

The discriminant b2-4ac may be positive, negative or zero. A positive value reveals two real roots:

x1=-b+b2-4ac2a,x2=-b-b2-4ac2a

(3.2)

A negative value reveals two complex roots:

x1=-b+|b2-4ac|i2a,x2=-b-|b2-4ac|i2a

(3.3)

Readers may have noticed the use of | in (3.3), which are used to indicate that the enclosed expression is always positive. And a zero value reveals a single root:

x=-b2a

Fig. 3.1

Graph of y=x2+x-2

For example, Fig. 3.1 shows the graph of y=x2+x-2, where we can see that y=0 at two points: x=-2 and x=1. In this equation:

a=1b=1c=-2

which when plugged into (3.2) confirms the graph:

x1=-1+1+82=1x2=-1-1+82=-2

Fig. 3.2

Graph of y=x2+x+1

Figure 3.2 shows the graph of y=x2+x+1, where at no point does y=0. In this equation:

a=1b=1c=1

which when plugged into (3.2) confirms the graph by giving complex roots:

x1=-1+1-42=-12+32ix2=-1-1-42=-12-32i

Let’s show that x1 satisfies the original equation:

0=x12+x1+1=(-12+32i)2-12+32i+1=14-32i-34-12+32i+1=0

x2 also satisfies the same equation.

Algebraic expressions also contain a wide variety of functions, such as:

x=squarerootofxxn=n-throotofxxn=xtothepowernn!=factorialnsinx=sineofxcosx=cosineofxtanx=tangentofxlogx=logarithmofxlnx=naturallogarithmofx

Trigonometric functions are factorised as follows:

sin2x-cos2x=(sinx+cosx)(sinx-cosx)sin2x-tan2x=(sinx+tanx)(sinx-tanx)sin2x+4sinxcosx+4cos2x=(sinx+2cosx)2sin2x-6sinxcosx+9cos2x=(sinx-3cosx)2

3.3.2 Difference of Two Squares

  A useful algebraic identity is the difference of two squares, which works as follows. Given two numbers a and b, then:

(a+b)(a-b)=a2+ab-ab-b2=a2-b2

3.4 Indices

Indices are used to imply repeated multiplication and create a variety of situations where laws are required to explain how the result is to be computed.

3.4.1 Laws of Indices

  The laws of indices are expressed as follows:

am×an=am+naman=am-n(am)n=amn

and are verified using some simple examples:

23×22=25=322422=22=4223=26=64

From the above laws, it is evident that:

a0=1a-p=1apa1q=aqapq=apq

Fig. 3.3

Graph of logx

3.5 Logarithms

Two people are associated with the invention of logarithms: the Scottish theologian and mathematician John Napier (1550–1617), and the Swiss clockmaker and mathematician Joost Bürgi (1552–1632). Both men were frustrated by the time they spent multiplying numbers together, and both realised that multiplication could be replaced by addition using logarithms. Logarithms exploit the addition and subtraction of indices shown above, and are always associated with a base. For example, if ax=n, then logan=x, where a is the base. Where no base is indicated, it is assumed to be 10. Two examples bring the idea to life:

102=100thenlog100=2103=1,000thenlog1,000=3

The first example is interpreted as ‘10 has to be raised to the power (index) 2 to equal 100.’ The second is interpreted as ‘10 has to be raised to the power 3 to equal 1000.’ The log operation finds the power of the base for a given number. Thus a multiplication is translated into an addition using logs. Figure 3.3 shows the graph of logx, up to x=100, where we see that log20≈1.3 and log50≈1.7. Therefore, given suitable software, logarithm tables, or a calculator with a log function, we can compute the product 20×50 as follows:

20×50=log20+log50≈1.3+1.7=3103=1,000

In general, the two bases used in calculators and software are 10 and e=2.71828⋯. To distinguish one type of logarithm from the other, a logarithm to the base 10 is written as ‘log’, and a natural logarithm to the base e is written ‘ln’.

Fig. 3.4

Graph of lnx

Figure 3.4 shows the graph of lnx, up to x=100, where we see that ln20≈3 and ln50≈3.9. Therefore, given suitable software, a set of natural logarithm tables or a calculator with a ln function, we can compute the product 20×50 as follows:

20×50=ln20+ln50≈3+3.9=6.9e6.9≈1,000

From the above notation, it is evident that:

log(ab)=loga+logblog(ab)=loga-logblog(an)=nloga

3.6 Further Notation

All sorts of symbols are used to stand in for natural language expressions – here are some examples:

<lessthan>greaterthan≤lessthanorequalto≥greaterthanorequalto≈approximatelyequalto≡equivalentto≠notequalto|x|absolutevalueofx

For example, 0≤t≤1 is interpreted as: ‘t is greater than or equal to 0, and is less than or equal to 1’. Basically, this means t varies between 0 and 1.

3.7 Functions

The theory of functions is a large subject, and at this point in the book, I will only touch upon some introductory ideas that will help you understand the following chapters.

The German mathematician Gottfried von Leibniz (1646–1716), is credited with an early definition of a function, based upon the slope of a graph. However, it was the Swiss mathematician Leonhard Euler (pronounced Oiler) (1707–1783), who provided a definition along the lines: ‘A function is a variable quantity, whose value depends upon one or more independent variables.’ Other mathematicians have introduced more rigorous definitions, which are examined later on in the chapter on calculus.

3.7.1 Explicit and Implicit Equations

        The equation:

y=3x2+2x+4

associates the value of y with different values of x. The directness of the equation: ‘y=’, is why it is called an explicit equation, and their explicit nature is extremely useful. However, simply by rearranging the terms, creates an implicit equation:

4=y-3x2-2x

which implies that certain values of x and y combine to produce the result 4. Another implicit form is:

0=y-3x2-2x-4

which means the same thing, but expresses the relationship in a slightly different way.

An implicit equation can be turned into an explicit equation using algebra. For example, the implicit equation:

4x+2y=12

has the explicit form:

y=6-2x

where it is clear what y equals.

3.7.2 Function Notation

      The explicit equation:

y=3x2+2x+4

tells us that the value of y depends on the value of x, and not the other way around. For example, when x=1, y=9; and when x=2, y=20. As y depends upon the value of x, it is called the dependent variable; and as x is independent of y, it is called the independent variable.

We can also say that y is a function of x, which can be written as:

y=f(x)

where the letter ‘f’ is the name of the function, and the independent variable is enclosed in brackets. We could have also written y=g(x), y=h(x), etc.

Eventually, we have to identify the nature of the function, which in this case is:

f(x)=3x2+2x+4

Nothing prevents us from writing:

y=f(x)=3x2+2x+4

which means: y equals the value of the function f(x), which is determined by the independent variable x using the expression 3x2+2x+4.

An equation may involve more than one independent variable, such as the volume of a cylinder:

V=πr2h

where r is the radius, and h, the height, and is written:

V(r,h)=πr2h

3.7.3 Intervals

              An interval is a continuous range of numerical values associated with a variable, which can include or exclude the upper and lower values. For example, a variable such as x is often subject to inequalities like x≥a and x≤b, which can also be written as:

a≤x≤b

and implies that x is located in the closed interval [a,b], where the square brackets indicate that the interval includes a and b. For example:

1≤x≤20

means that x is located in the closed interval [1,20], which includes 1 and 20.

When the boundaries of the interval are not included, then we would state x>a and x<b, which is written:

a<x<b

and means that x is located in the open interval ]a,b[, where the reverse square brackets indicate that the interval excludes a and b. For example:

1<x<10

means that x is located in the open interval ]1,10[, which excludes 1 and 10.

Closed and open intervals may be combined as follows. If x≥a and x<b then:

a≤x<b

and means that x is located in the half-open interval [a,b[. For example:

1≤x<10

means that x is located in the half-open interval [1,10[, which includes 1, but not 10. Similarly:

1<x≤b

means that x is located in the half-open interval ]1,10], which includes 10, but not 1.

An alternative notation employs parentheses instead of reversed brackets:

]a,b[=(a,b)[a,b[=[a,b)]a,b]=(a,b]

Figure 3.5 shows open, closed and half-open intervals diagrammatically.

Fig. 3.5

Closed, open and half-open intervals. The filled circles indicate that a or b are included in the interval

3.7.4 Function Domains and Ranges

        The following descriptions of function domains and ranges only apply to functions with one independent variable: f(x).

Returning to the above function:

y=f(x)=3x2+2x+4

The independent variable x, can take on any value from -∞ to +∞, which is called the domain of the function. In this case, the domain of f(x) is the set of real numbers R. The notation used for intervals, is also used for domains, which in this case is:

]-∞,+∞[

and is open, as there are no precise values for -∞ and +∞.

As the independent variable takes on different values from its domain, so the dependent variable, y or f(x), takes on different values from its range. Therefore, the range of y=f(x)=3x2+2x+4 is also the set of real numbers R.

The domain of logx is:

]0,+∞[

which is open, because x≠0. Whereas, the range of logx is:

]-∞,+∞[

The domain of x is:

[0,+∞[

which is half-open, because 0=0, and +∞ has no precise value. Similarly, the range of x is:

[0,+∞[

Sometimes, a function is sensitive to one specific number. For example, in the function:

y=f(x)=1x-1

when x=1, there is a divide by zero, which is meaningless. Consequently, the domain of f(x) is the set of real numbers R, apart from 1.

3.7.5 Odd and Even Functions

        An odd function satisfies the condition:

f(-x)=-f(x)

where x is located in a valid domain. Consequently, the graph of an odd function is symmetrical relative to the x-axis, relative to the origin. For example, sinα is odd because:

sin(-α)=-sinα

as illustrated in Fig. 3.6. Other odd functions include:

f(x)=axf(x)=ax3

Fig. 3.6

The sine function is an odd function

An even function satisfies the condition:

f(-x)=f(x)

where x is located in a valid domain. Consequently, the graph of an even function is symmetrical relative to the f(x) axis. For example, cosα is even because:

cos(-α)=cosα

as illustrated in Fig. 3.7. Other even functions include:

f(x)=ax2f(x)=ax4

Fig. 3.7

The cosine function is an even function

3.7.6 Power Functions

    Functions of the form f(x)=xn are called power functions of degree n and are either odd or even. If n is an odd natural number, then the power function is odd, else if n is an even natural number, then the power function is even.

3.8 Series

Many constants and functions can be represented as a series of terms, which are summed or represented as a product. This is very convenient in computing, as it means that accuracy is maximised. The Greek symbol sigma ∑ is used to stand for ‘sum’, whereas the Greek symbol pi ∏ is used for ‘product’.

Here are a list of such series, which are given without proof.

π=2·43·1615·3635·6463⋯=2∏k=1∞4k24k2-1e=1+11!+12!+13!+⋯=∑n=0∞1n!ex=1+x11!+x22!+x33!+⋯=∑n=0∞xnn!sinx=x-x33!+x55!-x77!+⋯=∑n=0∞(-1)n(2n+1)!x2n+1cosx=1-x22!+x44!-x66!+⋯=∑n=0∞(-1)n(2n)!x2nsinhx=x+x33!+x55!+x77!+⋯=∑n=0∞x2n+1(2n+1)!coshx=1+x22!+x44!+x66!+⋯=∑n=0∞x2n(2n)!

3.9 Binomial Theorem

In mathematics, the term ‘binomial’ means the sum or difference of two terms. When the binomial (a+b) is raised to an integral power, we can invoke the binomial theorem. For example, the first six terms are:

(a+b)0=1(a+b)1=1a+1b(a+b)2=1a2+2ab+1b2(a+b)3=1a3+3a2b+3ab2+1b3(a+b)4=1a4+4a3b+6a2b2+4ab3+1b4(a+b)5=1a5+5a4b+10a3b2+10a2b3+5ab4+1b5

Any term is expressed by the following:

(a+b)n=n0an+n1an-1b+n2an-2b2+⋯+nn-1abn-1+nnbn

(3.4)

Equation (3.4) can be expressed as the sum:

(a+b)n=∑i=0nnian-ibi

where ni stands for:

ni=n!(n-i)!i!

and means ‘the number of combinations of n elements selected i at a time.’ For example, when n=3:

30=3×2×1(3×2×1)=131=3×2×1(2×1)×1=332=3×2×1(1)×2×1=333=3×2×13×2×1=1

which are the coefficients in the expansion (a+b)3.

The pattern of coefficients is known as ‘Pascal’s triangle’ and part is shown in Table 3.1. Note, that any row of numbers, is closely related to the previous row. And even though it has been named after the French mathematician Blaise Pascal (1623–1662),  the triangle of numbers was known in China many centuries previously.

Table 3.1

Pascal’s triangle

n = 0

1

n = 1

1

1

n = 2

1

2

1

n = 3

1

3

3

1

n = 4

1

4

6

4

1

n = 5

1

5

10

10

5

1

n = 6

1

6

15

20

15

6

1

⋮

⋮

⋮

⋮

⋮

⋮

⋮

⋮

⋮

3.10 Summary

The above description of algebra should be sufficient for the reader to understand the following chapters. However, one should remember that this is only the beginning of a very complex subject.

3.11 Worked Examples

3.11.1 Algebraic Manipulation

Rearrange the following equations to make y the subject:

7=x+43-y,23=x+683+1ey,23=x+683-siny

Solution

7=x+43-y3-y=x+47y=3-x+47y=17-x7

Solution

23=x+683+1ey3+1ey=x+68231ey=x+6823-3=x-123ey=23x-1y=ln(23x-1)

Solution

23=x+683-siny3-siny=x+6823siny=3-x+6823=1-x23y=arcsin(1-x23)

3.11.2 Solving a Quadratic Equation

Solve the following quadratic equations, and test the answers:

0=x2+4x+1,0=2x2+4x+2,0=2x2+4x+4

Solution

0=x2+4x+1x=-b±b2-4ac2a=-4±16-42=-4±122=-2±3

Test with x=-2+3:

x2+4x+1=(-2+3)2+4(-2+3)+1=4-43+3-8+43+1=0

Test with x=-2-3:

x2+4x+1=(-2-3)2+4(-2-3)+1=4+43+3-8-43+1=0

Solution

0=2x2+4x+2x=-b±b2-4ac2a=-4±16-164=-44=-1

Test with x=-1:

2x2+4x+2=2-4+2=0

Solution

0=2x2+4x+4x=-b±b2-4ac2a=-4±16-324=-4±-164=-1±-1=-1±i

Test with x=-1+i:

2x2+4x+4=2(-1+i)2+4(-1+i)+4=2(1-2i-1)-4+4i+4=-4i+4i=0

Test with x=-1-i:

2x2+4x+4=2(-1-i)2+4(-1-i)+4=2(1+2i-1)-4-4i+4=4i-4i=0

3.11.3 Factorising

Factorise the following equations:

4sin2x-4cos2x9sin2x+6sinx·cosx+cos2x25sin2x+10sinx·cosx+cos2x

Solution

4sin2x-4cos2x=(2sinx+2cosx)(2sinx-2cosx)9sin2x+6sinx·cosx+cos2x=(3sinx+cosx)225sin2x+10sinx·cosx+cos2x=(5sinx+cosx)2

3.11.4 Binomial Theorem

Show the expansion (2a+3b)n for n=0 to 3.

Solution

(2a+3b)0=1(2a+3b)1=2a+3b(2a+3b)2=4a2+2×2×3ab+9b2=4a2+12ab+9b2(2a+3b)3=8a3+3×4×3a2b+3×2×9ab2+27b3=8a3+36a2b+54ab2+27b3

References

1.

Russell B, Whitehead AN (1903) Principia mathematica. Cambridge University Press

2.

Russell B (1938) [First published 1903] Principles of mathematics, 2nd edn. WW Norton & Co.

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_4

4. Trigonometry

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

4.1 Introduction

This chapter covers some basic features of trigonometry such as angular measure, trigonometric ratios, inverse ratios, trigonometric identities and various rules, with which the reader should be familiar.

4.2 Background

The word trigonometry divides into three parts: ‘tri’, ‘gon’, ‘metry’, which means the measurement of three-sided polygons, i.e. triangles. It is an ancient subject and is used across all branches of mathematics.

4.3 Units of Angular Measurement

The  measurement of angles is at the heart of trigonometry, and today two units of angular measurement have survived into modern usage: degrees and radians. The degree (or sexagesimal) unit of measure derives from defining one complete rotation as 360∘. Each degree divides into 60 minutes, and each minute divides into 60 seconds. The number 60 has survived from Mesopotamian days and is rather incongruous when used alongside today’s decimal system. The radian, however, is natural to mathematics.

The radian of angular measure does not depend upon any arbitrary constant–it is the angle created by a circular arc whose length is equal to the circle’s radius. And because the perimeter of a circle is 2πr, 2π radians correspond to one complete rotation. As 360∘ correspond to 2π radians, 1 radian equals 180∘/π, which is approximately 57.3∘. The following relationships between radians and degrees are worth remembering:

π2rad=90∘πrad=180∘3π2rad=270∘2πrad=360∘1rad≈57.29578∘1∘≈0.0174533rad

To convert x∘ to radians:

πx∘180rad

To convert xrad to degrees:

180xπ∘

4.4 The Trigonometric Ratios

Ancient civilisations knew that triangles–whatever their size–possessed some inherent properties, especially the ratios of sides and their associated angles. This means that if these trigonometric ratios are known in advance, problems involving triangles with unknown lengths and angles, can be discovered using these ratios.

Fig. 4.1

The four quadrants for the trigonometric ratios

Figure 4.1 shows a point P with coordinates (base,height), on a unit-radius circle rotated through an angle θ. As P is rotated, it moves into the 2nd quadrant, 3rd quadrant, 4th quadrant and returns back to the first quadrant. During the rotation, the sign of height and base change as follows:

Fig. 4.2

The graph of height over the four quadrants

Fig. 4.3

The graph of base over the four quadrants

Figures 4.2 and 4.3 plot the changing values of height and base over the four quadrants, respectively.

When radius=1, the curves vary between 1 and -1. In the context of triangles, the sides are labelled as follows:

hypotenuse=radiusopposite=heightadjacent=base

Fig. 4.4

Sides of a right-angle triangle

Thus, using the right-angle triangle shown in Fig. 4.4, the trigonometric ratios: sine, cosine and tangent are defined as:

sinθ=oppositehypotenuse,cosθ=adjacenthypotenuse,tanθ=oppositeadjacent

The reciprocals  of these functions, cosecant, secant and cotangent are also useful:

cscθ=1sinθ,secθ=1cosθ,cotθ=1tanθ

Fig. 4.5

A right-angle triangle with two unknown sides

As an example, Fig. 4.5 shows a triangle where the hypotenuse and an angle are known. The other sides are calculated as follows:

opposite10=sin40∘opposite=10sin40∘≈10×0.64278=6.4278adjacent10=cos40∘adjacent=10cos40∘≈10×0.7660=7.660

The theorem of Pythagoras confirms that these lengths are correct:

6.42782+7.6602≈102

Figure 4.6 shows the graph of the tangent function, which, like the sine and cosine functions, is periodic, but with only a period of π radians.

Fig. 4.6

Graph of the tangent function

4.4.1 Domains and Ranges

The periodic  nature of sinθ, cosθ and tanθ, means that their domains are infinitely large. Consequently, it is customary to confine the domain of sinθ to:

-π2,π2

and cosθ to:

[0,π]

The range for both sinθ and cosθ is:

[-1,1]

The domain for tanθ is the open interval:

-π2,π2

and its range is the open interval:

-∞,∞

4.5 Inverse Trigonometric Functions

The  functions sinθ, cosθ, tanθ, cscθ, secθ and cotθ provide different ratios for the angle θ, and the inverse trigonometric functions convert a ratio back into an angle. These are arcsin, arccos, arctan, arccsc, arcsec and arccot, and are sometimes written as sin-1, cos-1, tan-1, csc-1, sec-1 and cot-1. For example, sin30∘=0.5, therefore, arcsin(0.5)=30∘. Consequently, the domain for arcsin is the range for sin:

[-1,1]

and the range for arcsin is the domain for sin:

-π2,π2

as shown in Fig. 4.7. Similarly, the domain for arccos is the range for cos:

Fig. 4.7

Graph of the arcsin function

[-1,1]

and the range for arccos is the domain for cos:

[0,π]

as shown in Fig. 4.8.

Fig. 4.8

Graph of the arccos function

The domain for arctan is the range for tan:

]-∞,∞[

and the range for arctan is the domain for tan:

-π2,π2

as shown in Fig. 4.9.

Fig. 4.9

Graph of the arctan function

Various programming languages include the atan2 function, which is an arctan function with two arguments: atan2(y,x). The signs of x and y provide sufficient information to locate the quadrant containing the angle, and gives the atan2 function a range of [0,2π].

4.6 Trigonometric Identities

The sin and cos curves  are identical, apart from being displaced by 90∘, and are related by:

cosθ=sin(θ+π/2)

Also, simple algebra and the theorem of Pythagoras can be used to derive other trigonometric identities such as:

sinθcosθ=tanθsin2θ+cos2θ=11+tan2θ=sec2θ1+cot2θ=csc2θ

Fig. 4.10

A triangle

4.7 The Sine Rule

Figure 4.10 shows a triangle labeled such that side a is opposite angle A, side b is opposite angle B, etc. The sine rule is:

asinA=bsinB=csinC

which can be used to compute the length of an unknown length or angle. For example, if A=60∘, B=40∘, C=80∘, and b=10, then:

asin60∘=10sin40∘

rearranging, we have:

a=10sin60∘sin40∘≈13.47

Similarly:

csin80∘=10sin40∘

therefore:

c=10sin80∘sin40∘≈15.32

4.8 The Cosine Rule

The cosine rule expresses the sin2θ+cos2θ=1 identity for the arbitrary triangle shown in Fig. 4.10. In fact, there are three versions:

a2=b2+c2-2bccosAb2=c2+a2-2cacosBc2=a2+b2-2abcosC

Three further relationships also hold:

a=bcosC+ccosBb=ccosA+acosCc=acosB+bcosA

Fig. 4.11

The geometry to expand sin(α+β)

4.9 Compound-Angle Identities

Compound-angle identities are useful for solving various mathematical problems, but apart from this, their proof often contains a strategy that can be used else where. In the first example, watch out for the technique of multiplying by 1 in the form of a ratio, and swapping denominators. The technique is rather elegant and suggests that the result was known in advance, which probably was the case. Let’s begin by finding a way of representing sin(α+β) in terms of sinα,cosα,sinβ,cosβ.

With reference to Fig. 4.11:

sin(α+β)=FDAD=BC+EDAD=BCADACAC+EDADCDCD=BCACACAD+EDCDCDADsin(α+β)=sinαcosβ+cosαsinβ

(4.1)

To find sin(α-β), reverse the sign of β in (4.1):

sin(α-β)=sinαcosβ-cosαsinβ

(4.2)

Now let’s expand cos(α+β) with reference to Fig. 4.11:

cos(α+β)=AEAD=AB-ECAD=ABADACAC-ECADCDCD=ABACACAD-ECCDCDADcos(α+β)=cosαcosβ-sinαsinβ

(4.3)

To find cos(α-β), reverse the sign of β in (4.3):

cos(α-β)=cosαcosβ+sinαsinβ

To expand tan(α+β), divide (4.1) by (4.3):

sin(α+β)cos(α+β)=sinαcosβ+cosαsinβcosαcosβ-sinαsinβ=sinαcosβcosαcosβ+cosαsinβcosαcosβcosαcosβcosαcosβ-sinαsinβcosαcosβtan(α+β)=tanα+tanβ1-tanαtanβ

(4.4)

To find tan(α-β), reverse the sign of β in (4.4):

tan(α-β)=tanα-tanβ1+tanαtanβ

4.9.1 Double-Angle Identities

  By making β=α, the three compound-angle identities:

sin(α±β)=sinαcosβ±cosαsinβcos(α±β)=cosαcosβ∓sinαsinβtan(α±β)=tanα±tanβ1∓tanαtanβ

and provide the starting point for deriving three corresponding double-angle identities:

sin(α±α)=sinαcosα±cosαsinαsin(2α)=2sinαcosα

Similarly:

cos(α±α)=cosαcosα∓sinαsinαcos(2α)=cos2α-sin2α

which can be further simplified using sin2α+cos2α=1:

cos(2α)=cos2α-sin2αcos(2α)=2cos2α-1cos(2α)=1-2sin2α

And for tan(2α), we have:

tan(α+α)=tanα+tanα1-tanαtanαtan(2α)=2tanα1-tan2α

4.9.2 Multiple-Angle Identities

  Euler’s trigonometric formula shows how the following multiple-angle identities are computed:

sin(3α)=3sinα-4sin3αcos(3α)=4cos3α-3cosαtan(3α)=3tanα-tan3α1-3tan2αsin(4α)=4sinαcosα-8sin3αcosαcos(4α)=8cos4α-8cos2α+1tan(4α)=4tanα-4tan3α1-6tan2α+tan4αsin(5α)=16sin5α-20sin3α+5sinαcos(5α)=16cos5α-20cos3α+5cosαtan(5α)=5tanα-10tan3α+tan5α1-10tan2α+5tan4α

4.9.3 Half-Angle Identities

  Every now and then, it is necessary to compute the half-angle identities from the corresponding whole-angle functions. To do this, we rearrange the double-angle identities as follows:

cos(2α)=1-2sin2αsin2α=1-cos(2α)2sin2(α/2)=1-cosα2sin(α/2)=±1-cosα2

(4.5)

Similarly:

cos2α=1+cos(2α)2cos2(α/2)=1+cosα2cos(α/2)=±1+cosα2

(4.6)

Dividing (4.5) by (4.6) we have:

tan(α/2)=1-cosα1+cosα

4.10 Perimeter Relationships

Finally, with reference to Fig. 4.10, we come to the perimeter relationships that integrate angles with the perimeter of a triangle:

s=12(a+b+c)sin(A/2)=(s-b)(s-c)bcsin(B/2)=(s-c)(s-a)casin(C/2)=(s-a)(s-b)abcos(A/2)=s(s-a)bccos(B/2)=s(s-b)cacos(C/2)=s(s-c)absinA=2bcs(s-a)(s-b)(s-c)sinB=2cas(s-a)(s-b)(s-c)sinC=2abs(s-a)(s-b)(s-c)

4.11 Worked Examples

4.11.1 Degrees to Radians

Convert 20∘ to radians.

Solution

α=20×π180≈0.349066rad

Fig. 4.12

A triangle

4.11.2 Sine Rule

Find the angles α and β using the sine rule in Fig. 4.12.

Solution

Using the sine rule:

3sinα=5sin90∘sinα=35α≈36.870∘4sinβ=5sin90∘sinβ=45β≈53.130∘

Fig. 4.13

A right-angled triangle

4.11.3 Cosine Rule

Find the angles α and β using the cosine rule in Fig. 4.13.

Solution

Using the cosine rule:

52=132+122-2×13×12cosα25=169+144-312cosαcosα=-288-312α≈22.620∘122=52+132-2×5×13cosβ144=25+169-130cosβcosβ=-50-130β≈67.380∘

4.11.4 Compound Angle

Give an example of sin(α+β)=sinαcosβ+cosαsinβ.

Solution

Let α=30∘,β=60∘, then:

sin(α+β)=sinαcosβ+cosαsinβsin(30∘+60∘)=sin30∘cos60∘+cos30∘sin60∘1=0.5×0.5+32321=0.25+0.75

4.11.5 Double-Angle Identity

Give an example of cos(2α)=cos2α-sin2α.

Solution

Let α=30∘:

cos(2α)=cos2α-sin2αcos(2×30∘)=cos230∘-sin230∘cos60∘=34-1412=12

4.11.6 Perimeter Relationship

Give an example of sin(A/2)=(s-b)(s-c)bc.

Solution

Let a=5,b=3,c=4, be the sides of a triangle:

s=12(a+b+c)=12(5+3+4)=6sin(A/2)=(s-b)(s-c)bcsin(90∘/2)=(6-3)(6-4)3×4sin45∘=61222=22

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_5

5. Coordinate Systems

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

5.1 Introduction

This chapter revises coordinate systems which include Cartesian coordinates, polar, spherical polar, cylindrical and barycentric coordinate systems. It also includes the distance between two points in space, and the area of simple 2D shapes. It concludes with a collection of worked examples.

5.2 Background

René  Descartes is often credited with the invention of the xy-plane, but Pierre de Fermat was probably the first inventor. In 1636 Fermat was working on a treatise titled Ad locus planos et solidos isagoge, which  outlined what we now call ‘analytic geometry’. Unfortunately, Fermat never published his treatise, although he shared his ideas with other mathematicians such as Blaise Pascal (1623–1662). At the same time, Descartes devised his own system of analytic geometry and in 1637 published his results in the prestigious journal Géométrie. In the eyes of the scientific world, the publication date of a technical paper determines when a new idea or invention is released into the public domain. Consequently, ever since this publication Descartes has been associated with the xy-plane, which is why it is called the Cartesian plane.

The Cartesian plane is such a simple idea that it is strange that it took so long to be discovered. However, although it is true that René Descartes showed how an orthogonal coordinate system could be used for graphs and coordinate geometry, coordinates had been used by ancient Egyptians, almost 2000 years earlier! If Fermat had been more efficient in publishing his research results, the xy-plane could have been called the Fermatian plane! [1].

5.3 The Cartesian Plane

The Cartesian plane provides a mechanism for locating points with a unique, ordered pair of numbers (x,y) as shown in Fig. 5.1, where P has coordinates (3,2) and Q has coordinates (-4,-2). The point (0,0) is called the origin. As previously  mentioned, Descartes suggested that the letters x and y should be used to represent variables, and letters at the other end of the alphabet should stand for numbers. Which is why equations such as y=ax2+bx+c, are written this way.

Fig. 5.1

The Cartesian plane

The axes are said to be oriented as the x-axis rotates anticlockwise towards the y-axis. They could have been oriented in the opposite sense, with the y-axis rotating anticlockwise towards the x-axis.

5.4 Function Graphs

When functions such as:

are drawn  as graphs, they create familiar shapes that permit the function to be easily identified. Linear functions are straight lines; quadratics are parabolas; cubics have an ‘S’ shape; and trigonometric functions often possess a wave-like trace. Figure 5.2 shows examples of each type of function.

Fig. 5.2

Graphs of four function types

5.5 Shape Representation

The Cartesian plane also provides a way to represent 2D shapes numerically, which permits them to be manipulated mathematically. Let’s begin with 2D polygons and show how their internal area can be calculated.

5.5.1 2D Polygons

     A 2D polygon is formed from a chain of vertices (points) as shown in Fig. 5.3. A straight line is assumed to connect each pair of neighbouring vertices; intermediate points on the line are not explicitly stored. There is no convention for starting a chain of vertices, but software will often dictate whether polygons have a clockwise or anticlockwise vertex sequence.

Fig. 5.3

A polygon created from a chain of vertices

We can now subject this list of coordinates to a variety of arithmetic and mathematical operations. For example, if we double the values of x and y and redraw the vertices, we discover that the shape’s geometric integrity is preserved, but its size is doubled relative to the origin. Similarly, if we divide the values of x and y by 2, the shape is still preserved, but its size is halved relative to the origin. On the other hand, if we add 1 to every x-coordinate, and 2 to every y-coordinate, and redraw the vertices, the shape’s size remains the same but is displaced 1 unit horizontally and 2 units vertically.

Table 5.1

A polygon’s coordinates

x

y

x0

y0

x1

y1

x2

y2

x3

y3

5.5.2 Areas of a Polygonal Shapes

The area of a polygonal shape is readily calculated from its list of coordinates. For example, using the list of coordinates shown in Table 5.1, the area is computed by:

area=12[(x0y1-x1y0)+(x1y2-x2y1)+(x2y3-x3y2)+(x3y0-x0y3)]

You will observe that the calculation sums the results of multiplying an x by the next y, minus the next x by the previous y. When the last vertex is selected, it is paired with the first vertex to complete the process. The result is then halved to reveal the area. As a simple test, let’s apply this formula to the shape described in Fig. 5.3:

area=12[(1×1-3×1)+(3×2-3×1)+(3×3-1×2)+(1×1-1×3)]area=12[-2+3+7-2]=3

which, by inspection, is the true area. The beauty of this technique is that it works with any number of vertices and any arbitrary shape.

Another feature of the technique is that if the set of coordinates is clockwise, the area is negative, which means that the calculation computes vertex orientation as well as area. To illustrate this feature, the original vertices are reversed to a clockwise sequence as follows:

area=12[(1×3-1×1)+(1×2-3×3)+(3×1-3×2)+(3×1-1×1)]area=12[2-7-3+2]=-3

The minus sign confirms that the vertices are in a clockwise sequence.

Fig. 5.4

Calculating the distance between two points

5.5.3 Theorem of Pythagoras in 2D

The theorem of Pythagoras is used to  calculate the distance between two points. Figure 5.4 shows two arbitrary points P1(x1,y1) and P2(x2,y2). The distance Δx=x2-x1 and Δy=y2-y1. Therefore, the distance d between P1 and P2 is given by:

d=(Δx)2+(Δy)2

For example, given P1(1,1),P2(4,5), then d=32+42=5.

5.5.4 Pythagorean Triples

A Pythagorean triple states the  theorem of Pythagoras using integers. For example, these are the first few:

32+42=52,9+16=2562+82=102,36+64=10092+122=152,81+144=22552+122=132,25+144=16972+242=252,49+576=625

Pierre de Fermat proposed that there is no integer solution to an+bn=cn, with n>2, but he did not provide a solution. The English mathematician Sir Andrew John Wiles (1953–), provided a solution in 1994, what is known as Fermat’s Last Theorem.

5.6 3D Cartesian Coordinates

 Two Cartesian coordinates are required to locate a point on the 2D Cartesian  plane, and three Cartesian coordinates are required for 3D space. The corresponding axial system requires three mutually perpendicular axes; however, there are two ways to add the extra z-axis. Figure 5.5 shows the two orientations, which are described as left- and right-handed axial systems. The left-handed system permits us to align our left hand with the axes such that the thumb aligns with the x-axis, the first finger aligns with the y-axis, and the middle finger aligns with the z-axis. The right-handed system permits the same system of alignment, but using our right hand. The choice between these axial systems is arbitrary, but one should be aware of the system employed by commercial computer graphics packages. The main problem arises when projecting 3D points onto a 2D plane, which has an oriented axial system. A right-handed system is employed throughout this book, as shown in Fig. 5.6, which also shows a point P with its coordinates. It also worth noting that handedness has no meaning in spaces with 4 dimensions or more.

Fig. 5.5

a A left-handed system. b A right-handed system

Fig. 5.6

A right-handed axial system showing the coordinates of a point P

5.6.1 Theorem of Pythagoras in 3D

The theorem of Pythagoras in 3D is a natural  extension of the 2D rule. In fact, it even works in higher dimensions. Given two arbitrary points P1(x1,y1,z1) and P2(x2,y2,z2), we compute Δx=x2-x1, Δy=y2-y1 and Δz=z2-z1, from which the distance d between P1 and P2 is given by:

d=(Δx)2+(Δy)2+(Δz)2

and the distance from the origin to a point P(x,y,z) is simply:

d=x2+y2+z2

Therefore, the point (3,4,5) is 32+42+52≈7.07 from the origin.

5.7 Polar Coordinates

Polar coordinates are used for handling data  containing angles, rather than linear offsets. Figure 5.7 shows the convention used for 2D polar coordinates, where the point P(x,y) has equivalent polar coordinates P(ρ,θ), where:

x=ρcosθy=ρsinθρ=x2+y2θ=arctan(y/x)

For example, the point Q(4,0.8π) in Fig. 5.7 has Cartesian coordinates:

x=4cos(0.8π)≈-3.24y=4sin(0.8π)≈2.35

and the point (3,4) has polar coordinates:

ρ=32+42=5θ=arctan(4/3)≈53.13∘

These conversion formulae work only for the first quadrant. The atan2 function should be used in a software environment, as it works with all four quadrants.

Fig. 5.7

2D polar coordinates

Fig. 5.8

Nine Archimedean spirals

Figure 5.8 shows nine Archimedean spirals using polar coordinates, created by:

ρ=kθ,k=2,4,6,8,10,12,14,16,18

5.8 Spherical Polar Coordinates

Figure 5.9 shows one  convention used for spherical polar coordinates, where the point P(x,y,z) has equivalent polar coordinates P(ρ,ϕ,θ), where:

x=ρsinϕcosθy=ρsinϕsinθz=ρcosϕρ=x2+y2+z2ϕ=arccos(z/ρ)θ=arctan(y/x)

Fig. 5.9

Spherical polar coordinates

For example, the point (3,4,0) has spherical polar coordinates (5,90∘,53.13∘):

ρ=32+42+02=5ϕ=arccos(0/5)=90∘θ=arctan(4/3)≈53.13∘

Take great care when using spherical coordinates, as authors often swap ϕ with θ, as well as the alignment of the Cartesian axes; not to mention using a left-handed axial system in preference to a right-handed system!

5.9 Cylindrical Coordinates

Figure 5.10 shows  one convention used for cylindrical coordinates, where the point P(x,y,z) has equivalent cylindrical coordinates P(ρ,θ,z), where:

x=ρcosθy=ρsinθz=zρ=x2+y2θ=arctan(y/x)

For example, the point (3,4,6) has cylindrical coordinates (5,53.13∘,6):

ρ=32+42=5θ=arctan(4/3)≈53.13∘z=6

Again, be careful when using cylindrical coordinates to ensure compatibility.

Fig. 5.10

Cylindrical coordinates

5.10 Homogeneous Coordinates

Homogeneous coordinates surfaced in the early 19th century where they were independently proposed by Möbius, Feuerbach, Bobillier, and Plücker. Homogeneous coordinates, define a point in a plane using three coordinates instead of two. This means that for a point (x,y) there exists a homogeneous point (xt,yt,t) where t is an arbitrary number. For example, the point (3,4) has homogeneous coordinates (6,8,2), because 3=6/2 and 4=8/2. But the homogeneous point (6,8,2) is not unique to (3,4); (12,16,4), (15,20,5) and (300,400,100) are all possible homogeneous coordinates for (3,4).

The reason why this coordinate system is called homogeneous is because it is possible to transform functions such as f(x,y) into the form f(x/t,y/t) without disturbing the degree of the curve. To the non-mathematician this may not seem anything to get excited about, but in the field of projective geometry it is a very powerful concept.

In 3D, a point (x,y,z) becomes (xt,yt,zt,t) and for may applications t=1, which seems a futile operation, but in matrix theory it is very useful, as we will discover.

5.11 Worked Examples

5.11.1 Area of a Shape

Compute the area and orientation of the shape defined by the coordinates in Table 5.2.

Table 5.2

Coordinates of the shape

x

0

2

2

1

1

0

y

0

0

2

2

1

1

Solution

area=12[(2×2-0×2)+(2×2-2×1)+(1×1-2×1)+(1×1-1×0)]=12(4+2-1+1)=3

The shape is oriented anticlockwise, as the area is positive.

5.11.2 Distance Between Two Points

Find the distance d12 between P1(1,1) and P2(6,7), and d34 between P3(1,1,1) and P4(7,8,9).

Solution

d12=(6-1)2+(7-1)2=61≈7.81d34=(7-1)2+(8-1)2+(9-1)2=149≈12.21

5.11.3 Polar Coordinates

Convert  the 2D polar coordinates (3,π/2) to Cartesian form, and the point (4,5) to polar form.

Solution

ρ=3θ=π/2x=ρcosθ=3cos(π/2)=0y=ρsinθ=3sin(π/2)=3

Therefore, (3,π/2)≡(0,3).

x=4y=5ρ=x2+y2=42+52≈6.4θ=arctan(y/x)=arctan(5/4)≈51.34∘

Therefore, (4,5)≈(6.4,51.34∘).

5.11.4 Spherical Polar Coordinates

Convert  the spherical polar coordinates (10,π/2,45∘) to Cartesian form, and the point (3,4,5) to spherical form.

Solution

ρ=10ϕ=π/2θ=45∘x=ρsinϕcosθ=10sin(π/2)cos45∘=102/2≈7.07y=ρsinϕsinθ=10sin(π/2)sin45∘=102/2≈7.07z=ρcosϕ=10cos(π/2)=0

Therefore, (10,π/2,45∘)≈(7.07,7.07,0).

x=3y=4z=5ρ=x2+y2+z2=32+42+52≈7.07ϕ=arccos(z/ρ)≈arccos(5/7.07)=45∘θ=arctan(y/x)=arctan(4/3)≈53.13∘

Therefore, (3,4,5)≈(7.07,45∘,53.13∘).

5.11.5 Cylindrical Coordinates

Convert the  3D cylindrical coordinates (10,π/2,5) to Cartesian form, and the point (3,4,5) to cylindrical form.

Solution

ρ=10θ=π/2z=5x=ρcosθ=10cos(π/2)=0y=ρsinθ=10sin(π/2)=10z=5

Therefore, (10,π/2,5)≈(0,10,5).

x=3y=4z=5ρ=32+42=5θ=arctan(4/3)≈53.13∘z=5

Therefore, (3,4,5)≈(5,53.13∘,5).

Reference

1.

Boyer C, Merzbach U (2011) A history of mathematics. John Wiley & SonszbMATH

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_6

6. Determinants

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

6.1 Introduction

This chapter introduces the determinant as a mathematical construct that simplifies the solution of groups of simultaneous equations. The chapter begins by tracing the determinant’s historical development, and the reader is shown how to evaluate the determinant’s magnitude for real and complex values. The chapter concludes with some worked examples.

6.2 Background

When patterns of numbers or symbols occur over and over again, mathematicians often devise a way to simplify their description and assign a name to them. For example:

∏i=14piαi

is shorthand for:

p1α1p2α2p3α3p4α4

and

∑i=14piαi

is shorthand for:

p1α1+p2α2+p3α3+p4α4

A determinant is another example of this process, and is a value derived from a square matrix of terms, often associated with sets of equations. Such problems were studied by the Babylonians around 300 BC and by the Chinese, between 200 BC and 100 BC. Since then many mathematicians have been associated with the evolution of determinants and matrices, including Girolamo Cardano (1501–1576), Jan de Witt (1625–1672), Takakazu Seki (1642–1708), Gottfried von Leibniz,  Guillaume de L’Hôpital (1661–1704), Augustin-Louis Cauchy (1789–1857), Pierre Laplace (1749–1827) and Arthur Cayley (1821–1895). To understand the rules used to compute a determinant’s value, we need to understand their origin, which is in the solution of sets of linear equations.

6.3 Linear Equations with Two Variables

Consider the linear equations with two variables (6.1) and (6.2) where we want to find values of x and y that satisfy both equations:

7=3x+2y

(6.1)

10=2x+4y

(6.2)

A standard way to resolve this problem is to multiply (6.1) by 2 and subtract (6.2) from (6.1), which removes the y-terms:

14=6x+4y10=2x+4y4=4xx=1

Substituting x=1 in (6.1) reveals the value of y:

7=3+2y4=2yy=2

Therefore, x=1 and y=2, solves (6.1) and (6.2) as follows:

7=3×1+2×210=2×1+4×2

The equations must be linearly independent, otherwise we only have one equation. For example, starting with: 

7=3x+2y14=6x+4y

is a futile exercise, as the second equation is double the first, and does not provide any extra information.

To find a general solution to this problem, we start with (6.3) and (6.4):

d1=a1x+b1y

(6.3)

d2=a2x+b2y

(6.4)

To remove the y-term, we multiply (6.3) by b2 and (6.4) by b1:

d1b2=a1b2x+b1b2y

(6.5)

b1d2=b1a2x+b1b2y

(6.6)

Next, we subtract (6.6) from (6.5):

d1b2-b1d2=a1b2x-b1a2x=(a1b2-b1a2)xx=d1b2-b1d2a1b2-b1a2

(6.7)

To find y, we multiply (6.3) by a2 and (6.4) by a1:

d1a2=a2a1x+b1a2y

(6.8)

a1d2=a2a1x+a1b2y

(6.9)

Next, we subtract (6.8) from (6.9):

a1d2-d1a2=a1b2y-b1a2y=(a1b2-b1a2)yy=a1d2-d1a2a1b2-b1a2

(6.10)

Observe that both (6.7) and (6.10) share the common denominator a1b2-b1a2. Furthermore, note the positions of a1,b1,a2 and b2 in the original equations:

a1b1a2b2

and the denominator is formed by cross-multiplying the diagonal terms a1b2 and subtracting the other cross-multiplied terms b1a2. Placing the four terms between two vertical lines creates a second-order determinant  whose value equals:

a1b1a2b2=a1b2-b1a2

Although the name was originally given by Carl Gauss,  it was the French mathematician Augustin-Louis Cauchy who clarified its current modern identity.

If the original equations were linearly related by a factor λ, the determinant equals zero:

a1b1λa1λb1=a1λb1-b1λa1=0

Observe that the numerators of (6.7) and (6.10) are also second-order determinants:

d1b1d2b2=d1b2-b1d2

and

a1d1a2d2=a1d2-d1a2

which means that equations (6.7) and (6.10) can be written using determinants:

x=d1b1d2b2a1b1a2b2y=a1d1a2d2a1b1a2b2

And one final piece of algebra permits the solution to be written as:

xd1b1d2b2=ya1d1a2d2=1a1b1a2b2

(6.11)

Observe another pattern in (6.11) where the determinant is:

a1b1a2b2

but the d-terms replace the x-coefficients:

d1b1d2b2

and then the y-coefficients:

a1d1a2d2

Returning to the original equations:

7=3x+2y10=2x+4y

and substituting the constants in (6.11), we have:

x72104=y37210=13224

which, when expanded reveals:

x28-20=y30-14=112-4

x8=y16=18

making x=1 and y=2.

Let’s try another example:

11=4x+y

(6.12)

5=x+y

(6.13)

and substituting the constants in (6.11), we have:

x11151=y41115=14111

which, when expanded reveals:

x11-5=y20-11=14-1

x6=y9=13

Therefore, x=2 and y=3, solves (6.12) and (6.13) as follows:

11=4×2+1×35=1×2+1×3

Now let’s see how a third-order determinant  arises from the coefficients of three equations in three unknowns.

6.4 Linear Equations with Three Variables

Consider the linear equations with three variables (6.14), (6.15) and (6.16) where we want to find the values of x, y and z that satisfy the three equations:

13=3x+2y+2z

(6.14)

20=2x+3y+4z

(6.15)

7=2x+y+z

(6.16)

One way to resolve this problem is to multiply (6.14) by 2 and subtract (6.15), which removes the z-terms:

26=6x+4y+4z20=2x+3y+4z6=4x+y

(6.17)

leaving (6.17) with two unknowns. Next, we take (6.15) and (6.16) and remove the z-term by multiplying (6.16) by 4 and subtracting (6.15):

28=8x+4y+4z20=2x+3y+4z8=6x+y

(6.18)

leaving (6.18) with two unknowns. We are now left with (6.17) and (6.18):

6=4x+y8=6x+y

which can be solved using (6.11):

x6181=y4668=14161

Therefore:

x=6-84-6=1y=32-364-6=2

Substituting x=1 and y=2 in (6.14) reveals that z=3. Therefore, x=1, y=2 and z=3 solves (6.14) (6.15) and (6.16) as follows:

13=3×1+2×2+2×320=2×1+3×2+4×37=2×1+1×2+1×3

We can generalise (6.11) for three equations using third-order determinants:

xd1b1c1d2b2c2d3b3c3=ya1d1c1a2d2c2a3d3c3=za1b1d1a2b2d2a3b3d3=1a1b1c1a2b2c2a3b3c3

(6.19)

Once again, there is an important pattern in (6.19) where the underlying determinant is:

a1b1c1a2b2c2a3b3c3

but the d-terms replace the x-coefficients:

d1b1c1d2b2c2d3b3c3

the d-terms replace the y-coefficients:

a1d1c1a2d2c2a3d3c3

and the d-terms replace the z-coefficients:

a1b1d1a2b2d2a3b3d3

We must now find a way of computing the value of a third-order determinant, which requires the following algebraic analysis of three equations in three unknowns. We start with three linear equations:

d1=a1x+b1y+c1z

(6.20)

d2=a2x+b2y+c2z

(6.21)

d3=a3x+b3y+c3z

(6.22)

and derive one equation in two unknowns from (6.20) and (6.21), and another from (6.21) and (6.22).

We multiply (6.20) by c2, (6.21) by c1 and subtract them:

c2d1=a1c2x+b1c2y+c1c2zc1d2=c1a2x+b2c1y+c1c2zc2d1-c1d2=(a1c2-c1a2)x+(b1c2-b2c1)y

(6.23)

Next, we multiply (6.21) by c3, (6.22) by c2 and subtract them:

c3d2=a2c3x+b2c3y+c2c3zc2d3=a3c2x+b3c2y+c2c3zc3d2-c2d3=(a2c3-a3c2)x+(b2c3-b3c2)y

(6.24)

Simplify (6.23) by letting:

e1=c2d1-c1d2f1=a1c2-c1a2g1=b1c2-b2c1

Therefore:

e1=f1x+g1y

(6.25)

Simplify (6.24) by letting:

e2=c3d2-c2d3f2=a2c3-a3c2g2=b2c3-b3c2

Therefore:

e2=f2x+g2y

(6.26)

Now we have two equations in two unknowns:

e1=f1x+g1ye2=f2x+g2y

which are solved using:

xA=yB=1C

(6.27)

where:

A=e1g1e2g2=c2d1-c1d2b1c2-b2c1c3d2-c2d3b2c3-b3c2

(6.28)

B=f1e1f2e2=a1c2-c1a2c2d1-c1d2a2c3-a3c2c3d2-c2d3

(6.29)

C=f1g1f2g2=a1c2-c1a2b1c2-b2c1a2c3-a3c2b2c3-b3c2

(6.30)

We first compute A, from which we can derive B, because the only difference between (6.​28) and (6.​29) is that d1,d2,d3 become a1,a2,a3 respectively, and b1,b2,b3 become d1,d2,d3 respectively.

We can derive C from A, as the only difference between (6.​28) and (6.30) is that d1,d2,d3 become a1,a2,a3 respectively. Starting with A:

A=(c2d1-c1d2)(b2c3-b3c2)-(b1c2-b2c1)(c3d2-c2d3)=b2c2c3d1-b3c22d1-b2c1c3d2+b3c1c2d2-b1c2c3d2+b1c22d3+b2c1c3d2-b2c1c2d3=b2c2c3d1-b3c22d1+b3c1c2d2-b1c2c3d2+b1c22d3-b2c1c2d3=c2(b2c3d1-b3c2d1+b3c1d2-b1c3d2+b1c2d3-b2c1d3)A=c2(d1(b2c3-c2b3)-b1(d2c3-c2d3)+c1(d2b3-b2d3))

(6.31)

Using the substitutions described above we can derive B and C from (6.31):

B=c2(a1(d2c3-c2d3)-b1(a2c3-c2a3)+c1(a2d3-d2a3))

(6.32)

C=c2(a1(b2c3-c2b3)-b1(a2c3-c2a3)+c1(a2b3-b2a3))

(6.33)

We can now rewrite (6.31), (6.32) and (6.33) using determinant notation. At the same time, we can drop the c2 terms as they cancel out when computing x, y and z:

A=d1b2c2b3c3-b1d2c2d3c3+c1d2b2d3b3

(6.34)

B=a1d2c2d3c3-d1a2c2a3c3+c1a2d2a3d3

(6.35)

C=a1b2c2b3c3-b1a2c2a3c3+c1a2b2a3b3

(6.36)

As (6.19) and (6.27) refer to the same x and y, then:

d1b1c1d2b2c2d3b3c3=d1b2c2b3c3-b1d2c2d3c3+c1d2b2d3b3

(6.37)

a1d1c1a2d2c2a3d3c3=a1d2c2d3c3-d1a2c2a3c3+c1a2d2a3d3

(6.38)

a1b1c1a2b2c2a3b3c3=a1b2c2b3c3-b1a2c2a3c3+c1a2b2a3b3

(6.39)

As a consistent algebraic analysis has been pursued to derive (6.37), (6.38) and (6.39), a consistent pattern has surfaced in Fig. 6.1 which shows how the three determinants are evaluated. This pattern comprises taking each entry in the top row, called a cofactor, and multiplying it by the determinant of entries in rows 2 and 3, whilst ignoring the column containing the original term, called a first minor. Observe that the second term of the top row is switched negative, called an inversion correction factor.

Fig. 6.1

Evaluating the determinants shown in (6.37), (6.38) and (6.39)

Let’s repeat (6.33) again without the c2 term, as it has nothing to do with the calculation of the determinant:

C=a1(b2c3-c2b3)-b1(a2c3-c2a3)+c1(a2b3-b2a3)

(6.40)

It is possible to arrange the terms of (6.40) as a square matrix  such that each row and column sums to C:

a1(b2c3-c2b3)-b1(a2c3-c2a3)+c1(a2b3-b2a3)-a2(b1c3-c1b3)+b2(a1c3-c1a3)-c2(a1b3-b1a3)a3(b1c2-c1b2)-b3(a1c2-c1a2)+c3(a1b2-b1a2)

which means that there are six ways to evaluate the determinant C: summing the rows, or summing the columns. Figure 6.2 shows this arrangement with the cofactors in blue, and the first minor determinants in green. Observe how the signs alternate between the terms.

Fig. 6.2

The patterns of multipliers with their respective second-order determinants

Having discovered the origins of these patterns, let’s evaluate the original equations declared at the start of this section using (6.11):

13=3x+2y+2z20=2x+3y+4z7=2x+y+z

xd1b1c1d2b2c2d3b3c3=ya1d1c1a2d2c2a3d3c3=za1b1d1a2b2d2a3b3d3=1a1b1c1a2b2c2a3b3c3

Therefore:

x13222034711=y31322204271=z32132320217=1322234211

computing the determinants using the top row entries as cofactors:

x-13+16-2=y-24+78-52=z3+52-52=1-3+12-8

x1=y2=z3=11

Therefore, x=1, y=2 and z=3 solves (6.14), (6.15) and (6.16) as follows:

13=3×1+2×2+2×320=2×1+3×2+4×37=2×1+1×2+1×3

6.4.1 Sarrus’s Rule

The French mathematician Pierre Sarrus (1798–1861),  discovered another way, now called Sarrus’s rule, to compute the value of a third-order determinant, that arises from (6.40):

C=a1(b2c3-c2b3)-b1(a2c3-c2a3)+c1(a2b3-b2a3)=a1b2c3-a1c2b3-b1a2c3+b1c2a3+c1a2b3-c1b2a3=a1b2c3+b1c2a3+c1a2b3-a1c2b3-b1a2c3-c1b2a3

(6.41)

The pattern in (6.41) becomes clear in Fig. 6.3, where the first two columns of the matrix are repeated, and comprises two diagonal sets of terms: on the left in blue, we have the products a1b2c3, b1c2a3, c1a2b3, and on the right in red and orange, the products a1c2b3, b1a2c3, c1b2a3. These diagonal patterns provide a useful aide-mémoire when computing the determinant. Unfortunately, this rule only applies to third-order determinants.

Fig. 6.3

The pattern behind Sarrus’s rule

6.5 Mathematical Notation

Having discovered the background of determinants, now let’s explore a formal description of their structure and characteristics.

6.5.1 Matrix

  In the following definitions, a matrix is a square array of entries, with an equal number of rows and columns. The entries may be numbers, vectors, complex numbers or even partial differentials, in the case of a Jacobian. In general, each entry is identified by two subscripts row col:

arowcol

A matrix with n rows and m columns has the following entries:

a11a12⋯a1ma21a22⋯a2m⋮⋮⋱⋮an1an2⋯anm

The entries lying on the two diagonals are identified as follows: a11 and anm lie on the main diagonal, and a1m and an1 lie on the secondary diagonal.

6.5.2 Order of a Square Determinant

The order of a square determinant equals the number of rows or columns. For example, a first-order determinant contains a single entry; a second-order determinant has two rows and two columns; and a third-order determinant has three rows and three columns.

6.5.3 Value of a Determinant

  A determinant posses a unique, single value derived from its entries. The algorithms used to compute this value must respect the algebra associated with solving sets of linear equations, as discussed above.

Pierre-Simon Laplace developed a way to expand the determinant of any order. The Laplace expansion is the idea described above and shown in Fig. 6.1, where cofactors and first minors or principal minors are used. For example, starting with a fourth-order determinant, when any row and column are removed, the remaining entries create a third-order determinant, called the first minor of the original determinant.

The following equation is used to control the sign of each cofactor:

(-1)row+col

which, for a fourth-order determinant creates:

+-+--+-++-+--+-+

The Laplace expansion begins by choosing a convenient row or column as the source of cofactors. Any zeros are particularly useful, as they cancel out any contribution by the first minor determinant. It then sums the products of every cofactor in the chosen row or column, with its associated first minor, including an appropriate inversion correction factor to adjust the sign changes. The final result is the determinant’s value.

A first-order determinant:

a11=a11

A second-order determinant:

a11a12a21a22=a11a22-a12a21

A third-order determinant using the Laplace expansion with cofactors from the first row:

a11a12a13a21a22a23a31a32a33=a11a22a23a32a33-a12a21a23a31a33+a13a21a22a31a32

A fourth-order determinant using the Laplace expansion with cofactors from the first row:

a11a22a23a24a32a33a34a42a43a44-a12a21a23a24a31a33a34a41a43a44+a13a21a22a24a31a32a34a41a42a44-a14a21a22a23a31a32a33a41a42a43=a11a12a13a14a21a22a23a24a31a32a33a34a41a42a43a44

Sarrus’s rule is useful to compute a third-order determinant:

a11a12a13a21a22a23a31a32a33=a11a22a33+a12a23a31+a13a21a32-a11a23a32-a12a21a33+a13a22a31

The Laplace expansion works with higher-order determinants, as any first minor can itself be expanded using the same expansion.

6.5.4 Properties of Determinants

  We now summarise various properties of determinants. For example, if a determinant contains a row or column of zeros, the Laplace expansion implies that the value of the determinant is zero:

0002104281=0302204201=0

If a determinant’s rows and columns are interchanged, the Laplace expansion also implies that the value of the determinant is unchanged:

31222104281=32212108241=-2

If any two rows, or columns, are interchanged, without changing the order of their entries, the determinant’s numerical value is unchanged, but its sign is reversed:

31222104281=-212321024821=2

If the entries of a row or column share a common factor, the entries may be adjusted, and the factor placed outside:

31222104281=2362254241=-2

6.6 Worked Examples

6.6.1 Determinant Expansion

Evaluate this determinant using the Laplace expansion and Sarrus’s rule:

147258369

Solution

Using the Laplace expansion:

147258369=15869-24769+34758=1(45-48)-2(36-42)+3(32-35)=-3+12-9=0

Using Sarrus’s rule:

147258369=1×5×9+4×8×3+7×2×6-7×5×3-1×8×6-4×2×9=45+96+84-105-48-72=0

6.6.2 Complex Determinant

    Evaluate the complex determinant:

4+2i1+i2-3i3+3i

Solution

Using the Laplace expansion:

4+2i1+i2-3i3+3i=(4+2i)(3+3i)-(1+i)(2-3i)=(12+18i-6)-(2-i+3)=6+18i-5+i=1+19i

6.6.3 Simple Expansion

Write down the simplest expansion of this determinant with its value:

123450670

Solution

Using the Laplace expansion with cofactors from the third column:

123450670=34567=-6

6.6.4 Simultaneous Equations

Solve the following equations using determinants:

3=2x+y-z12=x+2y+z8=3x-2y+2z

Solution

Using (6.19):

x31-112218-22=y23-11121382=z21312123-28=121-11213-22

Therefore:

x=31-112218-2221-11213-22=18-16+4012+1+8=4221=2

y=23-1112138221-11213-22=32+3+2812+1+8=6321=3z=21312123-2821-11213-22=80+28-2424+1+8=8421=4

Therefore, x=2, y=3 and z=4, which satisfy the original equations as follows:

3=2×2+1×3-1×412=1×2+2×3+1×48=3×2-2×3+2×4

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_7

7. Vectors

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

7.1 Introduction

This chapter provides a comprehensive introduction to Euclidean vectors. It covers a description of vector space, basis vectors, dimension, 2D and 3D vectors, unit vectors, position vectors, Cartesian vectors, vector magnitude, vector products, and area calculations. The chapter concludes with some worked examples.

7.2 Background

Vectors are a relative new invention in the world of mathematics, dating only from the 19th century. They enable us to solve complex geometric problems, the dynamics of moving objects, and problems involving forces and fields.

We often only require a single number to represent quantities used in our daily lives such as height, age, shoe size, waist and chest measurement. The magnitude of these numbers depends on our age and whether we use metric or imperial units. Such quantities are called scalars. There are some things that require more than one number to represent them: wind, force, weight, velocity and sound are just a few examples. For example, any sailor knows that wind has a magnitude and a direction. The force we use to lift an object also has a value and a direction. Similarly, the velocity of a moving object is measured in terms of its speed (e.g. miles per hour), and a direction such as north-west. Sound, too, has intensity and a direction. These are represented by vectors.

Complex numbers seemed to be a likely candidate for representing forces, and were being investigated by the Norwegian-Danish mathematician Caspar Wessel (1745–1818), the French amateur mathematician Jean-Robert Argand (1768–1822) and the English mathematician John Warren (1796–1852). At the time, complex numbers were two-dimensional, and their 3D form was being investigated by the Irish mathematician Sir William Rowan Hamilton (1805–1865), who discovered them in 1843, calling them quaternions. In 1853, Hamilton published his book Lectures on Quaternions [1] in which he described names such as vector, transvector and provector. Hamilton’s vectors were not widely accepted until in 1901, when the American mathematician Edwin Bidwell Wilson (1879–1964), published Vector Analysis [2], describing modern vector analysis. This was based upon a series of lectures delivered earlier by the American scientist Josiah Gibbs (1839–1903). 

Gibbs was not a fan of the imaginary quantities associated with Hamilton’s quaternions, but saw the potential of creating a vectorial system from the imaginary i, j and k into the unit basis vectors i, j and k, which is what we use today.

Some mathematicians were not happy with the direction mathematics had taken. The German mathematician Hermann Gunther Grassmann (1809–1877), believed that his own geometric calculus was far superior to Hamilton’s quaternions, but he died without managing to convince any of his fellow mathematicians. Fortunately, the English mathematician and philosopher William Kingdon Clifford (1845–1879), recognised the brilliance of Grassmann’s ideas, and formalised what today has become known as geometric algebra.

With the success of Gibbs’ vector analysis, quaternions faded into obscurity, only to be rediscovered in the 1970s when they were employed by the flight simulation community to control the dynamic behaviour of a simulator’s motion platform. A decade later they found their way into computer graphics where they are used for rotations about an arbitrary axis.

Now this does not mean that vector analysis is dead–far from it. Vast quantities of scientific software depends upon the vector mathematics developed over a century ago, and will continue to employ it for many years to come. Nevertheless, geometric algebra is destined to emerge as a powerful mathematical framework that could eventually replace vector analysis one day.

Readers interested in the history of vector analysis should read Michael Crowe’s book A History of Vector Analysis [3].

7.3 Vectors

  As mentioned above, vectors owe their invention to Hamilton’s discovery of quaternions, which are four-dimensional objects, composed of a scalar and three imaginary terms i, j and k. Gibbs saw that the imaginary component could represent 3D quantities, and by using i and j, 2D quantities. Since then, vectors have been embraced by mathematicians, and adjusted to become a part of linear algebra.

7.3.1 Vector Space

  A vector space is the set of vectors that satisfy the axioms of this space, that often include being able to add and scale vectors. For this chapter, all vectors are Euclidean vectors which are used to represent force, velocity, surface normals, etc.

7.3.2 Basis Vectors

    A basis is the set of vectors in a vector space that is used to define other vectors. Basis vectors are at the heart of any vectorial system, and ultimately determine the value of a vector’s components. For example, the standard basis used in this chapter, defines a 2D vector by two basis vectors e1 and e2, where:

e1=(1,0)e2=(0,1)

and a 3D vector by three basis vectors e1, e2 and e3, where:

e1=(1,0,0)e2=(0,1,0)e3=(0,0,1)

We visualise these basis vectors being mutually perpendicular such that e1 is the x-axis, e2 is the y-axis, and e3 is the z-axis. These basis vectors permit any 2D vector v=(a,b) to be written uniquely as:

v=ae1+be2

and any 3D vector w=(a,b,c) to be written as:

w=ae1+be2+ce3

For example, given u=(1,2,3) and w=(3,4,5), then:

u=1e1+2e2+3e3w=3e1+4e2+5e3u+w=(1+3)e1+(2+4)e2+(3+5)e3=4e1+6e2+8e3

which uniquely describes the vectors u, w and u+w.

Naturally, other sets of basis vectors are possible, such as:

e1=(2,0,0)e2=(0,3,0)e3=(0,0,4)

and generate the following coordinates for the above example:

u=2e1+6e2+12e3w=6e1+12e2+20e3u+w=(2+6)e1+(6+12)e2+(12+20)e3=8e1+18e2+32e3

but are unnecessary for our work.

Later in this chapter, I employ different names for the basis vectors. Instead of using e1, e2 and e3, I use i, j and k.

7.3.3 Dimension of a Vector Space

  A vector space determines the dimension of the associated vectors by controlling the number of elements required to define a vector. When a vector requires 2 or 3 elements, we can visualise them as two- and three-dimensional structures, but four dimensions, and more, are impossible to visualise.

7.3.4 Vector Notation

        As a vector contains two or more numbers, its symbolic name is printed either using a bold font, such as n, or with a normal font with an arrow, such as n→. I prefer the bold font.

When a scalar variable is assigned a value, we use the standard algebraic notation:

x=5

However, a vector has one or more numbers enclosed in brackets, written as a column or as a row– in this text column vectors are used:

n=23

A row vector places the components horizontally:

n=[23]

The difference between the two, is appreciated in the context of matrices. Sometimes it is convenient–for presentation purposes–to write a column vector as a row vector, in which case, it is written:

n=[23]T

where the superscript T reminds us that n is really a transposed column vector.

For this chapter, all vectors are assumed to be Euclidean vectors which have a standard basis.

Fig. 7.1

An arrow with magnitude and direction

Fig. 7.2

Two vectors r and s have the same magnitude but opposite directions

7.3.5 Graphical Representation of Vectors

An arrow is used to represent a vector as it possesses length and direction, as shown in Fig. 7.1. By assigning coordinates to the arrow it is possible to translate the arrow’s length and direction into two numbers. For example, in Fig. 7.2 the vector r has its tail defined by (x1,y1)=(1,2), and its head by (x2,y2)=(3,4). Vector s has its tail defined by (x3,y3)=(5,3), and its head by (x4,y4)=(3,1). The x- and y-components for r are computed as follows:

xr=x2-x1=3-1=2yr=y2-y1=4-2=2

The components for s are computed as follows:

xs=x4-x3=3-5=-2ys=y4-y3=1-3=-2

It is the negative value of xs and ys that encode the vector’s direction. In general, if the coordinates of a vector’s head and tail are (xh,yh) and (xt,yt) respectively, its components Δx and Δy are given by:

Δx=xh-xtΔy=yh-yt

One can readily see from this notation that a vector does not have an absolute position. It does not matter where we place a vector, so long as we preserve its length and orientation.

7.3.6 Magnitude of a Vector

  The magnitude or length of a vector r is written ‖r‖ and computed using the theorem of Pythagoras:

‖r‖=(Δx)2+(Δy)2

and used as follows. Consider a vector defined by:

(xh,yh)=(4,5)(xt,yt)=(1,1)

where the x- and y-components are 3 and 4 respectively. Therefore its magnitude equals 32+42=5. The magnitude of a vector is also written with single vertical lines |r|, or double vertical lines ||r||.

Figure 7.3 shows eight vectors, and their geometric properties are listed in Table 7.1.

Fig. 7.3

Eight vectors whose coordinates are shown in Table 7.1

Table 7.1

Values associated with the eight vectors in Fig. 7.3

xh

yh

xt

yt

Δx

Δy

‖vector‖

2

0

0

0

2

0

2

0

2

0

0

0

2

2

-2

0

0

0

-2

0

2

0

-2

0

0

0

-2

2

1

1

0

0

1

1

2

-1

1

0

0

-1

1

2

-1

-1

0

0

-1

-1

2

1

-1

0

0

1

-1

2

Fig. 7.4

The vector r has components Δx, Δy, Δz

7.3.7 3D Vectors

   The above vector examples are in 2D, but it is easy to extend this notation to embrace an extra dimension. Figure 7.4 shows a 3D vector r with its head, tail, components and magnitude annotated. The vector, its components and magnitude are given by:

r=[ΔxΔyΔz]TΔx=xh-xtΔy=yh-yt

Δz=zh-zt‖r‖=(Δx)2+(Δy)2+(Δz)2

All future examples are three-dimensional.

7.4 Vector Manipulation

As vectors are different to scalars, there are rules to control how the two mathematical entities interact with one another. For instance, we need to consider vector addition, subtraction and products, and how a vector is scaled.

7.4.1 Scaling a Vector

  Given a vector n, 2n means that the vector’s components are scaled by a factor of 2. For example, given:

n=345,then2n=6810

which seems logical. Similarly, if we divide n by 2, its components are halved. Note that the vector’s direction remains unchanged–only its magnitude changes. In general, given:

n=n1n2n3,thenλn=λn1λn2λn3whereλ∈R

There is no obvious way we can resolve the expression 2+n, for it is not clear which component of n is to be increased by 2. However, if we can add a scalar to an imaginary (e.g. 2+3i), why can’t we add a scalar to a vector (e.g. 2+n)? Well, the answer to this question is two-fold: First, if we change the meaning of ‘add’ to mean ‘associated with’, then there is nothing to stop us from ‘associating’ a scalar with a vector, like complex numbers. Second, the axioms controlling our algebra must be clear on this matter. Unfortunately, the axioms of traditional vector analysis do not support the ‘association’ of scalars with vectors in this way. However, geometric algebra does! Furthermore, geometric algebra even permits division by a vector, which does sound strange. Consequently, whilst reading the rest of this chapter keep an open mind about what is permitted, and what is not permitted. At the end of the day, virtually anything is possible, so long as we have a well-behaved axiomatic system.

7.4.2 Vector Addition and Subtraction

    Given vectors r and s, r±s is defined as:

r=xryrzr,s=xsyszs,thenr±s=xr±xsyr±yszr±zs

Vector addition is commutative:

a+b=b+ae.g.123+456=456+123

However, like scalar subtraction, vector subtraction is not commutative:

a-b≠b-ae.g.456-123≠123-456

Fig. 7.5

Vector addition r+s

Let’s illustrate vector addition and subtraction with two examples. Figure 7.5 shows the graphical interpretation of adding two vectors r and s. Note that the tail of vector s is attached to the head of vector r. The resultant vector t=r+s is defined by adding the corresponding components of r and s together. Figure 7.6 shows a graphical interpretation for r-s. This time, the components of vector s are reversed to produce an equal and opposite vector. Then it is attached to r and added as described above.

Fig. 7.6

Vector subtraction r-s

7.4.3 Position Vectors

  Given any point P(x,y,z), a position vector p is created by assuming that P is the vector’s head and the origin is its tail. As the tail coordinates are (0,0,0) the vector’s components are x,y,z. Consequently, the vector’s magnitude ‖p‖ equals x2+y2+z2.

7.4.4 Unit Vectors

    By definition, a unit vector has a magnitude of 1. A simple example is i, where:

i=[100]T,where‖i‖=1

Unit vectors are extremely useful in the product of two vectors, where their magnitudes are required; and if these are unit vectors, the computation is greatly simplified.

Converting a vector into a unit form is called normalising, and is achieved by dividing its components by the vector’s magnitude. To formalise this process, consider a vector r=[xyz]T, with magnitude ‖r‖=x2+y2+z2. The unit form of r is given by:

r^=1‖r‖[xyz]T

This is confirmed by showing that the magnitude of r^ is 1:

‖r^‖=(x‖r‖)2+(y‖r‖)2+(z‖r‖)2=1‖r‖x2+y2+z2‖r^‖=1

7.4.5 Cartesian Vectors

    A Cartesian vector is constructed from three unit basis vectors: i, j and k, aligned with the x-, y- and z-axis, respectively:

i=[100]T,j=[010]T,k=[001]T

Therefore, any vector aligned with the x-, y- or z-axis is a scalar multiple of the associated unit vector. For example, 10i is aligned with the x-axis, with a magnitude of 10. 20k is aligned with the z-axis, with a magnitude of 20. By employing the rules of vector addition and subtraction, we can compose a vector r by summing three scaled Cartesian unit vectors as follows:

r=ai+bj+ck

which is equivalent to:

r=[abc]T

where the magnitude of r is:

‖r‖=a2+b2+c2

Any pair of Cartesian vectors, such as r and s, can be combined as follows:

r=ai+bj+cks=di+ej+fkr±s=(a±d)i+(b±e)j+(c±f)k

7.4.6 Products

  The product of two scalars is very familiar: for example, 6×7 or 7×6=42. We often visualise this operation as a rectangular area, where 6 and 7 are the dimensions of a rectangle’s sides, and 42 is the area. However, a vector’s qualities are its length and orientation, which means that any product must include them in any calculation. The length is easily calculated, but we must know the angle between the two vectors as this reflects their relative orientation. Although the angle can be incorporated within the product in various ways, two particular ways lead to useful results. For example, the product of r and s, separated by an angle θ could be ‖r‖‖s‖cosθ or ‖r‖‖s‖sinθ. It just so happens that cosθ forces the product to result in a scalar quantity, and sinθ creates a vector. Consequently, there are two products to consider: the scalar product, and the vector product which are written as r·s and r×s respectively.

Fig. 7.7

The projection of r on s

7.4.7 Scalar Product

  Figure 7.7 shows two vectors r and s that have been drawn, for convenience, with their tails touching. Taking s as the reference vector–which is an arbitrary choice–we compute the projection of r on s, which takes into account their relative orientation. The length of r on s is ‖r‖cosθ. We can now multiply the magnitude of s by the projected length of r: ‖s‖‖r‖cosθ. This scalar product is written:

r·s=‖r‖‖s‖cosθ

(7.1)

Because of the dot symbol ‘·’, the scalar product is also called the dot product. 

Fortunately, everything is in place to perform this task. To begin with, we define two Cartesian vectors r and s, and proceed to multiply them together using (7.1):

r=ai+bj+cks=di+ej+fkr·s=(ai+bj+ck)·(di+ej+fk)=ai·(di+ej+fk)+bj·(di+ej+fk)+ck·(di+ej+fk)=adi·i+aei·j+afi·k+bdj·i+bej·j+bfj·k+cdk·i+cek·j+cfk·k

Before we proceed any further, we can see that we have created various dot product terms such as i·i, i·j,i·k, etc. These terms can be divided into two groups: those that reference the same basis vector, and those that reference different basis vectors.

Using the definition of the dot product (7.1), terms such as i·i, j·j and k·k=1, because the angle between i and i, j and j, or k and k, is 0∘; and cos0∘=1. But as the other vector combinations are separated by 90∘, and cos90∘=0, all remaining terms collapse to zero, and we are left with:

r·s=adi·i+bej·j+cfk·k

But as the magnitude of a unit vector is 1, we can write:

r·s=‖r‖‖s‖cosθ=ad+be+cf

which confirms that the dot product is indeed a scalar quantity.

It is worth pointing out that the angle returned by the dot product ranges between 0∘ and 180∘. This is because, as the angle between two vectors increases beyond 180∘ the returned angle θ is always the smallest angle associated with the geometry.

Fig. 7.8

The geometry associated with Lambert’s law

7.4.8 Lambert’s Law

  Lambert’s law states that the intensity of illumination on a diffuse surface is proportional to the cosine of the angle between the surface normal vector and the light source direction. Figure 7.8 shows a scenario where a light source is located at (20, 20, 40), and the illuminated point is (0, 10, 0). In this situation we are interested in calculating cosβ, which, when multiplied by the light source intensity, gives the incident light intensity on the surface. To begin with, we are given the normal vector n^ to the surface. In this case n^ is a unit vector: i.e. ‖n^‖=1:

n^=[010]T

The direction of the light source from the surface is defined by the vector s:

s=20-020-1040-0=201040‖s‖=202+102+402≈45.826‖n^‖‖s‖cosβ=0×20+1×10+0×40=101×45.826×cosβ=10cosβ=1045.826≈0.218

Therefore the light intensity at the point (0,10,0) is 0.218 of the original light intensity at (20,20,40), but does not take into account the attenuation due to the inverse-square law of light propagation.

7.4.9 Back-Facing Polygons

  A simple way to identify back-facing polygons relative to the virtual camera, is to compute the angle between the polygon’s surface normal and the line of sight between the camera and the polygon. If this angle is less than 90∘, the polygon is visible; if it equals or exceeds 90∘, the polygon is invisible. This geometry is shown in Fig. 7.9. Although it is obvious from Fig. 7.9 that the right-hand polygon is invisible to the camera, let’s prove algebraically that this is so.

Fig. 7.9

Back-facing polygons

For example, if the virtual camera is located at (0,0,0) and the polygon’s vertex is (10,10,40). The normal vector is n=[55-2]T:

n=[55-2]T‖n‖=52+52+(-2)2≈7.348

The camera vector c is:

c=0-100-100-40=-10-10-40‖c‖=(-10)2+(-10)2+(-40)2≈42.426

therefore:

‖n‖‖c‖cosβ=5×(-10)+5×(-10)+(-2)×(-40)7.348×42.426×cosβ=-20cosβ=-207.348×42.426≈-0.0634β=cos-1(-0.0634)≈93.64∘

which shows that the polygon is invisible for the camera.

7.4.10 The Vector Product

  As mentioned above, the vector product r×s creates a third vector whose magnitude equals ‖r‖‖s‖sinθ, where θ is the angle between the original vectors. Figure 7.10 reminds us that the area of a parallelogram formed by r and s equals ‖r‖‖s‖sinθ. Because of the cross symbol ‘×’, the vector product is also called the cross product:

r×s=t‖t‖=‖r‖‖s‖sinθ

(7.2)

Fig. 7.10

The area of the parallelogram formed by r and s

Fig. 7.11

The vector product

We will discover that the vector t is normal (90∘) to the plane containing the vectors r and s, as shown in Fig. 7.11, which makes it an ideal way of computing the vector normal to a surface. Once again, let’s define two vectors and this time multiply them together using (7.2):

r=ai+bj+cks=di+ej+fkr×s=(ai+bj+ck)×(di+ej+fk)=ai×(di+ej+fk)+bj×(di+ej+fk)+ck×(di+ej+fk)=adi×i+aei×j+afi×k+bdj×i+bej×j+bfj×k+cdk×i+cek×j+cfk×k

As we found with the dot product, there are two groups of vector terms: those that reference the same basis vector, and those that reference different basis vectors.

Using the definition for the cross product (7.2), operations such as i×i, j×j and k×k result in a vector whose magnitude is 0. This is because the angle between the vectors is 0∘, and sin0∘=0. Consequently these terms disappear and we are left with:

r×s=aei×j+afi×k+bdj×i+bfj×k+cdk×i+cek×j

(7.3)

Sir William Rowan Hamilton struggled for many years when working on quaternions to resolve the meaning of a similar result. At the time, he was not using vectors, as they had yet to be defined, but the imaginary terms i, j and k. Hamilton’s problem was to resolve the products ij, jk, ki and their opposites ji, kj and ik. What did the products mean? He reasoned that ij=k, jk=i and ki=j, but could not resolve their opposites. One day in 1843, when he was out walking, thinking about this problem, he thought the impossible: ij=k, but ji=-k, jk=i, but kj=-i, and ki = j, but ik=-j. To his surprise, this worked, but it contradicted the commutative multiplication law of scalars where 6×7=7×6. We now accept that the commutative multiplication law is there to be broken!

Let’s continue with Hamilton’s rules and reduce the cross product terms of (7.3) to:

r×s=aek-afj-bdk+bfi+cdj-cei

(7.4)

Equation (7.4) can be tidied up to bring like terms together:

r×s=(bf-ce)i+(cd-af)j+(ae-bd)k

(7.5)

Now let’s repeat the original vector equations to see how (7.5) is computed:

r=ai+bj+cks=di+ej+fkr×s=(bf-ce)i+(cd-af)j+(ae-bd)k

(7.6)

To compute the i scalar term we consider the scalars associated with the other two unit vectors, i.e. b, c, e, and f, and cross-multiply and subtract them to form (bf-ce).

To compute the j scalar term we consider the scalars associated with the other two unit vectors, i.e. a, c, d, and f, and cross-multiply and subtract them to form (cd-af).

To compute the k scalar term we consider the scalars associated with the other two unit vectors, i.e. a, b, d, and e, and cross-multiply and subtract them to form (ae-bd).

The middle operation seems out of step with the other two, but in fact it preserves a cyclic symmetry often found in mathematics. Nevertheless, some authors reverse the sign of the j scalar term and cross-multiply and subtract the terms to produce -(af-cd) which maintains a visual pattern for remembering the cross-multiplication. Equation (7.6) now becomes:

r×s=(bf-ce)i-(af-cd)j+(ae-bd)k

(7.7)

However, we now have to remember to introduce a negative sign for the j scalar term!

We can write (7.7) using determinants as follows:

r×s=bcefi-acdfj+abdek

or

r×s=bcefi+cafdj+abdek

Therefore, to derive the cross product of two vectors we first write the vectors in the correct sequence. Remembering that r×s does not equal s×r. Second, we compute the three scalar terms and form the resultant vector, which is perpendicular to the plane containing the original vectors.

So far, we have assumed that:

r×s=t‖t‖=‖r‖‖s‖sinθ

where θ is the angle between r and s, and t is perpendicular to the plane containing r and s. Now let’s prove that this is the case:

r·s=‖r‖‖s‖cosθ=xrxs+yrys+zrzscos2θ=(xrxs+yrys+zrzs)2‖r‖2‖s‖2‖t‖=‖r‖‖s‖sinθ‖t‖2=‖r‖2‖s‖2sin2θ=‖r‖2‖s‖21-cos2θ=‖r‖2‖s‖21-(xrxs+yrys+zrzs)2‖r‖2‖s‖2=‖r‖2‖s‖2-(xrxs+yrys+zrzs)2

=xr2+yr2+zr2xs2+ys2+zs2-(xrxs+yrys+zrzs)2=xr2ys2+zs2+yr2xs2+zs2+zr2xs2+ys2-2xrxsyrys-2xrxszrzs-2yryszrzs=xr2ys2+xr2zs2+yr2xs2+yr2zs2+zr2xs2+zr2ys2-2xrxsyrys-2xrxszrzs-2yryszrzs=(yrzs-zrys)2+(zrxs-xrzs)2+(xrys-yrxs)2

which in determinant form is:

‖t‖2=yrzryszs2+zrxrzsxs2+xryrxsys2

and confirms that t is the vector:

t=yrzryszsi+zrxrzsxsj+xryrxsysk

All that remains is to prove that t is orthogonal (perpendicular) to r and s, which is achieved by showing that r·t=s·t=0:

r=xri+yrj+zrks=xsi+ysj+zskt=(yrzs-zrys)i+(zrxs-xrzs)j+(xrys-yrxs)kr·t=xr(yrzs-zrys)+yr(zrxs-xrzs)+zr(xrys-yrxs)=xryrzs-xryszr+xsyrzr-xryrzs+xryszr-xsyrzr=0s·t=xs(yrzs-zrys)+ys(zrxs-xrzs)+zs(xrys-yrxs)=xsyrzs-xsyszr+xsyszr-xryszs+xryszs-xsyrzs=0

and we have proved that r×s=t, where ‖t‖=‖r‖‖s‖sinθ and t is orthogonal to the plane containing r and s.

Let’s now consider two vectors r and s and compute the normal vector t. The vectors are chosen so that we can anticipate approximately the answer. For the sake of clarity, the vector equations include the scalar multipliers 0 and 1. Normally, these are omitted. Figure 7.12 shows the vectors r and s and the normal vector t, and Table 7.2 contains the coordinates of the vertices forming the two vectors which confirms what we expected from Fig. 7.12.

r=[(x3-x2)(y3-y2)(z3-z2)]Ts=[(x1-x2)(y1-y2)(z1-z2)]TP1=(0,0,1)P2=(1,0,0)P3=(0,1,0)r=-1i+1j+0ks=-1i+0j+1kr×s=[1×1-0×0]i-[-1×1-(-1)×0]j+[-1×0-(-1)×1]kt=i+j+k

Now let’s reverse the vectors to illustrate the importance of vector sequence:

s=-1i+0j+1kr=-1i+1j+0ks×r=[0×0-1×1]i-[-1×0-(-1)×1]j+[-1×1-(-1)×0]kt=-i-j-k

which is in the opposite direction to r×s and confirms that the vector product is non-commutative.

Fig. 7.12

Vector t is normal to the vectors r and s

Table 7.2

Coordinates of the vertices used in Fig. 7.12

Vertex

x

y

z

P1

0

0

1

P2

1

0

0

P3

0

1

0

7.4.11 The Right-Hand Rule

 The right-hand rule is an aide mémoire for working out the orientation of the cross product vector. Given the operation r×s, if the right-hand thumb is aligned with r, the first finger with s, and the middle finger points in the direction of t. However, we must remember that this only holds in 3D. In 4D and above, it makes no sense.

7.5 Deriving a Unit Normal Vector for a Triangle

  Figure 7.13 shows a triangle with vertices defined in an anticlockwise sequence from its visible side. This is the side from which we want the surface normal to point. Using the following information we will compute the surface normal using the cross product and then convert it to a unit normal vector.

Fig. 7.13

The normal vector t is derived from the cross product r×s

Create vector r between P3 and P1, and vector s between P3 and P2:

r=-1i+1j+0ks=-1i+0j+2kr×s=(1×2-0×0)i-(-1×2-0×-1)j+(-1×0-1×-1)kt=2i+2j+1k‖t‖=22+22+12=5t^u=25i+25j+15k

The unit vector t^u can now be used for illumination calculations in computer graphics, and as it has unit length, dot product calculations are simplified.

7.6 Surface Areas

  Figure 7.14 shows two vectors r and s, where the height h=‖s‖sinθ. Therefore the surface area of the associated parallelogram is:

area=‖r‖h=‖r‖‖s‖sinθ

Fig. 7.14

The area of the parallelogram formed by two vectors r and s

But this is the magnitude of the cross product vector t. Thus when we calculate r×s, the length of the normal vector t equals the area of the parallelogram formed by r and s; which means that the triangle formed by halving the parallelogram is half the area:

areaofparallelogram=‖t‖areaoftriangle=12‖t‖

This makes it relatively easy to calculate the surface area of an object constructed from triangles or parallelograms. In the case of a triangulated surface, we simply sum the magnitudes of the normals and halve the result.

7.6.1 Calculating 2D Areas

Figure 7.15 shows a triangle with vertices P0(x0,y0), P1(x1,y1) and P2(x2,y2) formed in an anticlockwise sequence. The vectors r and s are computed as follows:

r=(x1-x0)i+(y1-y0)js=(x2-x0)i+(y2-y0)j‖r×s‖=(x1-x0)(y2-y0)-(x2-x0)(y1-y0)=x1(y2-y0)-x0(y2-y0)-x2(y1-y0)+x0(y1-y0)=x1y2-x1y0-x0y2+x0y0-x2y1+x2y0+x0y1-x0y0=x1y2-x1y0-x0y2-x2y1+x2y0+x0y1=(x0y1-x1y0)+(x1y2-x2y1)+(x2y0-x0y2)

But the area of the triangle formed by the three vertices is 12‖r×s‖. Therefore:

area=12[(x0y1-x1y0)+(x1y2-x2y1)+(x2y0-x0y2)]

which is the formula disclosed in Chap. 5!

Fig. 7.15

The area of the triangle formed by the vectors r and s

7.7 Summary

Vectors are extremely useful and relatively easy to use. They are vital to rendering algorithms and shaders, and most of the time we only need to use the scalar and cross products.

Even if you already knew something about vectors, I hope that this chapter has introduced some new ideas and illustrated the role vectors play in computer science.

7.8 Worked Examples

7.8.1 Position Vector

Calculate the magnitude of the position vector p, for the point P(4, 5, 6).

Solution

p=[456]T,therefore,‖p‖=42+52+62≈8.77

7.8.2 Unit Vector

Convert r to a unit vector.

Solution

r=[123]T‖r‖=12+22+32=14r^=114[123]T≈[0.2670.5350.802]T

7.8.3 Vector Magnitude

Compute the magnitude of r+s.

Solution

r=2i+3j+4ks=5i+6j+7kr+s=7i+9j+11k‖r+s‖=72+92+112≈15.84

7.8.4 Angle Between Two Vectors

Find the angle between r and s.

Solution

r=[204]Ts=[5610]T‖r‖=22+02+42≈4.472‖s‖=52+62+102≈12.689

Therefore:

‖r‖‖s‖cosθ=2×5+0×6+4×10=5012.689×4.472×cosθ=50cosθ=5012.689×4.472≈0.8811θ=arccos0.8811≈28.22∘

The angle between the two vectors is approximately 28.22∘.

7.8.5 Vector Product

To show that the vector product works with the unit vectors i, j and k.

Solution

r=1i+0j+0ks=0i+1j+0k

and then compute (7.7):

r×s=(0×0-0×1)i-(1×0-0×0)j+(1×1-0×0)k

The i scalar and j scalar terms are both zero, but the k scalar term is 1, which makes i×j=k.

Let’s see what happens when we reverse the vectors. This time we start with:

r=0i+1j+0ks=1i+0j+0k

and then compute (7.7):

r×s=(1×0-0×0)i-(0×0-0×1)j+(0×0-1×1)k

The i scalar and j scalar terms are both zero, but the k scalar term is -1, which makes j×i=-k. So we see that the vector product is antisymmetric, i.e. there is a sign reversal when the vectors are reversed. Similarly, it can be shown that:

j×k=ik×i=jk×j=-ii×k=-j

References

1.

Hamilton WR (1853) Lectures on quaternions. Macmillan & Co., Cambridge

2.

Wilson EB (1901) Vector analysis. Yale University Press, New Haven

3.

Crowe MJ (1994) A history of vector analysis. Dover Publications Inc, New York

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_8

8. Matrices

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

8.1 Introduction

This chapter introduces the reader to matrices and covers: notation, vectors, null, unit, trace, determinant, transpose, symmetric, antisymmetric matrices, arithmetic operations on matrices, inverse, orthogonal matrices, and concludes with some worked examples.

Matrices, like determinants, have their background in algebra and offer another way to represent and manipulate equations. Matrices can be added, subtracted and multiplied together, and even inverted, however, they must give the same result obtained through traditional algebraic techniques.

8.2 Transforms and Matrices

     Matrix notation was researched by the British mathematician Arthur Cayley around 1858. Cayley formalised matrix algebra, along with the American mathematicians Charles Peirce (1839–1914), and his father, Benjamin Peirce. Previously, Carl Gauss had shown that transforms were not generally, commutative, i.e. T1T2≠T2T1, (where T1 and T2 are transforms) and matrix notation clarified such observations.

Consider the transform T1, where x and y are transformed into x′ and y′ respectively:

T1=x′=ax+byy′=cx+dy

(8.1)

and a second transform T2, where x′ and y′ are transformed into x′′ and y′′ respectively:

T2=x′′=Ax′+By′y′′=Cx′+Dy′

(8.2)

substituting (8.1) in (8.2) we get:

T3=x′′=A(ax+by)+B(cx+dy)y′′=C(ax+by)+D(cx+dy)

which simplifies to:

T3=x′′=(Aa+Bc)x+(Ab+Bd)yy′′=(Ca+Dc)x+(Cb+Dd)y

(8.3)

Having derived the algebra for T3, let’s examine matrix notation, where constants are separated from the variables. For example, the transform (8.4):

x′=ax+byy′=cx+dy

(8.4)

can be written in matrix form as:

x′y′=abcdxy

(8.5)

where (8.5) contains two different structures: two single-column matrices or column vectors:

x′y′andxy

and a 2×2 matrix:

abcd

Algebraically, (8.4) and (8.5) are identical, which dictates the way (8.5) is converted to (8.4). therefore: using (8.5) we have x′ followed by the ‘=’ sign, and the sum of the products of the top row of constants a and b with the x and y in the last column vector:   

x′=ax+by

Next, we have y′ followed by the ‘=’ sign, and the sum of the products of the bottom row of constants c and d with the x and y in the last column vector:

y′=cx+dy

As an example:

x′y′=3456xy

is equivalent to:

x′=3x+4yy′=5x+6y

We can now write T1 and T2 using matrix notation:

T1=x′y′=abcdxy

(8.6)

T2=x′′y′′=ABCDx′y′

(8.7)

and substituting (8.6) in (8.7) we have:

T3=x′′y′′=ABCDabcdxy

(8.8)

But we have already computed T3 (8.3), which in matrix form is:

T3=x′′y′′=Aa+BcAb+BdCa+DcCb+Ddxy

(8.9)

which implies that:

ABCDabcd=Aa+BcAb+BdCa+DcCb+Dd

and demonstrates how matrices must be multiplied. Here are the rules for matrix multiplication: 

AB⋯⋯a⋯c⋯=Aa+Bc⋯⋯⋯

1: The top left-hand corner element Aa+Bc is the product of the top row of the first matrix by the left column of the second matrix.

AB⋯⋯⋯b⋯d=⋯Ab+Bd⋯⋯

2: The top right-hand element Ab+Bd is the product of the top row of the first matrix by the right column of the second matrix.

⋯⋯CDa⋯c⋯=⋯⋯Ca+Dc⋯

3: The bottom left-hand element Ca+Dc is the product of the bottom row of the first matrix by the left column of the second matrix.

⋯⋯CD⋯b⋯d=⋯⋯⋯Cb+Dd

4: The bottom right-hand element Cb+Dd is the product of the bottom row of the first matrix by the right column of the second matrix.

Let’s multiply the following matrices together:

24683579=(2×3+4×7)(2×5+4×9)(6×3+8×7)(6×5+8×9)=344674102

8.3 Matrix Notation

  Having examined the background to matrices, we can now formalise matrix notation.

A matrix is an array of numbers (real, imaginary, complex, etc.) organised in m rows and n columns, where each entry aij belongs to the i-th row and j-th column:

A=a11a12a13⋯a1na21a22a23⋯a2na31a32a33⋯a3n⋮⋮⋮⋱⋮am1am2am3⋯amn

It is also convenient to express the above definition as:

A=[aij]mn

8.3.1 Matrix Dimension or Order

    The dimension or order of a matrix is the expression m×n where m is the number of rows, and n is the number of columns.

8.3.2 Square Matrix

    A square matrix has the same number of rows as columns:

A=[aij]nn=a11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮an1an2⋯ann,e.g.1-24657431

8.3.3 Column Vector

    A column vector is a matrix with a single column:

a11a21⋮am1,e.g.2323

8.3.4 Row Vector

    A row vector is a matrix with a single row:

a11a12⋯a1n,e.g.235

8.3.5 Null Matrix

    A null matrix has all its elements equal to zero:

θn=[aij]nn=00⋯000⋯0⋮⋮⋱⋮00⋯0,e.g.θ3=000000000

The null matrix behaves like zero when used with numbers, where we have, 0+n=n+0=n and 0×n=n×0=0, and similarly, θ+A=A+θ=A and θA=Aθ=θ. For example:

000000000123456789=123456789000000000=000000000

8.3.6 Unit Matrix

    A unit matrix In, is a square matrix with the elements on its diagonal a11 to ann equal to 1:

In=[aij]nn=10⋯001⋯0⋮⋮⋱⋮00⋯1,e.g.I3=100010001

The unit matrix behaves like the number 1 in a conventional product, where we have, 1×n=n×1=n, and similarly, IA=AI=A. For example:

100010001123456789=123456789100010001=123456789

8.3.7 Trace

    The trace of a square matrix is the sum of the elements on its diagonal a11 to ann:

Tr(A)=∑i=1naii

For example:

A=123456789,thenTr(A)=1+5+9=15

The trace of a rotation matrix can be used to compute the angle of rotation. For example, the matrix to rotate a point about the origin is:

A=cosθ-sinθsinθcosθ

where:

Tr(A)=2cosθ

which means that:

θ=arccosTr(A)2

The three matrices for rotating points about the x-, y- and z-axis are respectively:

Rα,x=1000cosα-sinα0sinαcosαRα,y=cosα0sinα010-sinα0cosαRα,z=cosα-sinα0sinαcosα0001

and it is clear that:

Tr(Rα,x)=Tr(Rα,y)=Tr(Rα,z)=1+2cosα

therefore:

α=arccos(Tr(Rα,x)-12)

8.3.8 Determinant of a Matrix

   The determinant of a matrix is a scalar value computed from the elements of the matrix. The different methods for computing the determinant are described in Chap. 6. For example, using Sarrus’s rule:

A=123456789then:detA=45+84+96-105-48-72=0

8.3.9 Transpose

    The transpose of a matrix exchanges all row elements for column elements. The transposition is indicated by the letter ‘T’ outside the right-hand bracket:

a11a12a13a21a22a23a31a32a33T=a11a21a31a12a22a32a13a23a33

For example:

124657431T=164253471

and

235T=235

To prove that (AB)T=BTAT, we could develop a general proof using n×n matrices, but for simplicity, let’s employ 3×3 matrices and assume the result generalises to higher dimensions. Given:

A=a11a12a13a21a22a23a31a32a33,AT=a11a21a31a12a22a32a13a23a33

and

B=b11b12b13b21b22b23b31b32b33,BT=b11b21b31b12b22b32b13b23b33

then:

AB=a11b11+a12b21+a13b31a11b12+a12b22+a13b32a11b13+a12b23+a13b33a21b11+a22b21+a23b31a21b12+a22b22+a23b32a21b13+a22b23+a23b33a31b11+a32b21+a33b31a31b12+a32b22+a33b32a31b13+a32b23+a33b33(AB)T=a11b11+a12b21+a13b31a21b11+a22b21+a23b31a31b11+a32b21+a33b31a11b12+a12b22+a13b32a21b12+a22b22+a23b32a31b12+a32b22+a33b32a11b13+a12b23+a13b33a21b13+a22b23+a23b33a31b13+a32b23+a33b33

and

BTAT=b11a11+b21a12+b31a13b11a21+b21a22+b31a23b11a31+b21a32+b31a33b12a11+b22a12+b32a13b12a21+b22a22+b32a23b12a31+b22a32+b32a33b13a11+b23a12+b33a13b13a21+b23a22+b33a23b13a31+b23a32+b33a33

which confirms that (AB)T=BTAT.

8.3.10 Symmetric Matrix

  A symmetric matrix is a square matrix that equals its transpose: i.e. A=AT. For example, A is a symmetric matrix:

A=124253436=124253436T

In general, a square matrix A=S+Q, where S is a symmetric matrix, and Q is an antisymmetric matrix. The symmetric matrix is computed as follows. Given a matrix A and its transpose AT:

A=a11a12…a1na21a22…a2n⋮⋮⋱⋮an1an2…ann,AT=a11a21…an1a12a22…an2⋮⋮⋱⋮a1na2n…ann

their sum is:

A+AT=2a11a12+a21…a1n+an1a12+a212a22…a2n+an2⋮⋮⋱⋮a1n+an1a2n+an2…2ann

By inspection, A+AT is symmetric, and if we divide throughout by 2 we have:

S=12A+AT

which is defined as the symmetric part of A. For example:

A=a11a12a13a21a22a23a31a32a33,AT=a11a21a31a12a22a32a13a23a33

then:

S=12A+AT=a11(a12+a21)/2(a13+a31)/2(a12+a21)/2a22a23+a32(a13+a31)/2(a23+a32)/2a33=a11s3/2s2/2s3/2a22s1/2s2/2s1/2a33

where:

s1=a23+a32s2=a13+a31s3=a12+a21

Using a real example:

A=014314426,AT=034112446S=024213436

which equals its own transpose.

8.3.11 Antisymmetric Matrix

        An antisymmetric matrix is a matrix whose transpose is its own negative:

AT=-A

and is also known as a skew-symmetric matrix.

As the elements of A and AT are related by:

arow,col=-acol,row

When k=row=col:

ak,k=-ak,k

which implies that the diagonal elements must be zero. For example, this is an antisymmetric matrix:

A=0-2420-3-430=-0-2420-3-430T

The antisymmetric part is computed as follows. Given a matrix A and its transpose AT:

A=a11a12…a1na21a22…a2n⋮⋮⋱⋮an1an2…ann,AT=a11a21…an1a12a22…an2⋮⋮⋱⋮a1na2n…ann

their difference is:

A-AT=0a12-a21…a1n-an1-(a12-a21)0…a2n-an2⋮⋮⋱⋮-(a1n-an1)-(a2n-an2)…0

It is clear that A-AT is antisymmetric, and if we divide throughout by 2 we have:

Q=12A-AT

For example:

A=a11a12a13a21a22a23a31a32a33,AT=a11a21a31a12a22a32a13a23a33Q=0(a12-a21)/2(a13-a31)/2(a21-a12)/20(a23-a32)/2(a31-a13)/2(a32-a23)/20

and if we maintain some symmetry with the subscripts, we have:

Q=0(a12-a21)/2-(a31-a13)/2-(a12-a21)/20(a23-a32)/2(a31-a13)/2-(a23-a32)/20=0q3/2-q2/2-q3/20q1/2q2/2-q1/20

where:

q1=a23-a32q2=a31-a13q3=a12-a21

Using a real example:

A=014314426,AT=034112446Q=0-101010-10

Furthermore, we have already computed:

S=024213436

and

S+Q=014314426=A

8.4 Matrix Addition and Subtraction

    As equations can be added and subtracted together, it follows that matrices can also be added and subtracted, as long as they have the same dimension. For example:

A=112214-152728,andB=21-4518

then:

A+B=132310-102836,A-B=92118-202620

8.5 Scalar Multiplication

  As equations can be scaled and factorised, it follows that matrixes can also be scaled and factorised:

λA=λa11a12⋯a1na21a22⋯a2n⋮⋮⋱⋮am1am2⋯amn=λa11λa12⋯λa13λa21λa22⋯λa23⋮⋮⋱⋮λam1λam2⋯λamn

For example:

2123456=24681012

8.6 Matrix Products

  We have already seen that matrices can be multiplied together employing rules that maintain the algebraic integrity of the equations they represent. And as matrices may be vectors, rectangular or square, we need to examine the matrix products that are permitted. To keep the notation simple, the definitions and examples are restricted to a dimension of 3 or 3×3. We begin with row and column vectors.

8.6.1 Row and Column Vectors

        Given:

A=[abc],andB=αβγ

then:

AB=abcαβγ=aα+bβ+cγ

which is a scalar and equivalent to the dot or scalar product of two vectors.

For example:

A=234,andB=103020

then:

AB=234103020=20+90+80=190

Whereas:

BA=b11b21b31a11a12a13=b11a11b11a12b11a13b21a11b21a12b21a13b31a11b31a12b31a13

For example:

BA=103020234=2030406090120406080

The products AA and BB are not permitted.

8.6.2 Row Vector and a Matrix

Given:

A=a11a12a13,andB=b11b12b13b21b22b23bm1bm2b33

then:

AB=a11a12a13b11b12b13b21b22b23bm1bm2b33=[(a11b11+a12b21+a13b31)(a11b12+a12b22+a13b32)(a11b13+a12b23+a13b33)]

The product BA is not permitted.

For example:

A=[234],andB=123345456

then:

AB=[234]123345456=[(2+9+16)(4+12+20)(6+15+24)]=[273645]

8.6.3 Matrix and a Column Vector

Given:

A=a11a12a13a21a22a23a31a32a33,andB=b11b21b31

then:

AB=a11a12a13a21a22a23a31a32a33b11b21b31=a11b11+a12b21+a13b31a21b11+a22b21+a23b31a31b11+a32b21+a33b31

The product BA is not permitted.

For example:

A=123345456,andB=234

then:

AB=123345456234=2+6+126+12+208+15+24=203847

8.6.4 Square Matrices

    To clarify the products, lower-case Greek symbols are used with lower-case letters. Here are their names:

α=alpha,β=beta,γ=gammaλ=lambda,μ=mu,ν=nuρ=rho,σ=sigma,τ=tau

Given:

A=abcpqruvw,andB=αβγλμνρστ

then:

AB=abcpqruvwαβγλμνρστ=aα+bλ+cρaβ+bμ+cσaγ+bν+cτpα+qλ+rρpβ+qμ+rσpγ+qν+rτuα+vλ+wρuβ+vμ+wσuγ+vν+wτ

and

BA=αβγλμνρστabcpqruvw=αa+βp+γuαb+βq+γvαc+βr+γwλa+μp+νuλb+μq+νvλc+μr+νwρa+σp+τuρb+σq+τvρc+σr+τw

For example:

A=123345567,andB=234456678

then:

AB=123345567234456678=2834405264767692112

and

BA=234456678123345567=3140494964896788109

8.6.5 Rectangular Matrices

    Given two rectangular matrices A and B, where A has a dimension m×n, the product AB is permitted iff B has a dimension n×p. The resulting matrix has a dimension m×p. For example:

A=a11a12a21a22a31a32,andB=b11b12b13b14b21b22b23b24

then:

AB=a11a12a21a22a31a32b11b12b13b14b21b22b23b24=(a11b11+a12b21)(a11b12+a12b22)(a11b13+a12b23)(a11b14+a12b24)(a21b11+a22b21)(a21b12+a22b22)(a21b13+a22b23)(a21b14+a22b24)(a31b11+a32b21)(a31b12+a32b22)(a31b13+a32b23)(a31b14+a32b24)

8.7 Inverse Matrix

    As matrix division is not possible, when two matrices have to be divided, we multiply by the inverse matrix. A square matrix Ann that is invertible satisfies the condition:

AnnAnn-1=Ann-1Ann=In

where Ann-1 is unique, and is the inverse matrix of Ann. For example:

A=4354

then:

A-1=4-3-54

because:

AA-1=43544-3-54=1001

A square matrix whose determinant is 0, cannot have an inverse, and is known as a singular matrix.   

We now require a way to compute A-1, which is rather easy. Consider two linear equations:

x′y′=abcdxy

(8.10)

Let the inverse of:

abcd

be:

efgh

therefore:

efghabcd=1001

(8.11)

From (8.11) we have:

ae+cf=1

(8.12)

be+df=0

(8.13)

ag+ch=0

(8.14)

bg+dh=1

(8.15)

Multiply (8.12) by d and (8.13) by c, and subtract:

ade+cdf=dbce+cdf=0ade-bce=d

therefore:

e=dad-bc

Multiply (8.12) by b and (8.13) by a, and subtract:

abe+bcf=babe+adf=0adf-bcf=-b

therefore:

f=-bad-bc

Multiply (8.14) by d and (8.15) by c, and subtract:

adg+cdh=0bcg+cdh=cadg-bcg=-c

therefore:

g=-cad-bc

Multiply (8.14) by b and (8.15) by a, and subtract:

abg+bch=0abg+adh=aadh-bch=a

therefore:

h=aad-bc

We now have values for e, f, g and h, which are the elements of the inverse matrix. Consequently:

A=abcd,andA-1=efgh

then:

A-1=1detAd-b-ca

The inverse matrix permits us to solve a pair or linear equations as follows. Starting with:

x′y′=abcdxy=Axy

multiply both sides by the inverse matrix:

A-1x′y′=A-1AxyA-1x′y′=1001xy=xyxy=A-1x′y′xy=1detAd-b-cax′y′

Although the elements of A-1 come from A, the relationship is not obvious. However, if A is transposed, a pattern is revealed. Given:

A=abcd,andAT=acbd

and placing A-1 alongside AT, we have:

A-1=efgh,andAT=acbd

The elements of A-1 share a common denominator (detA), which is placed outside the matrix, therefore: the matrix elements are taken from AT as follows. For any entry aij in A-1, mask out the i-th row and j-th column in AT, and the remaining entry is copied to the ij-th entry in A-1. In the case of e, it is d. For f, it is b, with a sign reversal. For g, it is c, with a sign reversal, and for h, it is a. The sign change is computed by the same formula used with determinants:

(-1)i+j

which generates this pattern:

+--+

You may be wondering what happens when a 3×3 matrix is inverted. Well, the same technique is used, but when the i-th row and j-th column in AT are masked out, it leaves behind a 2×2 determinant, whose value is copied to the ij-th entry in A-1, with the appropriate sign change. We investigate this later on.

Let’s illustrate this with an example. Given:

42=6x+2y28=2x+3y

Let:

A=6223

then detA=14, therefore:

xy=1143-2-264228=1147084=56

which is the solution.

Now let’s investigate how to invert a 3×3 matrix. Given three simultaneous equations in three unknowns:

x′=ax+by+czy′=dx+ey+fzz′=gx+hy+jz

they can be written using matrices as follows:

x′y′z′=abcdefghjxyz=Axyz

Let:

A-1=lmnpqrstu

therefore:

lmnpqrstuabcdefghj=100010001

(8.16)

From (8.16) we can write:

la+md+ng=1

(8.17)

lb+me+nh=0

(8.18)

lc+mf+nj=0

(8.19)

Multiply (8.17) by e and (8.18) by d, and subtract:

ael+dem+egn=ebdl+dem+dhn=0ael-bdl+egn-dhn=el(ae-bd)+n(eg-dh)=e

(8.20)

Multiply (8.18) by f and (8.19) by e, and subtract:

bfl+efm+fhn=0cel+efm+ejn=0bfl-cel+fhn-ejn=0l(bf-ce)+n(fh-ej)=0

(8.21)

Multiply (8.20) by (fh-ej) and (8.21) by (eg-dh), and subtract:

l(ae-bd)(fh-ej)+n(eg-dh)(fh-ej)=e(fh-ej)l(bf-ce)(eg-dh)+n(eg-dh)(fh-ej)=0l(ae-bd)(fh-ej)-l(bf-ce)(eg-dh)=efh-e2jl(aefh-ae2j-bdfh+bdej-befg+bdfh+ce2g-cdeh)=efh-e2jl(aefh-ae2j+bdej-befg+ce2g-cdeh)=efh-e2jl(afh+bdj+ceg-aej-cdh-bfg)=fh-ejl(aej+bfg+cdh-afh-bdj-ceg)=ej-fh

but (aej+bfg+cdh-afh-bdj-ceg) is the Sarrus expansion for detA, therefore:

l=ej-fhdetA

An exhaustive algebraic analysis reveals:

l=ej-fhdetA,m=-bj-chdetA,n=bf-cedetAp=-dj-gfdetA,q=aj-gcdetA,r=-af-dcdetAs=dh-gedetA,t=-ah-gbdetA,u=ae-bddetA

where:

A-1=lmnpqrstu,A=abcdefghj

However, there does not appear to be an obvious way of deriving A-1 from A. But, as we discovered with the 2×2 matrix, the transpose AT resolves the problem:

A-1=lmnpqrstu,AT=adgbehcfj

The elements for A-1 share a common denominator (detA), which is placed outside the matrix, therefore: the matrix elements are taken from AT as follows. For any entry aij in A-1, mask out the i-th row and j-th column in AT, and the remaining elements, in the form of a 2×2 determinant, is copied to the ij-th entry in A-1. In the case of l, it is (ej-hf). For m, it is (bj-hc), with a sign reversal, and for n, it is (bf-ec). The sign change is computed by the same formula used with determinants:

(-1)i+j

which generates the pattern:

+-+-+-+-+

With the above aide-mémoire, it is easy to write down the inverse matrix:

A-1=1detA(ej-fh)-(bj-ch)(bf-ce)-(dj-gf)(aj-gc)-(af-dc)(dh-ge)-(ah-gb)(ae-bd)

This technique is known as the Laplacian expansion or the cofactor expansion, after Pierre-Simon Laplace. The matrix of minor determinants is called the cofactor matrix of A, which permits the inverse matrix to be written as:

A-1=(cofactormatrixofA)TdetA

Let’s illustrate this solution with an example. Given:

18=2x+2y+2z20=x+2y+3z7=y+z

therefore:

18207=222123011xyz=Axyz

and

detA=4+2-2-6=-2AT=210221231

therefore:

A-1=-12-102-12-41-22

and

xyz=-12-102-12-41-2218207=234

and the solution is x=2,   y=3,   z=4.

8.7.1 Inverting a Pair of Matrices

Having seen how to invert a single matrix, let’s investigate how to invert a pair of matrices.

Given two matrices T and R, the product TR and its inverse (TR)-1 must equal the identity matrix I:

(TR)(TR)-1=I

and multiplying throughout by T-1 we have:

T-1TR(TR)-1=T-1R(TR)-1=T-1

Multiplying throughout by R-1 we have:

R-1R(TR)-1=R-1T-1(TR)-1=R-1T-1

therefore: if T and R are invertible, then:

(TR)-1=R-1T-1

Generalising this result to a triple product such as STR we can reason that:

(STR)-1=R-1T-1S-1

8.8 Orthogonal Matrix

    A matrix is orthogonal if its transpose is also its inverse, i.e. matrix A is orthogonal if:

AT=A-1

For example:

A=12-121212

and

AT=1212-1212

and

AAT=12-1212121212-1212=1001

which implies that AT=A-1.

The following matrix is also orthogonal:

A=cosβ-sinβsinβcosβ

because:

AT=cosβsinβ-sinβcosβ

and

AAT=cosβ-sinβsinβcosβcosβsinβ-sinβcosβ=1001

Orthogonal matrices play an important role in rotations because they leave the origin fixed and preserve all angles and distances. Consequently, an object’s geometric integrity is maintained after a rotation, which is why an orthogonal transform is known as a rigid motion transform.

8.9 Diagonal Matrix

    A diagonal matrix is a square matrix whose elements are zero, apart from its diagonal:

A=a110…00a22…0⋮⋮⋱⋮00…ann

The determinant of a diagonal matrix must be:

detA=a11×a22×⋯×ann

Here is a diagonal matrix with its determinant:

A=200030004detA=2×3×4=24

The identity matrix I is a diagonal matrix with a determinant of 1.

8.9.1 Augmented Matrix

An augmented matrix  arises from a system of linear equations, where the value to the equations is incorporated with the matrix. For example, the set of linear equations (8.22) is represented as matrices in (8.23), where x=1,y=2,z=3:

2x+2y+2z=12-3x-y+2z=1-x-2y-2z=-11

(8.22)

xyz=222-3-12-212121-11

(8.23)

However, the right-most column vector, can be incorporated with the middle matrix to make Gaussian elimination easier (8.24):

xyz=22212-3-121-1-2-2-11

(8.24)

Equation (8.24) is the augmented matrix, and is solved in Gaussian elimination. For example, starting with (8.24), a next step is to place a 1 in column 1:

Row1+Row3⇒Row1xyz=1001-3-121-1-2-2-11

where the right-most column is part of the matrix update. The augmented matrix makes this possible. See Gaussian Elimination for a complete process.

8.9.2 Gaussian Elimination

Carl Gauss developed a way of simplifying and solving a system of linear equations by back-substitution, now called Gaussian elimination. The technique involves simplifying the augmented matrix representing the equations, by adding and subtracting whole or fractional rows, to or from other rows. The technique terminates by creating a RREF (the next entry) in the left-hand side of the augmented matrix, and the answer is in the right-hand side.

2x+2y+2z=12-3x-y+2z=1-x-2y-2z=-11

xyz=22212-3-121-1-2-2-11

Place a 1 in column 1 on a background of 0s in the first row.

Row1+Row3⇒Row1xyz=1001-3-121-1-2-2-11

Place a 0 in column 3 of the second row.

Row2+Row3⇒Row2xyz=1001-4-30-10-1-2-2-11

Place a 0 in column 1 and a −3 in column 2 of the second row.

4Row1+Row2⇒Row2xyz=10010-30-6-1-2-2-11

Place a 1 in column 2 of the second row by dividing the second row by −3.

-1/3Row2⇒Row2xyz=10010102-1-2-2-11

Place a 0 in column 1 in the third row.

Row1+Row3⇒Row3xyz=100101020-2-2-10

Place a 0 in column 2 in the third row.

2Row2+Row3⇒Row3xyz=1001010200-2-6

Place a 1 in column 3 of the third row by dividing the third row by −2.

-0.5Row3⇒Row3xyz=100101020013x=1y=2z=3

8.9.3 Reduced Row Echelon Form

The Reduced Row-Echelon Form is a matrix form that exists after Gaussian elimination, and also goes under the initials RREF. The reduced row echelon form arises when simplifying systems of linear equations. For example, we know that the following equation:

2x+4y-6z=20

can be written:

x+2y-3z=10

without disturbing the equation. Therefore, the RREF strategy derives from such techniques when working with matrices.

A matrix is in a reduced row echelon form if it satisfies the following conditions:

∙ The leading in each nonzero row is 1 (called a leading one).

∙ Each column containing a leading one has zeros in all its other entries.

For example, see the section on Gaussian elimination:

100101020013

8.10 Worked Examples

8.10.1 Matrix Inversion

Invert A and show that AA-1=I2.

A=3524

Solution

Using:

A-1=1detAd-b-ca

then detA=2 and:

A-1=124-5-23

Calculating AA-1:

AA-1=1235244-5-23=122002=1001

8.10.2 Identity Matrix

Invert A and show that AA-1=I3.

A=234121567

Solution

Using Sarrus’s rule for detA:

detA=28+15+24-40-12-21=-6

therefore:

AT=215326417A-1=-16(14-6)-(21-24)(3-8)-(7-5)(14-20)-(2-4)(6-10)-(12-15)(4-3)=-1683-5-2-62-431

and

AA-1=-16234121567.83-5-2-62-431=-16-6000-6000-6=100010001

8.10.3 Solving Two Equations Using Matrices

Solve the following equations using matrices.

20=2x+3y36=7x+2y

Solution

Let:

A=2372

therefore: detA=-17, and:

A-1=-1172-3-72

therefore:

xy=-1172-3-722036=-11740-108-140+72=-117-68-68=44

therefore: x=y=4. We can prove these values by making sure that they satisfy the original equations as follows:

20=2x+3y=2×4+3×4=2036=7x+2y=7×4+2×4=36

8.10.4 Solving Three Equations Using Matrices

Solve the following equations using matrices.

10=2x+y-z13=-x-y+z28=-x+2y+z

Solution

Let:

A=21-1-1-11-121

Using Sarrus’s rule for detA:

detA=-2-1+2+1-4+1=-3

therefore:

AT=2-1-11-12-111A-1=-13(-1-2)-(1+2)(1-1)-(-1+1)(2-1)-(2-1)(-2-1)-(4+1)(-2+1)=-13-3-3001-1-3-5-1

therefore:

xyz=-13-3-3001-1-3-5-1101328=-13-30-3913-28-30-65-28=-13-69-15-123=23541

therefore: x=23,y=5,z=41. We can prove these values by making sure that they satisfy the original equations as follows:

10=2x+y-z=2×23+5-41=1013=-x-y+z=-23-5+41=1328=-x+2y+z=-23+2×5+41=28

8.10.5 Solving Two Complex Equations

Solve the following complex equations using matrices.

7+8i=2x+y-4-i=x-2y

Solution

Let:

A=211-2

therefore: detA=-5, and:

AT=211-2A-1=-15-2-1-12

therefore:

xy=-15-2-1-127+8i-4-i=-15-14-16i+4+i-7-8i-8-2i=-15-10-15i-15-10i=2+3i3+2i

therefore: x=2+3i,y=3+2i. We can prove these values by making sure that they satisfy the original equations as follows:

7+8i=2x+y=2×(2+3i)+(3+2i)=4+6i+3+2i=7+8i-4-i=x-2y=2+3i-2×(3+2i)=2+3i-6-4i=-4-i

8.10.6 Solving Three Complex Equations

Solve the following complex equations using matrices.

0=x+y-z3+3i=2x-y+z-5-5i=-x+y-2z

Solution

Let:

A=11-12-11-11-2

therefore: detA=2-1-2+1-1+4=3, and:

AT=12-11-11-11-2A-1=13(2-1)-(-2+1)0-(-4+1)(-2-1)-(1+2)(2-1)-(1+1)(-1-2)

therefore:

xyz=131103-3-31-2-303+3i-5-5i=133+3i-9-9i+15+15i-6-6i+15+15i=1+i2+2i3+3i

therefore: x=1+i,y=2+2i,z=3+3i. We can prove these values by making sure that they satisfy the original equations as follows:

0=x+y-z=(1+i)+(2+2i)-(3+3i)=3+3i-3-3i=03+3i=2x-y+z=2×(1+i)-(2+2i)+(3+3i)=2+2i-2-2i+3+3i=3+3i-5-5i=-x+y-2z=-(1+i)+(2+2i)-2×(3+3i)=1+i-6-6i=-5-5i

8.10.7 Solving Two Complex Equations

Solve the following complex equations using matrices.

3+5i=xi+2y5+i=3x-yi

Solution

Let:

A=i23-i

therefore: detA=1-6=-5, and:

AT=i32-iA-1=-15-i-2-3i

therefore:

xy=-15-i-2-3i3+5i5+i=-15-3i+5-10-2i-9-15i+5i-1=-15-5-5i-10-10i=1+i2+2i

therefore: x=1+i,y=2+2i. We can prove these values by making sure that they satisfy the original equations as follows:

3+5i=xi+2y=i×(1+i)+2×(2+2i)=-1+i+4+4i=3+5i5+i=3x-yi=3×(1+i)-i(2+2i)=3+3i-2i+2=5+i

8.10.8 Solving Three Complex Equations

Solve the following complex equations using matrices.

6+2i=xi+2y-zi-2+6i=2x-yi+2zi2+10i=2xi+yi+2z

Solution

Let:

A=i2-i2-i2i2ii2

therefore: detA=2-8+2+2i+2i-8=-12+4i, and:

AT=i22i2-ii-i2i2A-1=1-12+4i(-2i+2)-(4-1)(4i+1)-(4+4)(2i-2)-(-2+2i)(2i-2)-(-1-4i)(1-4)=1-12+4i2-2i-31+4i-8-2+2i2-2i-2+2i1+4i-3

therefore:

xyz=1-12+4i2-2i-31+4i-8-2+2i2-2i-2+2i1+4i-36+2i-2+6i2+10i=1-12+4i(2-2i)(6+i2)-3(-2+6i)+(1+4i)(2+10i)-8(6+2i)+(-2+2i)(-2+6i)+(2-2i)(2+10i)(-2+2i)(6+2i)+(1+4i)(-2+6i)-3(2+10i)=1-12+4i12+4i-12i+4+6-18i+2+10i+8i-40-48-16i+4-12i-4i-12+4+20i-4i+20-12-4i+12i-4-2+6i-8i-24-6-30i=1-12+4i-16-8i-32-16i-48-24i

multiply by the conjugate of -12+4i:

xyz=-12-4i160-16-8i-32-16i-48-24i

therefore:

x=1160(-12-4i)(-16-8i)=1160(192+64i+96i-32)=1160(160+160i)=1+iy=1160(-12-4i)(-32-16i)=1160(384+128i+192i-64)=1160(320+320i)=2+2iz=1160(-12-4i)(-48-24i)=1160(576+192i+288i-96)=1160(480+480i)=3+3i

therefore: x=1+i,y=2+2i,z=3+3i. We can prove these values by making sure that they satisfy the original equations as follows:

6+2i=xi+2y-zi=i(1+i)+2(2+2i)-i(3+3i)=i-1+4+4i-3i+3=6+2i-2+6i=2x-yi+2zi=2(1+i)-i(2+2i)+2i(3+3i)=2+2i-2i+2+6i-6=-2+6i2+10i=2xi+yi+2z=2i(1+i)+i(2+2i)+2(3+3i)=2i-2+2i-2+6+6i=2+10i

8.10.9 Augmented Matrix

Make the following matrix into an augmented matrix.

xy=24431216

Solution

xy=24124316

8.10.10 Gaussian Elimination

Solve the system of linear equations using Gaussian elimination:

2x+2y+2z=30-y-2z=-17-x-2y-2z=-26

Solution

The solution terminates when the augmented matrix contains a RREF.

Starting with the following augmented matrix.

xyz=222300-1-2-17-1-2-2-26

Place a 1 in column 1 and 0s column 2 and 3 of the first row.

Row1+Row3⇒Row1xyz=10040-1-2-17-1-2-2-26

Place a 1 in column 2 of the second row by reversing the sign of the second row.

-Row2⇒Row2xyz=100401217-1-2-2-26

Place a 1 in column 3 and a 0 in column 2 of the third row.

Row2+0.5Row3⇒Row3xyz=100401217-0.5014

Place a 0 in column 1of the third row.

0.5Row1+Row3⇒Row3xyz=1004012170016

Place a 0 in column 3 of the second row.

Row2-2Row3⇒Row2xyz=100401050016x=4y=5z=6

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_9

9. Complex Numbers

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

9.1 Introduction

In this chapter we investigate complex numbers and show how they can be thought of as an ordered pair. We also show how they are represented by a matrix. Many of the qualities associated with quaternions are found in complex numbers, which is why they are worthy of close examination. Readers interested in this subject may want to examine the author’s book Imaginary Mathematics for Computer Science [1].

9.2 Definition of a Complex Number

By definition, a complex number is the combination of a real number and an imaginary number, and is expressed as:

z=a+bi,a,b∈R,i2=-1

The set of complex numbers is C, which permits us to write z∈C. For example, 3+4i is a complex number where 3 is the real part and 4i is the imaginary part. The following are all complex numbers:

3,3+4i,-4-6i7i,5.5+6.7i

A real number is also a complex number–it just has no imaginary part. This leads to the idea that the set of real numbers is a subset of complex numbers, which is expressed as:

R⊂C

where ⊂ means is a subset of.

Although some mathematicians place i before its multiplier: i4, others place it after the multiplier: 4i, which is the convention used in this book. However, when i is associated with trigonometric functions, it is good practice to place it before the function to avoid any confusion with the function’s angle. For example, sinαi could imply that the angle is imaginary, whereas isinα implies that the value of sinα is imaginary.

Therefore, a complex number can be constructed in all sorts of ways:

sinα+icosβ,2-itanα,23+x2i

In general, we write a complex number as a+bi and subject it to the normal rules of real algebra. All that we have to remember is that whenever we encounter i2 it is replaced by -1. For example:

(2+3i)(3+4i)=2×3+2×4i+3i×3+3i×4i=6+8i+9i+12i2=6+17i-12=-6+17i

9.2.1 Addition and Subtraction of Complex Numbers

        The addition and subtraction of two complex numbers is achieved as follows. Given two complex numbers:

z1=a1+b1iz2=a2+b2i

then:

z1±z2=(a1±a2)+(b1±b2)i

where the real and imaginary parts are added or subtracted, respectively. The operations are closed, so long as a1,b1,a2,b2∈R.

For example:

z1=2+3iz2=4+2iz1+z2=6+5iz1-z2=-2+i

9.2.2 Multiplying a Complex Number by a Scalar

Multiplying a complex number by a scalar using normal algebraic rules. For example, the complex number a+bi is multiplied by the scalar λ as follows:

λ(a+bi)=λa+λbi

For example:

3(2+5i)=6+15i

9.2.3 Product of Complex Numbers

    The product of two complex numbers is achieved as follows. Given two complex numbers:

z1=a1+b1iz2=a2+b2i

their product is:

z1z2=(a1+b1i)(a2+b2i)=a1a2+a1b2i+b1a2i+b1b2i2=(a1a2-b1b2)+(a1b2+b1a2)i

which is another complex number and confirms that the operation is closed. For example:

z1=3+4iz2=3-2iz1z2=(3+4i)(3-2i)=9-6i+12i-8i2=9+6i+8=17+6i

Note that the addition, subtraction and multiplication of complex numbers obey the normal axioms of algebra.

9.2.4 Square of a Complex Number

    The square of a complex number is given by:

z=a+biz2=(a+bi)(a+bi)=a2-b2+2abi

For example:

z=4+3iz2=(4+3i)(4+3i)=42-32+2×4×3i=7+24i

9.2.5 Norm of a Complex Number

        The norm, modulus or absolute value of a complex number is given by:

z=a+bi|z|=a2+b2

For example, the norm of 3+4i is 5. We’ll see why this is so when we cover the polar representation of a complex number.

9.2.6 Complex Conjugate of a Complex Number

    The complex conjugate of a complex number, is the same complex number, but with the sign of the complex part reversed. When this is multiplied by the original complex number, it results, always, in a real number:

(a+bi)(a-bi)=a2-abi+abi-b2i2=a2+b2

The complex conjugate of the complex number z is written either with a bar z¯, or an asterisk z∗, and implies that:

zz∗=a2+b2=|z|2

For example:

z=3+4iz∗=3-4izz∗=9+16=25

9.2.7 Divide Complex Numbers

    The complex conjugate provides us with a mechanism to divide complex numbers. For example, the quotient:

a1+b1ia2+b2i

is resolved by multiplying the numerator and denominator by the denominator’s complex conjugate a2-b2i to create a real denominator:

a1+b1ia2+b2i=(a1+b1i)(a2-b2i)(a2+b2i)(a2-b2i)=a1a2-a1b2i+b1a2i-b1b2i2a22+b22=a1a2+b1b2a22+b22+b1a2-a1b2a22+b22i

For example, to evaluate:

4+3i3+4i

we multiply top and bottom by the complex conjugate 3-4i:

4+3i3+4i=(4+3i)(3-4i)(3+4i)(3-4i)=12-16i+9i-12i225=2425-725i

9.2.8 Inverse of a Complex Number

    The inverse of a complex number like z=a+bi, we start with:

z-1=1z

Multiplying top and bottom by z∗ we have:

z-1=z∗zz∗

But we have previously shown that zz∗=|z|2, therefore:

z-1=z∗|z|2=aa2+b2-ba2+b2i

As an example, the inverse of 3+4i is:

(3+4i)-1=325-425i

Let’s test this result by multiplying 3+4i by its inverse:

(3+4i)325-425i=925-1225i+1225i+1625=1

which confirms the correctness of the result.

9.2.9 Square-Root of i

  To find the square-root of ± i we assume that the roots are complex. Therefore, we start with:

i=a+bii=(a+bi)(a+bi)=a2+2abi-b2=a2-b2+2abi

Equating real and imaginary parts we have:

a2-b2=02ab=1

From this we deduce that:

a=b=±22

Therefore, the roots are:

i=±22(1+i)

Let’s test this result by squaring each root to ensure the answer is i:

±222(1+i)(1+i)=122i=i

To find -i we assume that the roots are complex. Therefore, we start with:

-i=a+bi-i=(a+bi)(a+bi)=a2+2abi-b2=a2-b2+2abi

Equating real and imaginary parts we have:

a2-b2=02ab=-1

From this we deduce that:

a=b=±22i

Therefore, the roots are:

-i=±22i(1+i)=±22(-1+i)=±22(1-i)

Let’s test this result by squaring each root to ensure the answer is -i:

±222(1-i)(1-i)=-122i=-i

We use these roots in the next chapter to investigate the rotational properties of complex numbers.

9.3 Ordered Pairs

    So far, we have chosen to express a complex number as a+bi where we can distinguish between the real and imaginary parts. However, one thing we cannot assume is that the real part is always first, and the imaginary part second, because bi+a is also a complex number. Consequently, two functions are employed to extract the real and imaginary coefficients as follows:

Re(a+bi)=aIm(a+bi)=b

and leads us to the idea of representing a complex number by an ordered pair where order is guaranteed:

a+bi=(a,b)

where b follows a to define the order. Thus the set C of complex numbers is equivalent to the set R2 of ordered pairs (a,b).

Writing a complex number as an ordered pair was a great contribution, and first made by Hamilton in 1833. Such notation is very succinct and free from any imaginary term, which can be added whenever required. 

9.3.1 Addition and Subtraction of Ordered Pairs

        Given two complex numbers:

z1=a1+b1iz2=a2+b2i

they are written as ordered pairs:

z1=(a1,b1)z2=(a2,b2)

and

z1±z2=(a1±a2,b1±b2)

where the two parts are added or subtracted, respectively.

For example:

z1=2+3i=(2,3)z2=4+2i=(4,2)z1+z2=(6,5)z1-z2=(-2,1)

9.3.2 Multiplying an Ordered Pair by a Scalar

  We have already seen how a complex number is multiplied by a scalar, which must be the same as ordered pairs:

λ(a,b)=(λa,λb)

An example is:

3(2,5)=(6,15)

9.3.3 Product of Ordered Pairs

 Given two complex numbers:

z1=a1+b1iz2=a2+b2i

their product is:

z1z2=(a1a2-b1b2)+(a1b2+b1a2)i

Therefore, the product of ordered pairs is:

z1=(a1,b1)z2=(a2,b2)z1z2=(a1,b1)(a2,b2)=(a1a2-b1b2,a1b2+b1a2)

For example:

z1=(6,2)z2=(4,3)z1z2=(6,2)(4,3)=(24-6,18+8)=(18,26)

9.3.4 Square of an Ordered Pair

  The square of a complex number is given by:

z=a+biz2=(a+bi)(a+bi)=a2-b2+2abi

Therefore, the square of an ordered pair is:

z=(a,b)z2=(a,b)(a,b)=a2-b2,2ab

For example:

z=(4,3)z2=(4,3)(4,3)=42-32,2×4×3=(7,24)

Let’s continue to develop an algebra based upon ordered pairs that is identical to the algebra of complex numbers. We start by writing:

z=(a,b)=(a,0)+(0,b)=a(1,0)+b(0,1)

which creates the unit ordered pairs (1,0) and (0,1).

Now let’s compute the product (1,0)(1,0):

(1,0)(1,0)=(1-0,0)=(1,0)

which shows that (1,0) behaves like the real number 1. i.e. (1,0)=1.

Next, let’s compute the product (0,1)(0,1):

(0,1)(0,1)=(0-1,0)=(-1,0)

which is the real number -1:

(0,1)2=-1

or

(0,1)=-1andisimaginary.

This means that the ordered pair (a,b), together with its associated rules, represents a complex number. i.e. (a,b)≡a+bi.

9.3.5 Norm of an Ordered Pair

        The norm of an ordered pair, or modulus, or absolute value of z is written |z| and by definition is:

z=(a,b)|z|=a2+b2

For example, the norm of (3,4) is 5.

9.3.6 Complex Conjugate of an Ordered Pair

  The complex conjugate of an ordered pair z=(a,b) is z∗=(a,-b).

z=(a,b)z∗=(a,-b)zz∗=(a,b)(a,-b)=(a2+b2,ba-ab)=(a2+b2,0)=a2+b2=|z|2

9.3.7 Quotient of an Ordered Pair

  The technique for resolving the quotient of complex numbers: z1/z2 is to multiply the expression by z2∗/z2∗. Therefore, the quotient of an ordered pair is:

z1z2=(a1,b1)(a2,b2)=(a1,b1)(a2,b2)(a2,-b2)(a2,-b2)=(a1a2+b1b2,b1a2-a1b2)a22+b22,0=a1a2+b1b2a22+b22,b1a2-a1b2a22+b22

For example, to evaluate:

(4,3)(3,4)

we multiply top and bottom by the complex conjugate (3,-4):

(4,3)(3,4)=(4,3)(3,-4)(3,4)(3,-4)=12+1225,9-1625=2425,-725

9.3.8 Inverse of an Ordered Pair

  The inverse of a complex number is z-1:

z-1=z∗zz∗=z∗|z|2

Therefore, the inverse of an ordered pair is:

z=(a,b)z-1=(a,-b)(a,b)(a,-b)=(a,-b)a2+b2,0=aa2+b2,-ba2+b2

As an illustration, the inverse of (3,4) is:

(3,4)-1=325,-425

Let’s test this result by multiplying (3,4) by its inverse:

(3,4)325,-425=925+1625,-1225+1225=(1,0)

9.3.9 Square-Root of i

  To find i we assume that the roots are complex. Therefore, we start with:

i=(a,b)i=(a,b)(a,b)(0,1)=a2-b2,2ab

and equating left and right ordered elements we have:

a2-b2=02ab=1

From this we deduce that:

a=b=±22

Therefore, the roots are:

i=±22(1,1)

Let’s test this result by squaring each root to ensure the answer is i:

±222(1,1)(1,1)=12(0,2)=(0,1)

To find -i we assume that the roots are complex. Therefore, we start with:

-i=(a,b)-i=(a,b)(a,b)(0,-1)=a2-b2,2ab

and equating left and right ordered elements we have:

a2-b2=02ab=-1

From this we deduce that:

a=b=±22i=±22(0,1)(1,1)=±22(-1,1)

Therefore, the roots are:

-i=±22(1,-1)

Let’s test this result by squaring each root to ensure the answer is -i:

±222(1,-1)(1,-1)=12(0,-2)=(0,-1)

It is obvious from the above definitions that ordered pairs provide an alternative notation for expressing complex numbers, where the imaginary feature is embedded within the product axiom. We will also use ordered pairs to define a quaternion with three imaginary terms, which when incorporated within the product axiom remain hidden.

9.4 Matrix Representation of a Complex Number

  As quaternions have a matrix representation, perhaps we should investigate the matrix representation for a complex number.

Although I have only hinted that i can be regarded as some sort of rotational operator, this is the perfect way of visualising it. In Chap. 2 we discovered that multiplying a complex number by i effectively rotates the number 90∘ anticlockwise. So for the moment, it can be represented by a rotation matrix of 90∘: 

i≡cos90∘-sin90∘sin90∘cos90∘=0-110

and the 2×2 identity matrix is:

1001

This permits us to write a complex number as:

a+bi=a1001+b0-110=a00a+0-bb0=a-bba

Note that the matrix representing i squares to -1:

0-1100-110=-100-1=-11001

However, we must also remember that i2=(-i)2=-1, which is interpreted as anticlockwise and clockwise rotations in the complex plane. This is confirmed by:

01-1001-10=-100-1=-11001

Now let’s employ matrix notation for all the arithmetic operations used for complex numbers.

9.4.1 Adding and Subtracting Complex Numbers

        Two complex numbers are added or subtracted as follows:

z1=a1+b1iz2=a2+b2iz1=a1-b1b1a1z2=a2-b2b2a2z1±z2=a1-b1b1a1±a2-b2b2a2=a1±a2-(b1±b2)b1±b2a1±a2

For example:

z1=2+3iz2=4+2iz1=2-332z2=4-224z1±z2=2-332±4-224z1+z2=6-556=6+5iz1-z2=-2-11-2=-2+i

9.4.2 Product of Two Complex Numbers

  The product of two complex numbers is computed as follows:

z1=a1+b1iz2=a2+b2iz1z2=a1-b1b1a1a2-b2b2a2=a1a2-b1b2-(a1b2+b1a2)a1b2+b1a2a1a2-b1b2

For example:

z1=6+2iz2=4+3iz1z2=6-2264-334=24-6-(18+8)18+824-6=18-262618

9.4.3 Norm Squared of a Complex Number

    The square of the norm is as the determinant of the matrix:

z=a+bi=a-bba|z|2=a2+b2=a-bba

9.4.4 Complex Conjugate of a Complex Number

  The complex conjugate of a complex number is:

z=a+bi=a-bbaz∗=a-bi=ab-ba

The product zz∗=a2+b2:

zz∗=a-bbaab-ba=a2+b200a2+b2=a2+b21001

For example:

z=3+4i=3-443z∗=3-4i=34-43zz∗=3-44334-43=250025=251001

9.4.5 Inverse of a Complex Number

  The inverse of 2×2 matrix A is given by:

A=a11a12a21a22A-1=1a11a22-a12a21a22-a12-a21a12

therefore, the inverse of z is given by:

z=a+biz=a-bbaz-1=1a2+b2ab-ba

For example:

z=3+4iz=3-443z-1=12534-43

9.4.6 Quotient of Two Complex Numbers

  The quotient of two complex numbers is computed as follows:

z1=a1+b1iz2=a2+b2iz1z2=z1z2-1=a1-b1b1a11a22+b22a2b2-b2a2=1a22+b22a1a2+b1b2-(b1a2-a1b2)b1a2-a1b2a1a2+b1b2

For example:

z1=4+3iz2=3+4iz1z2=z1z2-1=4-33419+1634-43=125247-724

9.4.7 Square-Root of i

  To find i we assume that the roots are complex. Therefore, we start with:

i=a-bbai=a-bbaa-bba0-110=a2-b2-2ab2aba2-b2

and equating left and right matrices we have:

a2-b2=02ab=1

From this we deduce that:

a=b=±22

Therefore, the roots are:

i=±221-111

Let’s test this result by squaring each root to ensure the answer is i:

±2221-1111-111=120-220=i

To find -i we assume that the roots are complex. Therefore, we start with

-i=a-bba-i=a-bbaa-bba01-10=a2-b2-2ab2aba2-b2

and equating left and right matrices we have:

a2-b2=02ab=-1

From this we deduce that:

a=b=±22i

Therefore, the roots are:

-i=±220-1101-111=±2211-11

Let’s test this result by squaring each root to ensure the answer is i:

±22211-1111-11=1202-20=-i

9.5 Summary

We have shown in this chapter that there is a one-to-one correspondence between a complex number and an ordered pair, and that a complex number can be represented as a matrix, which permits us to compute all complex number operations as matrix operations or ordered pairs.

If this the first time you have come across complex numbers you probably will have found them strange on the one hand, and amazing on the other. Simply by declaring the existence of i that squares to -1, opens up a new number system that unifies large areas of mathematics.

9.6 Worked Examples

Here are some worked examples that employ the ideas described above. In some cases a test is included to confirm the result.

9.6.1 Adding and Subtracting Complex Numbers

Add and subtract z1 and z2.

Solution

Complex Number:

z1=12+6iz2=10-4iz1+z2=22+2iz1-z2=2+10i

Ordered Pair:

z1=(12,6)z2=(10,-4)z1+z2=(12,6)+(10,-4)=(22,2)z1-z2=(12,6)-(10,-4)=(2,10)

Matrix:

z1=12-6612z2=104-410z1+z2=12-6612+104-410=22-2222z1-z2=12-6612-104-410=2-10102

9.6.2 Product of Complex Numbers

Compute the product z1z2.

Solution

Complex Number:

z1=12+6iz2=10-4iz1z2=(12+6i)(10-4i)=144+12i

Ordered Pair:

z1=(12,6)z2=(10,-4)z1z2=(12,6)(10,-4)=(120+24,-48+60)=(144,12)

Matrix:

z1=12-6612z2=104-410z1z2=12-6612104-410=144-1212144

9.6.3 Multiplying a Complex Number by i

Multiply z1 by i.

Solution

Complex Number:

z1=12+6iz1i=(12+6i)i=-6+12i

Ordered Pair:

z1=(12,6)i=(0,1)z1i=(12,6)(0,1)=(-6,12)

Matrix:

z1=12-6612i=0-110z1z2=12-66120-110=-6-1212-6

9.6.4 The Norm of a Complex Number

Compute the norm of z1.

Solution

Complex Number:

z1=12+6i|z1|=122+62≈13.416

Ordered Pair:

z1=(12,6)|z1|=122+62≈13.416

Matrix:

z1=12-6612|z1|=12-6612=122+62≈13.416

9.6.5 The Complex Conjugate of a Complex Number

Compute the complex conjugate of the following:

2+3i,1,i

Solution

Complex Number:

(2+3i)∗=2-3i1∗=1i∗=-i

Ordered Pair:

(2,3)∗=(2,-3)(1,0)∗=(1,0)(0,1)∗=(0,-1)

Matrix:

z=2-332z∗=23-321=10011∗=1001i=0-110i∗=01-10

9.6.6 The Quotient of Two Complex Numbers

Compute the quotient

(2+3i)/(3+4i)

Solution

Complex Number:

2+3i3+4i=(2+3i)(3+4i)(3-4i)(3-4i)=6-8i+9i+1225=1825+125i

Ordered Pair:

(2,3)(3,4)=(2,3)(3,4)(3,-4)(3,-4)=(6+12,1)(9+16,0)=1825,125

Matrix:

z1=2-332z2=3-443z1z2=z1z2-1=1252-33234-43=12518-1118

9.6.7 Divide a Complex Number by i

Divide 2+3i by i.

Solution

Complex Number:

2+3i0+i=(2+3i)(0+i)(0-i)(0-i)=-2i+31=3-2i

Ordered Pair:

(2,3)(0,1)=(2,3)(0,1)(0,-1)(0,-1)=(3,-2)(1,0)=(3,-2)

Matrix:

z=2-332i=0-110i-1=01-10zi-1=2-33201-10=32-23

9.6.8 Divide a Complex Number by -i

Divide 2+3i by -i.

Solution

Complex Number:

2+3i0-i=(2+3i)(0-i)(0+i)(0+i)=2i-31=-3+2i

Ordered Pair:

(2,3)(0,-1)=(2,3)(0,-1)(0,1)(0,1)=(-3,2)1=(-3,2)

Matrix:

z=2-332-i=01-10-i-1=0-110z-i-1=2-3320-110=-3-22-3

9.6.9 The Inverse of a Complex Number

Compute the inverse of 2+3i.

Solution

Complex Number:

12+3i=1(2+3i)(2-3i)(2-3i)=2-3i13=213-313i

Ordered Pair:

1(2,3)=1(2,3)(2,-3)(2,-3)=(2,-3)13=213,-313

Matrix:

z=2-332z-1=11323-32

9.6.10 The Inverse of i

Compute the inverse of i.

Solution

Complex Number:

10+i=1(0+i)(0-i)(0-i)=-i1=-i

Ordered Pair:

1(0,1)=1(0,1)(0,-1)(0,-1)=(0,-1)(1,0)=(0,-1)=-i

Matrix:

i=0-110i-1=01-10=-i

9.6.11 The Inverse of -i

Compute the inverse of -i.

Solution

Complex Number:

10-i=1(0-i)(0+i)(0+i)=i1=i

Ordered Pair:

1(0,-1)=1(0,-1)(0,1)(0,1)=(0,1)(1,0)=(0,1)=i

Matrix:

-i=01-10-i-1=0-110=i

References

1.

Vince J (2018) Imaginary mathematics for computer science. Springer

2.

Descartes R (1637) La Géométrie (There is an English translation by Michael Mahoney) Dover, New York, 1979

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_10

10. Geometric Transforms

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

10.1 Introduction

This chapter shows how matrices are used to scale, translate, reflect, shear and rotate 2D shapes and 3D objects. The reader should try to understand the construction of the various matrices and recognise the role of each matrix element. After a little practice it will be possible to define a wide variety of matrices without thinking about the underlying algebra.

10.2 Background

A point P(x,y) is transformed into P′(x′,y′) by manipulating the original coordinates x and y using:

x′=ax+by+ey′=cx+dy+f

where a,b,c,d,e and f have assigned values. Similarly, a 3D point P(x,y,z) is transformed into P′(x′,y′,z′) using:

x′=ax+by+cz+ky′=dx+ey+fz+lz′=gx+hy+jz+m

The values for a,b,c,⋯ etc. determine whether the transform translates, shears, scales, reflects or rotates a point.

Although transforms have an algebraic origin, it is convenient to express them as matrices, which provide certain advantages for viewing the transform and for interfacing to various types of computer graphics hardware. We begin with an algebraic approach and then introduce matrix notation.

10.3 2D Transforms

10.3.1 Translation

Cartesian coordinates  provide a one-to-one relationship between number and shape, such that when we change a shape’s coordinates, we change its geometry. For example, if P(x,y) is a shape’s vertex, when we apply the operation x′=x+3 we create a new point P′(x′,y) three units to the right. Similarly, the translation operation y′=y+1 creates a new point P′(x,y′) displaced one unit vertically. By applying both of these transforms to every vertex on the original shape, the shape is displaced as shown in Fig. 10.1.

Fig. 10.1

The translated shape results by adding 3 to every x-coordinate, and 1 to every y-coordinate to the original shape

10.3.2 Scaling

Shape scaling is effected by multiplying coordinates as follows:

x′=2.5xy′=1.5y

This transform results in a horizontal scaling of 2.5 and a vertical scaling of 1.5 as illustrated in Fig. 10.2. Note that a point located at the origin does not change its place, so scaling is relative to the origin.

Fig. 10.2

The scaled shape results by multiplying the x-coordinates by 2.5 and the y-coordinates by 1.5

10.3.3 Reflection

To make a reflection of a shape relative to the y-axis, we simply reverse the sign of the x-coordinates, leaving the y-coordinates unchanged:

x′=-xy′=y

and to reflect a shape relative to the x-axis we reverse the y-coordinates:

x′=xy′=-y

Figure 10.3 shows three reflections derived from the original shape by reversing the signs for the x- and y-coordinates. Note that a shape’s vertex order is reversed for each reflection.

Fig. 10.3

The original shape gives rise to three reflections simply by reversing the signs of its coordinates

Before proceeding, we pause to introduce matrix notation so that we can develop further transforms using algebra and matrix algebra side by side.

10.4 Transforms as Matrices

10.4.1 Systems of Matrix Notation

Over time  two systems of matrix notation have evolved: one where the matrix multiplies a column vector, as described above, and another where a row vector multiplies the matrix:

x′y′=xyacbd=ax+bycx+dy

Note how the elements of the matrix are transposed to accommodate the algebraic correctness of the transform. There is no preferred system of notation, and you will find technical books and papers supporting both. Personally, I prefer a matrix premultiplying a column vector, as it is very similar to the original algebraic equations. However, the important thing to remember is that the rows and columns of the matrix are transposed when moving between the two systems.

10.5 Homogeneous Coordinates

Chapter 8 showed how a pair of equations such as:

x′=ax+byy′=cx+dy

can be written in matrix notation as:

x′y′=abcdxy

One immediate problem with this notation is that there is no apparent mechanism to add or subtract a constant such as e or f:

x′=ax+by+ey′=cx+dy+f

Mathematicians resolved this by using homogeneous coordinates, which appeared in the early 19th century where they were independently proposed by the German mathematician August Möbius (1790–1868) (who also is associated with a one-sided curled band, the Möbius strip), and the German mathematician and physicist Julius Plücker (1801–1868). Möbius called them barycentric coordinates, and they have also been called areal coordinates because of their area-calculating properties.

Basically, homogeneous coordinates define a point in a plane using three coordinates instead of two. Initially, Plücker located a homogeneous point relative to the sides of a triangle, but later revised his notation to the one employed in contemporary mathematics and computer graphics. This states that for a point (x,y) there exists a homogeneous point (xt,yt,t) where t is an arbitrary number. For example, the point (3,4) has homogeneous coordinates (6,8,2), because 3=6/2 and 4=8/2. But the homogeneous point (6,8,2) is not unique to (3,4); (12,16,4), (15,20,5) and (300,400,100) are all possible homogeneous coordinates for (3,4).

The reason why this coordinate system is called ‘homogeneous’ is because it is possible to transform functions such as f(x,y) into the form f(x/t,y/t) without disturbing the degree of the curve. To the non-mathematician this may not seem anything to get excited about, but in the field of projective geometry it is a very powerful concept.

Figure 10.4 shows a 3D homogeneous space with axes x, y and h, where a point (x,y,1) is associated with a projected point (xt,yt,t). The figure shows a triangle on the h=1 plane, and a similar triangle on the plane h=t. Thus instead of working in two dimensions, we can work on an arbitrary xy-plane in three dimensions. The h-coordinate of the plane is immaterial because the x- and y-coordinates are eventually divided by t. However, to keep things simple it seems a good idea to choose t=1. This means that the point (x,y) has homogeneous coordinates (x,y,1) making scaling superfluous.

If we substitute 3D homogeneous coordinates for traditional 2D Cartesian coordinates we must attach 1 to every (x,y) pair. When a point (x,y,1) is transformed, it emerges as (x′,y′,1), and we discard the 1. This may seem a futile exercise, but it resolves the problem of creating a translation transform.

Fig. 10.4

2D homogeneous coordinates can be visualised as a plane in 3D space generally where h=1, for convenience

Consider the following transform on the homogeneous point (x,y,1):

x′y′1=abecdf001xy1

This expands to:

x′=ax+by+ey′=cx+dy+f1=1

and solves the above problem of adding a constant. Now let’s move on to see how homogeneous coordinates are used in practice.

10.5.1 2D Translation

The algebraic and matrix notation for 2D translation is:

x′=x+txy′=y+ty

or using matrices:

x′y′1=10tx01ty001xy1

10.5.2 2D Scaling

  The algebraic and matrix notation for 2D scaling is:

x′=sxxy′=syy

or using matrices:

x′y′1=sx000sy0001xy1

The scaling action is relative to the origin, i.e. the point (0,0) remains unchanged. All other points move away from the origin when sx>1, or move towards the origin when sx<1. To scale relative to another point (px,py) we first subtract (px,py) from (x,y) respectively. This effectively makes the reference point (px,py) the new origin. Second, we perform the scaling operation relative to the new origin, and third, add (px,py) back to the new (x,y) respectively to compensate for the original subtraction. Algebraically this is:

x′=sx(x-px)+pxy′=sy(y-py)+py

which simplifies to:

x′=sxx+px(1-sx)y′=syy+py(1-sy)

or as a homogeneous matrix:

x′y′1=sx0px(1-sx)0sypy(1-sy)001xy1

(10.1)

For example, to scale a shape by 2 relative to the point (1,1) the matrix is:

x′y′1=20-102-1001xy1

10.5.3 2D Reflections

The matrix notation for 2D reflecting about the y-axis is:

x′y′1=-100010001xy1

or about the x-axis:

x′y′1=1000-10001xy1

However, to make a reflection about an arbitrary vertical or horizontal axis we need to introduce some more algebraic deception.

To make a reflection about the vertical axis x=1, we first subtract 1 from the x-coordinate. This effectively makes the x=1 axis coincident with the major y-axis. Next, we perform the reflection by reversing the sign of the modified x-coordinate. And finally, we add 1 to the reflected coordinate to compensate for the original subtraction. Algebraically, the three steps are:

x1=x-1x2=-(x-1)x′=-(x-1)+1

which simplifies to:

x′=-x+2y′=y

or in matrix form:

x′y′1=-102010001xy1

Figure 10.5 illustrates this process.

Fig. 10.5

The shape on the right is reflected about the x=1 axis

To reflect a point about an arbitrary y-axis, x=ax, the following transform is required:

x′=-(x-ax)+ax=-x+2axy′=y

or in matrix form:

x′y′1=-102ax010001xy1

(10.2)

Similarly, to reflect a point about an arbitrary x-axis y=ay, the following transform is required:

x′=xy′=-(y-ay)+ay=-y+2ay

or in matrix form:

x′y′1=1000-12ay001xy1

Fig. 10.6

The original green, square shape is sheared to the right by an angle β, and the horizontal shear is proportional to ytanβ

10.5.4 2D Shearing

A shape is 2D sheared by leaning it over at an angle β. Figure 10.6 illustrates the geometry, and we see that the y-coordinates remain unchanged but the x-coordinates are a function of y and tanβ:

x′=x+ytanβy′=y

or in matrix form:

x′y′1=1tanβ0010001xy1

10.5.5 2D Rotation

Figure 10.7 shows a point P(x,y), distance R from the origin, which is to be rotated by an angle β about the origin to P′(x′,y′). It can be seen that:

x′=Rcos(θ+β)y′=Rsin(θ+β)

and substituting the identities for cos(θ+β) and sin(θ+β) we have:

x′=R(cosθcosβ-sinθsinβ)y′=R(sinθcosβ+cosθsinβ)x′=RxRcosβ-yRsinβy′=RyRcosβ+xRsinβx′=xcosβ-ysinβy′=xsinβ+ycosβ

or in matrix form:

x′y′1=cosβ-sinβ0sinβcosβ0001xy1

For example, to rotate a point through 90∘ the matrix is:

x′y′1=0-10100001xy1

Thus the point (1,0) becomes (0,1). If we rotate through 360∘ the matrix becomes:

x′y′1=100010001xy1

Such a matrix has a null effect and is called an identity matrix.

Fig. 10.7

The point P(x,y) is rotated through an angle β to P′(x′,y′)

To rotate a point (x,y) about an arbitrary point (px,py) we first, subtract (px,py) from the coordinates (x,y) respectively. This enables us to perform the rotation about the origin. Second, we perform the rotation, and third, we add (px,py) to compensate for the original subtraction. Here are the steps:

1. Subtract (px,py):

x1=(x-px)y1=(y-py)

2. Rotate β about the origin:

x2=(x-px)cosβ-(y-py)sinβy2=(x-px)sinβ+(y-py)cosβ.

3. Add (px,py):

x′=(x-px)cosβ-(y-py)sinβ+pxy′=(x-px)sinβ+(y-py)cosβ+py

Simplifying:

x′=xcosβ-ysinβ+px(1-cosβ)+pysinβy′=xsinβ+ycosβ+py(1-cosβ)-pxsinβ

and in matrix form:

x′y′1=cosβ-sinβpx(1-cosβ)+pysinβsinβcosβpy(1-cosβ)-pxsinβ001xy1

(10.3)

For example, to rotate a point 90∘ about the point (1,1) the matrix operation becomes:

x′y′1=0-12100001xy1

A simple test is to substitute the point (2,1) for (x,y); which is transformed correctly to (1,2).

The algebraic approach in deriving the above transforms is relatively easy. However, it is also possible to use matrices to derive compound transforms, such as a reflection relative to an arbitrary line and scaling and rotation relative to an arbitrary point. These transforms are called affine, as parallel lines remain parallel after being transformed. Furthermore, the word ‘affine’ is used to imply that there is a strong geometric affinity between the original and transformed shape. One can not always guarantee that angles and lengths are preserved, as the scaling transform can alter these when different x and y scaling factors are used. For completeness, we will repeat these transforms from a matrix perspective.

10.5.6 2D Scaling

The strategy used to scale a point (x,y) relative to some arbitrary point (px,py) is to first, translate (-px,-py); second, perform the scaling; and third translate (px,py). These three transforms are represented in matrix form as follows:

x′y′1=translate(px,py)scale(sx,sy)translate(-px,-py)xy1

which expands to:

x′y′1=10px01py001sx000sy000110-px01-py001xy1

Note the sequence of the transforms, as this often causes confusion. The first transform acting on the point (x,y,1) is translate (-px,-py), followed by scale (sx,sy), followed by translate (px,py). If they are placed in any other sequence, you will discover, like Gauss, that transforms are not commutative!

We can now combine these matrices into a single matrix by multiplying them together. This can be done in any sequence, so long as we preserve the original order. Let’s start with scale (sx,sy) and translate (-px,-py) matrices. This produces:

x′y′1=10px01py001sx0-sxpx0sy-sypy001xy1

and finally:

x′y′1=sx0px(1-sx)0sypy(1-sy)001xy1

which is the same as the previous transform (10.1).

10.5.7 2D Reflection

2D reflection about the y-axis is given by:

x′y′1=-100010001xy1

Therefore, using matrices, we can reason that a reflection transform about an arbitrary axis x=ax, parallel with the y-axis, is given by:

x′y′1=translate(ax,0)reflectiontranslate(-ax,0)xy1

which expands to:

x′y′1=10ax010001-10001000110-ax010001xy1

We can now combine these matrices into a single matrix by multiplying them together. Let’s begin by multiplying the reflection and the translate (-ax,0) matrices together. This produces:

x′y′1=10ax010001-10ax010001xy1

and finally:

x′y′1=-102ax010001xy1

which is the same as the previous transform (10.2).

10.5.8 2D Rotation About an Arbitrary Point

A 2D rotation about the origin is given by:

x′y′1=cosβ-sinβ0sinβcosβ0001xy1

Therefore, using matrices, we can develop a rotation about an arbitrary point (px,py) as follows:

x′y′1=translate(px,py)rotateβtranslate(-px,-py)xy1

which expands to:

x′y′1=10px01py001cosβ-sinβ0sinβcosβ000110-px01-py001xy1

We can now combine these matrices into a single matrix by multiplying them together. Let’s begin by multiplying the rotate β and the translate (-px,-py) matrices together. This produces:

x′y′1=10px01py001cosβ-sinβ-pxcosβ+pysinβsinβcosβ-pxsinβ-pycosβ001xy1x′y′1=cosβ-sinβpx(1-cosβ)+pysinβsinβcosβpy(1-cosβ)-pxsinβ001xy1

which is the same as the previous transform (10.3).

I hope it is now clear to the reader that one can derive all sorts of transforms either algebraically, or by using matrices–it is just a question of convenience.

10.6 3D Transforms

Now we come to 3D transforms, where we apply the same reasoning as in two dimensions. Scaling and translation are basically the same, but where in 2D we rotated a shape about a point, in 3D we rotate an object about an axis.

10.6.1 3D Translation

The algebra is so simple for 3D translation that we can simply write the homogeneous matrix directly:

x′y′z′1=100tx010ty001tz0001xyz1

10.6.2 3D Scaling

The algebra for 3D scaling is:

x′=sxxy′=syyz′=szz

which in matrix form is:

x′y′z′1=sx0000sy0000sz00001xyz1

The scaling is relative to the origin, but we can arrange for it to be relative to an arbitrary point (px,py,pz) using the following algebra:

x′=sx(x-px)+pxy′=sy(y-py)+pyz′=sz(z-pz)+pz

which in matrix form is:

x′y′z′1=sx00px(1-sx)0sy0py(1-sy)00szpz(1-sz)0001xyz1

10.6.3 3D Rotation

In 2D a shape is rotated about a point, whether it be the origin or some other position. In 3D an object is rotated about an axis, whether it be the x-, y- or z-axis, or some arbitrary axis. To begin with, let’s look at a 3D rotation transform of a point about one of the three orthogonal axes; such rotations are called Euler rotations after Leonhard Euler.

Recall that a general 2D rotation transform is given by:

x′y′1=cosβ-sinβ0sinβcosβ0001xy1

which in 3D can be visualised as rotating a point P(x,y,z) on a plane parallel with the xy-plane as shown in Fig. 10.8. In algebraic terms this is written as:

x′=xcosβ-ysinβy′=xsinβ+ycosβz′=z

Therefore, the 3D rotation transform is:

x′y′z′1=cosβ-sinβ00sinβcosβ0000100001xyz1

which basically rotates a point about the z-axis.

Fig. 10.8

Rotating the point P, through an angle β, about the z-axis

When rotating about the x-axis, the x-coordinates remain constant whilst the y- and z-coordinates are changed. Algebraically, this is:

x′=xy′=ycosβ-zsinβz′=ysinβ+zcosβ

or in matrix form:

x′y′z′1=10000cosβ-sinβ00sinβcosβ00001xyz1

When rotating about the y-axis, the y-coordinate remains constant whilst the x- and z-coordinates are changed. Algebraically, this is:

x′=zsinβ+xcosβy′=yz′=zcosβ-xsinβ

or in matrix form:

x′y′z′1=cosβ0sinβ00100-sinβ0cosβ00001xyz1

Note that the matrix terms do not appear to share the symmetry seen in the previous two matrices. Nothing really has gone wrong, it is just the way the axes are paired together to rotate the coordinates.

The above rotations are also known as yaw, pitch and roll, and great care should be taken with these angles when referring to other books and technical papers. Sometimes a left-handed system of axes is used rather than a right-handed set, and the vertical axis may be the y-axis or the z-axis.  Consequently, the matrices representing the rotations can vary greatly. In this chapter all Cartesian coordinate systems are right-handed, and the vertical axis is always the y-axis.

I will define the roll, pitch and yaw angles as follows:

roll is the angle of rotation about the z-axis.

pitch is the angle of rotation about the x-axis.

yaw is the angle of rotation about the y-axis.

Fig. 10.9

A convention for roll, pitch and yaw angles

Figure 10.9 illustrates these rotations and the sign convention. The homogeneous matrices representing these rotations are as follows:

rotate roll about the z-axis:

cosroll-sinroll00sinrollcosroll0000100001

rotate pitch about the x-axis:

10000cospitch-sinpitch00sinpitchcospitch00001

rotate yaw about the y-axis:

cosyaw0sinyaw00100-sinyaw0cosyaw00001

A common sequence for applying these rotations is roll, pitch, yaw, as seen in the following transform:

x′y′z′1=yawpitchrollxyz1

and if a translation is involved:

x′y′z′1=translateyawpitchrollxyz1

When these rotation transforms are applied, the vertex is first rotated about the z-axis (roll), followed by a rotation about the x-axis (pitch), followed by a rotation about the y-axis (yaw). Euler rotations are relative to the fixed frame of reference. This is not always easy to visualise as one’s attention is normally with the rotating frame of reference. Let’s consider a simple example where an axial system is subjected to a pitch rotation followed by a yaw rotation relative to fixed frame of reference.

We begin with two frames of reference XYZ and X′Y′Z′ mutually aligned. Figure 10.10 shows the orientation of X′Y′Z′ after it is subjected to a pitch of 90∘ about the X-axis. And Fig. 10.11 shows the final orientation after X′Y′Z′ is subjected to a yaw of 90∘ about the Y-axis.

Fig. 10.10

The X′Y′Z′ axial system after a pitch of 90∘

Fig. 10.11

The X′Y′Z′ axial system after a yaw of 90∘

Fig. 10.12

The X′Y′Z′ axial system after a roll of 45∘

Fig. 10.13

The X′Y′Z′ axial system after a pitch of 90∘

10.6.4 Gimbal Lock

Let’s take another example starting from the point where the two axial systems are mutually aligned. Figure 10.12 shows the orientation of X′Y′Z′ after it is subjected to a roll of 45∘ about the Z-axis, and Fig. 10.13 shows the orientation of X′Y′Z′ after it is subjected to a pitch of 90∘ about the X-axis. Now the interesting thing about this orientation is that if we now performed a yaw of 45∘ about the Y-axis, it would rotate the X′-axis towards the X-axis, counteracting the effect of the original roll. yaw has become a negative roll rotation, caused by the 90∘ pitch. This situation is known as gimbal lock, because one degree of rotational freedom has been lost. Quite innocently, we have stumbled across one of the major weaknesses of Euler angles: under certain conditions it is only possible to rotate an object about two axes. One way of preventing this is to create a secondary set of axes constructed from three orthogonal vectors that are also rotated alongside an object or virtual camera. But instead of making the rotations relative to the fixed frame of reference, the roll, pitch and yaw rotations are relative to the rotating frame of reference.

10.6.5 Rotating About an Axis

The above rotations were relative to the x-, y-, z-axis. Now let’s consider rotating about an axis parallel to one of these axes. To begin with, we will rotate about an axis parallel with the z-axis, as shown in Fig. 10.14. The scenario is very reminiscent of the 2D case for rotating a point about an arbitrary point, and the general transform is given by:

x′y′z′1=translate(px,py,0)rotateβtranslate(-px,-py,0)xyz1

and the matrix is:

x′y′z′1=cosβ-sinβ0px(1-cosβ)+pysinβsinβcosβ0py(1-cosβ)-pxsinβ00100001xyz1

Fig. 10.14

Rotating a point about an axis parallel with the x-axis

I hope you can see the similarity between rotating in 3D and 2D: the x- and y-coordinates are updated while the z-coordinate is held constant. We can now state the other two matrices for rotating about an axis parallel with the x-axis and parallel with the y-axis:

rotating about an axis parallel with the x-axis:

x′y′z′1=10000cosβ-sinβpy(1-cosβ)+pzsinβ0sinβcosβpz(1-cosβ)-pysinβ0001xyz1

rotating about an axis parallel with the y-axis:

x′y′z′1=cosβ0sinβpx(1-cosβ)-pzsinβ0100-sinβ0cosβpz(1-cosβ)+pxsinβ0001xyz1

10.6.6 3D Reflections

  A 3D reflection occurs with respect to a plane, rather than an axis. The matrix giving the reflection relative to the yz-plane is:

x′y′z′1=-1000010000100001xyz1

and the reflection relative to a plane parallel to, and ax units from the yz-plane is:

x′y′z′1=-1002ax010000100001xyz1

It is left to the reader to develop similar matrices for the other major axial planes.

10.7 Change of Axes

Points in one coordinate system often have to be referenced in another one. For example, to view a 3D scene from an arbitrary position, a virtual camera is positioned in the world space using a series of transforms. An object’s coordinates, which are relative to the world frame of reference, are computed relative to the camera’s axial system, and then used to develop a perspective projection. Before explaining how this is achieved in 3D, let’s examine the simple case of a change of axes in two dimensions.

10.7.1 2D Change of Axes

Figure 10.15 shows a point P(x,y) relative to the XY-axes, but we require to know the coordinates relative to the X′Y′-axes. To do this, we need to know the relationship between the two coordinate systems, and ideally we want to apply a technique that works in 2D and 3D. If the second coordinate system is a simple translation (tx,ty) relative to the reference system, as shown in Fig. 10.15, the point P(x,y) has coordinates relative to the translated system (x-tx,y-ty):

x′y′1=10-tx01-ty001xy1

Fig. 10.15

The X′Y′ axial system is translated (tx,ty)

Fig. 10.16

The X′Y′ axial system is rotated β

If the X′Y′-axes are rotated β relative to the XY-axes, as shown in Fig. 10.16, a point P(x,y) relative to the XY-axes becomes P′(x′,y′) relative to the rotated axes is given by:

x′y′1=cos(-β)-sin(-β)0sin(-β)cos(-β)0001xy1

which simplifies to:

x′y′1=cosβsinβ0-sinβcosβ0001xy1

When a coordinate system is rotated and translated relative to the reference system, a point P(x,y) becomes P′(x′,y′) relative to the new axes given by:

x′y′1=cosβsinβ0-sinβcosβ000110-tx01-ty001xy1

which simplifies to:

x′y′1=cosβsinβ-txcosβ-tysinβ-sinβcosβtxsinβ-tycosβ001xy1

10.7.2 Direction Cosines

Direction cosines are the cosines of the angles between a vector and the Cartesian axes, and for unit vectors they are the vector’s components. Figure 10.17 shows two unit vectors X′ and Y′, and by inspection the direction cosines for X′ are cosβ and cos(90∘-β), which can be rewritten as cosβ and sinβ, and the direction cosines for Y′ are cos(90∘+β) and cosβ, which can be rewritten as -sinβ and cosβ. But these direction cosines cosβ, sinβ, -sinβ and cosβ are the four elements of the rotation matrix used above:

cosβsinβ-sinβcosβ

The top row contains the direction cosines for the X′-axis and the bottom row contains the direction cosines for the Y′-axis. This relationship also holds in 3D.

Fig. 10.17

If the X′- and Y′-axes are assumed to be unit vectors, their direction cosines form the elements of the rotation matrix

As an example, let’s evaluate a simple 2D case where a set of axes is rotated 45∘ as shown in Fig. 10.18. The appropriate transform is:

x′y′1=cos45∘sin45∘0-sin45∘cos45∘0001xy1≈0.7070.7070-0.7070.7070001xy1

The four vertices on a unit square become:

(0,0)→(0,0)(1,0)→(0.707,-0.707)(1,1)→(1.1414,0)(0,1)→(0.707,0.707)

which by inspection of Fig. 10.18 are correct.

Fig. 10.18

The vertices of a unit square relative to the two axial systems

10.7.3 3D Change of Axes

The ability to reference a collection of coordinates is fundamental in computer graphics, especially in 3D. And rather than investigate them within this section, let’s delay their analysis for the next section, where we see how the technique is used for relating an object’s coordinates relative to an arbitrary virtual camera.

10.8 Positioning the Virtual Camera

Four coordinate systems are used in the computer graphics pipeline: object space, world space, camera space and image space.

The object space is a domain where objects are modelled and assembled. 

The world space is where objects are positioned and animated through appropriate transforms. The world space also hosts a virtual camera or observer. 

The camera space is a transform of the world space relative to the camera. 

Finally, the image space is a projection–normally perspective–of the camera space onto an image plane. 

The transforms considered so far are used to manipulate and position objects within the world space. What we will consider next is how a virtual camera or observer is positioned in world space, and the process of converting world coordinates to camera coordinates. The procedure used generally depends on the method employed to define the camera’s frame of reference within the world space, which may involve the use of direction cosines, Euler angles or quaternions.

Fig. 10.19

The components of a unit vector are equal to the cosines of the angles between the vector and the axes

10.8.1 Direction Cosines

A 3D unit vector has three components [xyz]T, which are equal to the cosines of the angles formed between the vector and the three orthogonal axes. These angles are known as direction cosines and can be computed taking the dot product of the vector and the Cartesian unit vectors. Figure 10.19 shows the direction cosines and the angles. These direction cosines enable any point P(x,y,z) in one frame of reference to be transformed into P′(x′,y′,z′) in another frame of reference as follows:

x′y′z′1=r11r12r130r21r22r230r31r32r3300001xyz1

where:

r11,r12,r13 are the direction cosines of the secondary x-axis.

r21,r22,r23 are the direction cosines of the secondary y-axis.

r31,r32,r33 are the direction cosines of the secondary z-axis.

Fig. 10.20

Two axial systems mutually aligned

To illustrate this operation, consider the scenario shown in Fig. 10.20 with two axial systems mutually aligned. Evaluating the direction cosines results in the following matrix transformation:

x′y′z′1=1000010000100001xyz1

which is the identity matrix and implies that (x′,y′,z′)=(x,y,z).

Fig. 10.21

The X′Y′Z′ axial system after a roll of 90∘

Figure 10.21 shows another scenario where the axes are rolled 90∘, and the associated transform is:

x′y′z′1=0100-100000100001xyz1

Substituting (1,1,0) for (x,y,z) produces (1,-1,0) for (x′,y′,z′) in the new frame of reference, which by inspection, is correct.

If the virtual camera is offset by (tx,ty,tz) the transform relating points in world space to camera space is expressed as a compound operation consisting of a translation back to the origin, followed by a change of axial systems. This is expressed as:

x′y′z′1=r11r12r130r21r22r230r31r32r3300001100-tx010-ty001-tz0001xyz1

To illustrate this, consider the scenario shown in Fig. 10.22. The values of (tx,ty,tz) are (10,1,1), and the direction cosines are as shown in the following matrix operation:

x′y′z′1=-1000010000-100001100-10010-1001-10001xyz1

which simplifies to:

x′y′z′1=-10010010-100-110001xyz1

Substituting (0,0,0) for (x,y,z) in the above transform produces (10,-1,1) for (x′,y′,z′), which can be confirmed from Fig. 10.22. Similarly, substituting (0,1,1) for (x,y,z) produces (10,0,0) for (x′,y′,z′), which is also correct.

Fig. 10.22

The secondary axial system is subject to a yaw of 180∘ and an offset of (10,1,1)

10.8.2 Euler Angles

Another approach  for locating the virtual camera involves Euler angles, but we must remember that they suffer from gimbal lock. However, if the virtual camera is located in world space using Euler angles, the transform relating world coordinates to camera coordinates can be derived from the inverse operations. The yaw, pitch, roll matrices described above are called orthogonal matrices, as the inverse matrix is the transpose of the original rows and columns. Consequently, to rotate through angles -roll, -pitch and -yaw, we use:

rotate -roll about the z-axis:

cosrollsinroll00-sinrollcosroll0000100001.

rotate -pitch about the x-axis:

10000cospitchsinpitch00-sinpitchcospitch00001

rotate -yaw about the y-axis:

cosyaw0-sinyaw00100sinyaw0cosyaw00001

The same result is obtained by substituting -roll, -pitch, -yaw in the original matrices. As described above, the virtual camera will normally be translated from the origin by (tx,ty,tz), which implies that the transform from the world space to the camera space must be evaluated as follows:

x′y′z′1=-roll-pitch-yawtranslate(-tx,-ty,-tz)xyz1

which is represented by a single homogeneous matrix:

x′y′z′1=T11T12T13T14T21T22T23T24T31T32T33T34T41T42T43T44xyz1

where:

T11=cos(yaw)cos(roll)+sin(yaw)sin(pitch)sin(roll)T12=cos(pitch)sin(roll)T13=-sin(yaw)cos(roll)+cos(yaw)sin(pitch)sin(roll)T14=-txT11+tyT12+tzT13T21=-cos(yaw)sin(roll)+sin(yaw)sin(pitch)cos(roll)T22=cos(pitch)cos(roll)T23=-sin(yaw)sin(roll)+cos(yaw)sin(pitch)cos(roll)T24=-txT21+tyT22+tzT23T31=sin(yaw)cos(pitch)T32=-sin(pitch)T33=cos(yaw)cos(pitch)T34=-txT31+tyT32+tzT33T41=T42=T43=0T44=1

For example, consider the scenario shown in Fig. 10.22 where the following conditions prevail:

roll=0∘pitch=0∘yaw=180∘tx=10ty=1tz=1

The transform is:

x′y′z′1=-10010010-100-110001xyz1

which is identical to the equation used for direction cosines.

Another scenario is shown in Fig. 10.23 where the following conditions prevail:

roll=90∘pitch=180∘yaw=0∘tx=0.5ty=0.5tz=11

The transform is:

x′y′z′1=0-100.5-1000.500-1110001xyz1

Substituting (1,1,1) for (x,y,z) produces (-0.5,-0.5,10) for (x′,y′,z′). Similarly, substituting (0,0,1) for (x,y,z) produces (0.5,0.5,10) for (x′,y′,z′), which can be visually verified from Fig. 10.23.

Fig. 10.23

The secondary axial system is subject to a roll of 90∘, a pitch of 180∘ and a translation of (0.5,0.5,11)

10.9 Rotating a Point About an Arbitrary Axis

10.9.1 Matrices

Let’s consider two ways of developing a matrix for rotating a point about an arbitrary axis. The first approach employs vector analysis and is quite succinct. The second technique is less analytical and relies on matrices and trigonometric evaluation and is rather laborious. Fortunately, they both arrive at the same result!

Figure 10.24 shows a view of the geometry associated with the task at hand. For clarification, Fig. 10.25 shows a cross-section and a plan view of the geometry.

Fig. 10.24

A view of the geometry associated with rotating a point about an arbitrary axis

Fig. 10.25

A cross-section and plan view of the geometry associated with rotating a point about an arbitrary axis

The axis of rotation is given by the unit vector:

n^=ai+bj+ck

P(xp,yp,zp) is the point to be rotated by angle α to P′(xp′,yp′,zp′).

O is the origin, whilst p and p′ are position vectors for P and P′ respectively.

From Figs. 10.24 and 10.25:

p′=ON→+NQ→+QP′→

To find ON→:

‖n‖=‖p‖cosθ=n^·p

therefore:

ON→=n=n^(n^·p)

To find NQ→:

NQ→=NQNPr=NQNP′r=cosαr

but:

p=n+r=n^(n^·p)+r

therefore:

r=p-n^(n^·p)

and

NQ→=[p-n^(n^·p)]cosα

To find QP′→:

Let:

n^×p=w

where:

‖w‖=‖n^‖‖p‖sinθ=‖p‖sinθ

but:

‖r‖=‖p‖sinθ

therefore:

‖w‖=‖r‖

Now:

QP′NP′=QP′‖r‖=QP′‖w‖=sinα

therefore:

QP′→=wsinα=(n^×p)sinα

then:

p′=n^(n^·p)+[p-n^(n^·p]cosα+(n^×p)sinα

and

p′=pcosα+n^(n^·p)(1-cosα)+(n^×p)sinα.

Let:

K=1-cosα

then:

p′=pcosα+n^(n^·p)K+(n^×p)sinα

and

p′=(xpi+ypj+zpk)cosα+(ai+bj+ck)(axp+byp+czp)K+[(bzp-cyp)i+(cxp-azp)j+(ayp-bxp)k]sinα=[xpcosα+a(axp+byp+czp)K+(bzp-cyp)sinα]i+[ypcosα+b(axp+byp+czp)K+(cxp-azp)sinα]j+[zpcosα+c(axp+byp+czp)K+(ayp-bxp)sinα]k=xpa2K+cosα+yp(abK-csinα)+zp(acK+bsinα)i+xp(abK+csinα)+ypb2K+cosα+zp(bcK-asinα)j+xp(acK-bsinα)+yp(bcK+asinα)+zpc2K+cosαk

and the transform is:

xp′yp′zp′1=a2K+cosαabK-csinαacK+bsinα0abK+csinαb2K+cosαbcK-asinα0acK-bsinαbcK+asinαc2K+cosα00001xpypzp1

where:

K=1-cosα

Now let’s approach the problem using transforms and trigonometric identities. The following is extremely tedious, but it is a good exercise for improving one’s algebraic skills!

Figure 10.26 shows a point P(x,y,z) to be rotated through an angle α to P′(x′,y′,z′) about an axis defined by:

v=ai+bj+ck

where: ‖v‖=1

Fig. 10.26

The geometry associated with rotating a point about an arbitrary axis

The transforms to achieve this operation is expressed as follows:

x′y′z′=T5T4T3T2T1xyz

which aligns the axis of rotation with the x-axis, performs the rotation of P through an angle α about the x-axis, and returns the axis of rotation back to its original position. Therefore:

where:

T1=cosϕ0sinϕ010-sinϕ0cosϕ,T2=cosθsinθ0-sinθcosθ0001T3=1000cosα-sinα0sinαcosα,T4=cosθ-sinθ0sinθcosθ0001T5=cosϕ0-sinϕ010sinϕ0cosϕ

Let:

T5T4T3T2T1=E11E12E130E21E22E230E31E32E3300001

where by multiplying the matrices together we find that:

E11=cos2ϕcos2θ+cos2ϕsin2θcosα+sin2ϕcosαE12=cosϕcosθsinθ-cosϕsinθcosθcosα-sinϕcosθsinα

E13=cosϕsinϕcos2θ+cosϕsinϕsin2θcosα+sin2ϕsinθsinα+cos2ϕsinθsinα-cosϕsinϕcosαE21=sinθcosθcosϕ-cosθsinθcosϕcosα+cosθsinϕsinαE22=sin2θ+cos2θcosαE23=sinθcosθsinϕ-cosθsinθsinϕcosα-cosθcosϕsinαE31=cosϕsinϕcos2θ+cosϕsinϕsin2θcosα-cos2ϕsinθsinα=-cosϕsinϕcosαE32=sinϕcosθsinθ-sinϕsinθcosθcosα+cosϕcosθsinαE33=sin2ϕcos2θ+sin2ϕsin2θcosα-cosϕsinϕsinθsinα+cosϕsinϕsinθsinα+cos2ϕcosα

From Fig. 10.26 we compute the sin and cos of θ and ϕ in terms of a, b and c, and then compute their equivalent sin2 and cos2 values:

cosθ=1-b2⇒cos2θ=1-b2sinθ=b⇒sin2θ=b2cosϕ=a1-b2⇒cos2ϕ=a21-b2sinϕ=c1-b2⇒sin2ϕ=c21-b2.

To find E11:

E11=cos2ϕcos2θ+cos2ϕsin2θcosα+sin2ϕcosα=a21-b2(1-b2)+a21-b2b2cosα+c21-b2cosα=a2+a2b21-b2cosα+c21-b2cosα=a2+c2+a2b21-b2cosα

but:

a2+b2+c2=1⇒c2=1-a2-b2

substituting c2 in E11:

E11=a2+1-a2-b2+a2b21-b2cosα=a2+(1-a2)(1-b2)1-b2cosα=a2+(1-a2)cosα=a2(1-cosα)+cosα.

Let:

K=1-cosα

then:

E11=a2K+cosα

To find E12:

E12=cosϕcosθsinθ-cosϕsinθcosθcosα-sinϕcosθsinα=a1-b21-b2b-a1-b2b1-b2cosα-c1-b21-b2sinα=ab-abcosα-csinα=ab(1-cosα)-csinαE12=abK-csinα

To find E13:

E13=cosϕsinϕcos2θ+cosϕsinϕsin2θcosα+sin2ϕsinθsinα+cos2ϕsinθsinα-cosϕsinϕcosα=cosϕsinϕcos2θ+cosϕsinϕsin2θcosα+sinθsinα-cosϕsinϕcosα=a1-b2c1-b2(1-b2)+a1-b2c1-b2b2cosα+bsinα-a1-b2c1-b2cosα=ac+acb2(1-b2)cosα+bsinα-ac(1-b2)cosα=ac+ac(b2-1)(1-b2)cosα+bsinα=ac(1-cosα)+bsinαE13=acK+bsinα

Using similar algebraic methods, we discover that:

E21=abK+csinαE22=b2K+cosαE23=bcK-asinαE31=acK-bsinαE32=bcK+asinαE33=c2K+cosα

and our original matrix transform becomes:

xp′yp′zp′1=a2K+cosαabK-csinαacK+bsinα0abK+csinαb2K+cosαbcK-asinα0acK-bsinαbcK+asinαc2K+cosα00001xpypzp1

where:

K=1-cosα

which is identical to the transformation derived from the first approach. Now let’s test the matrix with a simple example that can be easily verified. We do this by rotating a point P(10,5,0), about an arbitrary axis v=i+j+k, through 360∘, which should return it to itself producing P(10,5,0).

Therefore:

α=360∘,cosα=1,sinα=0,K=0

a=1,b=1,c=1

and

10501=100001000010000110501

As the matrix is an identity matrix P′=P.

10.10 Transforming Vectors

The transforms described  in this chapter have been used to transform single points. However, a geometric database will not only contain pure vertices, but vectors, which must also be subject to any prevailing transform. A generic transform Q of a 3D point is represented by:

x′y′z′1=Qxyz1

and as a vector is defined by two points we can write:

x′y′z′1=Qx2-x1y2-y1z2-z11-1

where we see the homogeneous scaling term collapse to zero; which implies that any vector [xyz]T can be transformed using:

x′y′z′0=Qxyz0

Let’s put this to the test by using a transform from an earlier example. The problem concerned a change of axial system where a virtual camera was subject to the following:

roll=90∘pitch=180∘yaw=90∘tx=2ty=2tz=0

and the transform is:

x′y′z′1=0-1020010-10020001xyz1

The point (1,1,0) is transformed to (1,0,1), as shown in Fig. 10.27. And the vector [110]T is transformed to [-10-1]T, using the following transform:

-10-10=0-1020010-100200011100

which is correct with reference to Fig. 10.27.

Fig. 10.27

Vector [110]T is transformed to [-10-1]T

10.11 Determinants

Before concluding this chapter, I would like to expand upon the role of determinants in transforms.

In Chap. 6 we saw that determinants arise in the solution of linear equations. Now let’s investigate their graphical significance. Consider the transform:

x′y′=abcdxy

The determinant of the transform is ad-cb. If we subject the vertices of a unit-square to this transform, we create the situation shown in Fig. 10.28. The vertices of the unit-square are transformed as follows:

(0,0)⇒(0,0)(1,0)⇒(a,c)(1,1)⇒(a+b,c+d)(0,1)⇒(b,d)

From Fig. 10.28 it can be seen that the area of the transformed unit-square A′ is given by:

area=(a+b)(c+d)-2B-2C-2D=(ac+ad+cb+bd)-bd-2cb-ac=ad-cb

which is the determinant of the transform. But as the area of the original unit-square is 1, the determinant of the transform controls the scaling factor applied to the transformed shape.

Fig. 10.28

The inner parallelogram is the transformed unit square

Let’s examine the determinants of two transforms: The first 2D transform encodes a scaling of 2, and results in an overall area scaling of 4:

2002

and the determinant is:

2002=4

The second 2D transform encodes a scaling of 3 and a translation of (3,3), and results in an overall area scaling of 9:

303033001

and the determinant is:

33301-00301+00333=9

These two examples demonstrate the extra role played by the elements of a matrix.

10.12 Perspective Projection

Of all the projections employed in computer graphics, the perspective projection is one most widely used. There are two stages to its computation: the first involves converting world coordinates to the camera’s frame of reference, and the second transforms camera coordinates to the projection plane coordinates. We have already looked at the transforms for locating a camera in world space, and the inverse transform for converting world coordinates to the camera’s frame of reference. Let’s now investigate how these camera coordinates are transformed into a perspective projection.

Fig. 10.29

The axial system used to produce a perspective view

Fig. 10.30

The plan view of the camera’s axial system

Fig. 10.31

The side view of the camera’s axial system

We begin by assuming that the camera is directed along the z-axis as shown in Fig. 10.29. Positioned d units along the z-axis is a projection screen, which is used to capture a perspective projection of an object. Figure 10.29 shows that any point (xc,yc,zc) is transformed to (xp,yp,d). It also shows that the screen’s x-axis is pointing in the opposite direction to the camera’s x-axis, which can be compensated for by reversing the sign of xp when it is computed.

Figure 10.30 shows a plan view of the scenario depicted in Figs. 10.29 and 10.31 a side view. Next, we reverse the sign of xp and state:

xczc=-xpdxp=-xczc/d

and

yczc=ypdyp=yczc/d

This is expressed in matrix form as:

xpypzpw=-10000100001/d00001xcyczc1

At first the transform seems strange, but if we multiply this out we get:

[xpypzpw]T=[-xcyczczc/d]T

and if we remember the idea behind homogeneous coordinates, we must divide the terms xp, yp, zp by w to get the scaled terms, which produces:

xp=-xczc/dyp=yczc/dzp=zczc/d=d

which, after all, is rather elegant. Notice that this transform takes into account the sign change that occurs with the x-coordinate. Some algorithms delay this sign reversal until the mapping is made to screen coordinates.

10.13 Summary

The purpose of this chapter was to introduce the reader to transforms and matrices–I hope this has been achieved. This is not the end of the subject, as one can do so much with matrices. For example, it would be interesting to see how a matrix behaves when some of its elements are changed dynamically.

10.14 Worked Examples

10.14.1 2D Scaling Transform

State the 2D homogeneous matrix to scale by a factor of 2 in the x-direction and 3 in the y-direction.

Solution

x′y′1=200030001xy1

10.14.2 2D Scale and Translate

Given matrix T1 which scales a 2D point by a factor of 2, and T2 which translates a 2D point by x=2 and y=2, combine them in two possible ways and show that the point (1,1) is transformed to two different places.

Solution

T1=x′y′1=200020001xy1T2=x′y′1=102012001xy1T1T2=x′y′1=200020001102012001xy1=204024001xy1

and the point (1,1) is transformed to (6,6).

T2T1=x′y′1=102012001200020001xy1=202022001xy1

and the point (1,1) is transformed to (4,4).

10.14.3 3D Scaling Transform

State the 3D homogeneous matrix to scale by a factor of 2 in the x-direction, 3 in the y-direction and 4 in the z-direction, relative to the point (1,1,1), and compute the transformed position of (2,2,2).

Solution

x′y′z′1=sx00px(1-sx)0sy0py(1-sy)00szpz(1-sz)0001xyz1

Substituting the given values:

x′y′z′1=200-1030-2004-30001xyz1

The point (2,2,2) is transformed to (3,4,5):

3451=200-1030-2004-300012221

10.14.4 2D Rotation

Compute the coordinates of the unit square in Table 10.1 after a rotation of 90∘.

Table 10.1

Original and rotated coordinates of the unit square

x

y

x′

y′

0

0

0

0

1

0

0

1

1

1

–1

1

0

1

–1

0

Solution

The points are rotated as follows:

x′y′1=cosβ-sinβ0sinβcosβ0001xy1=0-10100001xy1001=0-10100001001011=0-10100001101-111=0-10100001111-101=0-10100001011

10.14.5 2D Rotation About a Point

Derive the 2D homogeneous matrix to rotate 180∘ about (-1,0), and compute the transformed position of (0,0).

Solution

x′y′1=cosβ-sinβpx(1-cosβ)+pysinβsinβcosβpy(1-cosβ)-pxsinβ001xy1=cos180∘-sin180∘-1(1-cos180∘)+0sin180∘sin180∘cos180∘0(1-cos180∘)+1sin180∘001xy1-201=-10-20-10001001

The point (0,0) is rotated to (-2,0).

10.14.6 Determinant of the Rotate Transform

Using determinants, show that the rotate transform preserves area.

Solution

The determinant of a 2D matrix transform reflects the area change produced by the transform. Therefore, if area is preserved, the determinant must equal 1. Using Sarrus’s rule:

cosβ-sinβ0sinβcosβ0001=cos2β+sin2β=1

which confirms the role of the determinant.

10.14.7 Determinant of the Shear Transform

Using determinants, show that the shear transform preserves area.

Solution

The determinant of a 2D matrix transform reflects the area change produced by the transform. Therefore, if area is preserved, the determinant must equal 1. Using Sarrus’s rule:

1tanβ0010001=1

which confirms the role of the determinant.

10.14.8 Yaw, Pitch and Roll Transforms

Using the yaw and pitch transforms in the sequence yaw×pitch, compute how the point (1,1,1) is transformed with yaw=pitch=90∘.

Solution

x′y′1=cosyaw0sinyaw00100-sinyaw0cosyaw0000110000cospitch-sinpitch00sinpitchcospitch00001xyz1=00100100-10000001100000-1001000001xyz11-1-11=010000-10-100000011111

therefore, (1,1,1) is transformed to (1,-1,-1).

10.14.9 3D Rotation About an Axis

Derive a homogeneous matrix to rotate (-1,1,0), 270∘ about an axis parallel to the y-axis, and intersecting (1,0,0).

Solution

x′y′z′1=cosβ0sinβpx(1-cosβ)-pzsinβ0100-sinβ0cosβpz(1-cosβ)+pxsinβ0001xyz1=cos270∘0sin270∘1(1-cos270∘)-0sin270∘0100-sin270∘0cos270∘0(1-cos270∘)+1sin270∘0001xyz1=00-11(1-0)01001000(1-0)-10001xyz1=00-110100100-10001xyz111-21=00-110100100-10001-1101

The point (-1,1,0) is rotated to (1,1,-2).

10.14.10 3D Rotation Transform Matrix

Show that the matrix for rotating a point about an arbitrary axis corresponds to the three matrices for rotating about the x-, y- and z-axis.

Solution

a2K+cosαabK-csinαacK+bsinα0abK+csinαb2K+cosαbcK-asinα0acK-bsinαbcK+asinαc2K+cosα00001

Pitch about the x-axis: n^=i, where a=1 and b=c=0; K=1-cosα.

pitch=10000cosα-sinα00sinαcosα00001

Yaw about the y-axis: n^=j, where b=1 and a=c=0; K=1-cosα.

yaw=cosα0sinα00100-sinα0cosα00001

Roll about the z-axis: n^=k, where c=1 and a=b=0; K=1-cosα.

roll=cosα-sinα00sinαcosα0000100001

10.14.11 2D Change of Axes

Derive a 2D homogeneous matrix to compute (1,1) in an axial system with direction cosines cosβ=2/2 and sinβ=-2/2.

Solution

x′y′1=cosβsinβ0-sinβcosβ0001xy1=2/2-2/202/22/20001111021=2/2-2/202/22/20001111

The point (1,1) has coordinates (0,2) in the rotated axial system.

10.14.12 3D Change of Axes

Derive a 3D homogeneous matrix to compute the positions of (0,0,0) and (0,1,0) in an axial system with 180∘ yaw, 0∘ pitch, 180∘ roll, and translated by (10,0,0).

Solution

x′y′z′1=T11T12T13T14T21T22T23T24T31T32T33T34T41T42T43T44xyz1

where:

T11=cos(yaw)cos(roll)+sin(yaw)sin(pitch)sin(roll)T12=cos(pitch)sin(roll)T13=-sin(yaw)cos(roll)+cos(yaw)sin(pitch)sin(roll)T14=-(txT11+tyT12+tzT13)T21=-cos(yaw)sin(roll)+sin(yaw)sin(pitch)cos(roll)T22=cos(pitch)cos(roll)T23=-sin(yaw)sin(roll)+cos(yaw)sin(pitch)cos(roll)T24=-(txT21+tyT22+tzT23)T31=sin(yaw)cos(pitch)T32=-sin(pitch)T33=cos(yaw)cos(pitch)T34=-(txT31+tyT32+tzT33)T41=T42=T43=0T44=1

Substituting the above values:

T11=cos180∘cos180∘+sin180∘sin0∘sin180∘=1T12=cos0∘sin180∘=0T13=-sin180∘cos180∘+cos180∘sin0∘sin180∘=0T14=-(-10T11+0T12+0T13)=10T21=-cos180∘sin180∘+sin180∘sin0∘cos180∘=0T22=cos0∘cos180∘=-1T23=-sin180∘sin180∘+cos180∘sin0∘cos180∘=0T24=-(-10T21+0T22+0T23)=0T31=sin180∘cos0∘=0T32=-sin0∘=0T33=cos180∘cos0∘=-1T34=-(-10T31+0T32+0T33)=0T41=T42=T43=0T44=1

Therefore:

10001=100100-10000-1000010001

and

10-101=100100-10000-1000010101

The positions of (0,0,0) and (0,1,0) in the transformed axial system are (10,0,0) and (10,-1,0) respectively.

10.14.13 Rotate a Point About an Axis

Derive a 3D homogeneous matrix to rotate (1,0,0), 180∘ about an axis whose parallel vector is n^=1/2j+1/2k.

Solution

Given:

xp′yp′zp′1=a2K+cosαabK-csinαacK+bsinα0abK+csinαb2K+cosαbcK-asinα0acK-bsinαbcK+asinαc2K+cosα00001xpypzp1

where:

K=1-cosα

Therefore:

-1001=-10000010010000011001

The rotated point is (-1,0,0).

10.14.14 Perspective Projection

Compute the perspective coordinates of a 3D cube stored in Table 10.2 with the projection screen distance d=20. Sketch the result.

Solution

xp=-xc×dzc,yp=yc×dzc,zp=d

Vertex1:xp=0×20/10=0yp=0×20/10=0zp=20Vertex2:xp=-10×20/10=-20yp=0×20/10=0zp=20Vertex3:xp=-10×20/10=-20yp=10×20/10=20zp=20Vertex4:xp=0×20/10=0yp=10×20/10=20zp=20Vertex5:xp=0×20/20=0yp=0×20/20=0zp=20Vertex6:xp=-10×20/20=-10yp=0×20/20=0zp=20Vertex7:xp=-10×20/10=-10yp=10×20/20=10zp=20Vertex8:xp=0×20/10=0yp=10×20/20=10zp=20

The perspective coordinates are stored in Table 10.2, and Fig. 10.32 shows a sketch of the result, with the x-coordinate reversed.

Table 10.2

Coordinates of a 3D cube

Vertex

xc

yc

zc

xp

yp

1

0

0

10

0

0

2

10

0

10

–20

0

3

10

10

10

–20

20

4

0

10

10

0

20

5

0

0

20

0

0

6

10

0

20

–10

0

7

10

10

20

–10

10

8

0

10

20

0

10

Fig. 10.32

A perspective sketch of a 3D cube

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_11

11. Quaternion Algebra

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

11.1 Introduction

This chapter contains some historical background to the invention of quaternions, and covers the evolution of quaternion algebra. I show how quaternion algebra is greatly simplified by treating a quaternion as an ordered pair, and provide examples of addition, subtraction, real, pure and unit quaternions. After defining the complex conjugate, norm, quaternion product, square and inverse, I show how a quaternion is represented by a matrix. The chapter concludes with a summary of the important definitions and several worked examples.

11.2 Some History

A complex number is defined as:

z=a+ib,a,b∈R,i2=-1

Complex numbers can be regarded as a 2D point, which begs the question: is there a complex object for a 3D point? After many years of thinking, Sir Willian Rowan Hamilton found the answer in the form of a quaternion.

Note that I use ‘i’ to define a complex number, and Hamilton uses ‘i’, ‘j’ and ‘k’ to define a quaternion. I leave this preference throughout this chapter.

Hamilton defined a quaternion q, and its associated rules as: 

q=s+ia+jb+kc,s,a,b,c∈R

where:

i2=j2=k2=ijk=-1

ij=k,jk=i,ki=jji=-k,kj=-i,ik=-j

[1–3], but we tend to write quaternions as:

q=s+ai+bj+ck

Observe from Hamilton’s rules how the occurrence of ij is replaced by k. The extra imaginary k term is key to the cyclic patterns ij=k, jk=i, and ki=j, which are very similar to the cross product of two unit Cartesian vectors:

i×j=k,j×k=i,k×i=j

In fact, this similarity is no coincidence, as Hamilton also invented the scalar and vector products. However, although quaternions provided an algebraic framework to describe vectors, one must acknowledge that vectorial quantities had been studied for many years prior to Hamilton.

Hamilton also saw that the i,j,k terms could represent three Cartesian unit vectors i, j and k, which had to possess imaginary qualities. i.e. i2=-1, etc., which didn’t go down well with some mathematicians and scientists who were suspicious of the need to involve so many imaginary terms.

Hamilton’s motivation to search for a 3D equivalent of complex numbers was part algebraic, and part geometric. For if a complex number is represented by a couple and is capable of rotating points on the plane by 90∘, then perhaps a triple rotates points in space by 90∘. In the end, a triple had to be replaced by a a quadruple–a quaternion. 

One can regard Hamilton’s rules from two perspectives. The first, is that they are an algebraic consequence of combining three imaginary terms. The second, is that they reflect an underlying geometric structure of space. The latter interpretation was adopted by the Scottish mathematical physicist Peter Guthrie Tait (1831–1901), and outlined in his book An Elementary Treatise on Quaternions. Tait’s approach assumes three unit vectors i,j,k aligned with the x-, y-, z-axes respectively:

The result of the multiplication of i into j or ij is defined to be the turning of j through a right angle in the plane perpendicular to i in the positive direction, in other words, the operation of i on j turns it round so as to make it coincide with k; and therefore briefly ij=k.

To be consistent it is requisite to admit that if i instead of operating on j had operated on any other unit vector perpendicular to i in the plane yz, it would have turned it through a right-angle in the same direction, so that ik can be nothing else than -j.

Extending to other unit vectors the definition which we have illustrated by referring to i, it is evident that j operating on k must bring it round to i, or jk=i [4].

Tait’s explanation is illustrated in Fig. 11.1a–d. Figure 11.1a shows the original alignment of i,j,k. Figure 11.1b shows the effect of turning j into k. Figure 11.1c shows the turning of k into i, and Fig. 11.1d shows the turning of i in to j.

Fig. 11.1

Interpreting the products jk,ki,ij

So far, there is no mention of imaginary quantities–we just have:

ij=k,jk=i,ki=jji=-k,kj=-i,ik=-j

If we assume that these vectors obey the distributive and associative axioms of algebra, their imaginary qualities are exposed. For example:

ij=k

and multiplying throughout by i:

iij=ik=-j

therefore:

ii=i2=-1

Similarly, we can show that j2=k2=-1.

Next:

ijk=i(jk)=ii=i2=-1

Thus, simply by declaring the action of the cross-product, Hamilton’s rules emerge, with all of their imaginary features. Tait also made the following observation:

A very curious speculation, due to Servois, and published in 1813 in Gergonne’s Annales is the only one, so far has been discovered, in which the slightest trace of an anticipation of Quaternions is contained. Endeavouring to extend to space the form a+b-1 for the plane, he is guided by analogy to write a directed unit-line in space the form

pcosα+qcosβ+rcosγ,

where α,β,γ are its inclinations to the three axes. He perceives easily that p,q,r must be non-reals : but, he asks, “seraient-elles imaginaires réductibles à la forme générale A+B-1?” This could not be the answer. In fact they are the i,j,k of the Quaternion Calculus [4].

So the French mathematician François-Joseph Servois (1768–1847), was another person who came very close to discovering quaternions. Furthermore, both Tait and Hamilton were apparently unaware of a paper on transformation groups published by the French banker and mathematician Olinde Rodrigues (1795–1851) in 1840.  

And it doesn’t stop there: the brilliant mathematician Carl Friedrich Gauss was extremely cautious, and nervous of publishing anything too revolutionary, just in case he was ridiculed by fellow mathematicians. His diaries reveal that he had anticipated non-euclidean geometry ahead of the Russian mathematician Nikolai Lobachevsky (1792–1856). And in a short note from his diary in 1819 [5] he reveals that he had identified a method of finding the product of two quadruples (a,b,c,d) and (α,β,γ,δ) as:

(A,B,C,D)=(a,b,c,d)(α,β,γ,δ)=(aα-bβ-cγ-dδ,aβ+bα-cδ+dγ,aγ+bδ+cα-dβ,aδ-bγ+cβ+dα)

At first glance, this result does not look like a quaternion product, but if we transpose the second and third coordinates of the quadruples, and treat them as quaternions, we have:

(A,B,C,D)=(a+ci+bj+dk)(α+γi+βj+δk)=aα-cγ-bβ-dδ+a(γi+βj+δk)+α(ci+bj+dk),(bδ-dβ)i+(dγ-cδ)j+(cβ-bγ)k

which is identical to Hamilton’s quaternion product! Furthermore, Gauss also realised that the product was non-commutative. However, he did not publish his findings, and it was left to Hamilton to invent quaternions for himself, publish his results and take the credit.

In 1881 and 1884, Josiah Willard Gibbs, at Yale University, printed his lecture notes on vector analysis for his students. Gibbs had cut the ‘umbilical cord’ between the real and vector parts of a quaternion and raised the 3D vector as an independent object without any imaginary connotations. Gibbs also took on board the ideas of Grassmann, who had been developing his own ideas for a vectorial system since 1832. Gibbs also defined the scalar and vector products using the relevant parts of the quaternion product. Finally, in 1901, a student of Gibbs, Edwin Bidwell Wilson, published Gibbs’ notes in book form: Vector Analysis [6], which contains the notation in use today. 

Quaternion algebra is definitely imaginary, yet simply by isolating the vector part and ignoring the imaginary rules, Gibbs was able to reveal a new branch of mathematics that exploded into vector analysis.

Hamilton and his supporters were unable to persuade their peers that quaternions could represent vectorial quantities, and eventually, Gibbs’ notation won the day, and quaternions faded from the scene.

In recent years, quaternions have been rediscovered by the flight simulation industry, and more recently by the computer graphics community, where they are used to rotate vectors about an arbitrary axis. In the intervening years, various people have had the opportunity to investigate the algebra, and propose new ways of harnessing its qualities.

So let’s look at three ways of annotating a quaternion q:

q=s+xi+yj+zk

(11.1)

q=s+v

(11.2)

q=[s,v]wheres,x,y,z∈R,v∈R3andi2=j2=k2=-1

(11.3)

The difference is rather subtle. In (11.1) we have Hamilton’s original definition with its imaginary terms and associated rules. In (11.2) a ‘+’ sign is used to add a scalar to a vector, which seems strange, yet works. In (11.3) we have an ordered pair comprising a scalar and a vector.

Now you may be thinking: How is it possible to have three different definitions for the same object? Well, I would argue that you can call an object whatever you like, so long as they are algebraically identical. For example, matrix notation is used to represent a set of linear equations, and leads to the same results as every-day equations. Therefore, both systems of notation are equally valid.

Although I have employed the notation in (11.1) and (11.2) in other publications, in this book I have used ordered pairs. So what we need to show is that Hamilton’s original definition of a quaternion (11.1), with its scalar and three imaginary terms, can be replaced by an ordered pair (11.3) comprising a scalar and a ‘modern’ vector.

11.3 Defining a Quaternion

Let’s start with two quaternions qa and qb à la Hamilton:

qa=sa+xai+yaj+zakqb=sb+xbi+ybj+zbk

and the obligatory rules:

i2=j2=k2=ijk=-1

ij=k,jk=i,ki=jji=-k,kj=-i,ik=-j

Our objective is to show that qa and qb can also be represented by the ordered pairs:

qa=[sa,a]qb=[sb,b],sa,sb∈R,a,b∈R3

The quaternion product qaqb expands to:

qaqb=[sa,a][sb,b]=[sa+xai+yaj+zak][sb+xbi+ybj+zbk]=[(sasb-xaxb-yayb-zazb)+(saxb+sbxa+yazb-ybza)i+(sayb+sbya+zaxb-zbxa)j+(sazb+sbza+xayb-xbya)k]

(11.4)

Equation (11.4) takes the form of another quaternion, and confirms that the quaternion product is closed.

At this stage, Hamilton turned the imaginary terms i,j,k into unit Cartesian vectors i,j,k and transformed (11.4) into a vector form. The problem with this approach is that the vectors retain their imaginary roots. The author Simon Altmann suggests replacing the imaginaries by the ordered pairs:

i=[0,i],j=[0,j],k=[0,k]

which are themselves quaternions, and called quaternion units. 

The idea of defining a quaternion in terms of quaternion units is exactly the same as defining a vector in terms of its unit Cartesian vectors. Furthermore, it permits vectors to exist without any imaginary associations.

Let’s substitute these quaternion units in (11.4) together with [1,0]=1:

[sa,a][sb,b]=[(sasb-xaxb-yayb-zazb)[1,0]+(saxb+sbxa+yazb-ybza)[0,i]+(sayb+sbya+zaxb-zbxa)[0,j]+(sazb+sbza+xayb-xbya)[0,k]]

(11.5)

Next, we expand (11.5) using previously defined rules:

[sa,a][sb,b]=[[sasb-xaxb-yayb-zazb,0]+[0,(saxb+sbxa+yazb-ybza)i]+[0,(sayb+sbya+zaxb-zbxa)j]+[0,(sazb+sbza+xayb-xbya)k]]

(11.6)

A vertical scan of (11.6) reveals some hidden vectors:

[sa,a][sb,b]=[[sasb-xaxb-yayb-zazb,0]+[0,sa(xbi+ybj+zbk)+sb(xai+yaj+zak)+(yazb-ybza)i+(zaxb-zbxa)j+(xayb-xbya)k]]

(11.7)

Equation (11.7) contains two ordered pairs which can now be combined:

[sa,a][sb,b]=[sasb-xaxb-yayb-zazb+sa(xbi+ybj+zbk)+sb(xai+yaj+zak)+(yazb-ybza)i+(zaxb-zbxa)j+(xayb-xbya)k]

(11.8)

If we make:

a=xai+yaj+zakb=xbi+ybj+zbk

and substitute them in (11.8) we get:

[sa,a][sb,b]=[sasb-a·b,sab+sba+a×b]

(11.9)

which defines the quaternion product. 

From now on, we don’t have to worry about Hamilton’s rules as they are embedded within (11.9). Furthermore, our vectors have no imaginary associations.

Although Rodrigues did not have access to Gibbs’ vector notation used in (11.9), he managed to calculate the equivalent algebraic expression, which was some achievement.

11.3.1 The Quaternion Units

Using (11.9) we can check to see if the quaternion units are imaginary by squaring them:

i=[0,i]i2=[0,i][0,i]=[i·i,i×i]=[-1,0]

which is a real quaternion and equivalent to -1, confirming that [0,i] is imaginary. Using a similar expansion we can shown that [0,j] and [0,k] have the same property.

Now let’s compute the products ij,jk and ki:

ij=[0,i][0,j]=[-i·j,i×j]=[0,k]

which is the quaternion unit k.

jk=[0,j][0,k]=[-j·k,j×k]=[0,i]

which is the quaternion unit i.

ki=[0,k][0,i]=[-k·i,k×i]=[0,j]

which is the quaternion unit j.

Next, let’s confirm that ijk=-1:

ijk=[0,i][0,j][0,k]=[0,k][0,k]=[-k·k,k×k]=[-1,0]

which is a real quaternion equivalent to -1, confirming that ijk=-1.

Thus the notation of ordered pairs upholds all of Hamilton’s rules. However, the last double product assumes that quaternions are associative. So let’s double check to show that (ij)k=i(jk):

i(jk)=[0,i][0,j][0,k]=[0,i][0,i]=[-i·i,i×i]=[-1,0]

which is correct.

11.3.2 Quaternion Products

Although we have yet to discover how quaternions are used to rotate vectors, let’s concentrate on their algebraic traits by evaluating an example.

qa=[1,2i+3j+4k]qb=[2,3i+4j+5k]

The quaternion product qaqb is:

qaqb=[1,2i+3j+4k][2,3i+4j+5k]=[1×2-(2×3+3×4+4×5),1(3i+4j+5k)+2(2i+3j+4k)+(3×5-4×4)i-(2×5-4×3)j+(2×4-3×3)k]=[-36,7i+10j+13k-i+2j-k]=[-36,6i+12j+12k]

which is another ordered pair representing a quaternion.

Having shown that Hamilton’s imaginary notation has a vector equivalent, and can be represented as an ordered pair, we continue with this notation and describe other features of quaternions. Note that we can abandon Hamilton’s rules as they are embedded within the definition of the quaternion product, and will surface in the following definitions.

11.4 Algebraic Definition

A quaternion is the ordered pair:

q=[s,v],s∈R,v∈R3

If we express v in terms of its components, we have:

q=[s,xi+yj+zk],s,x,y,z∈R

11.5 Adding and Subtracting Quaternions

The  adding and subtraction of quaternions employ the following rule:

qa=[sa,a]qb=[sb,b]qa±qb=[sa±sb,a±b]

For example:

qa=[0.5,2i+3j-4k]qb=[0.1,4i+5j+6k]qa+qb=[0.6,6i+8j+2k]qa-qb=[0.4,-2i-2j-10k]

11.6 Real Quaternion

A real quaternion has a zero vector term:

q=[s,0]

The product of two real quaternions is:

qa=[sa,0]qb=[sb,0]qaqb=[sa,0][sb,0]=[sasb,0]

which is another real quaternion, and shows that they behave just like real numbers:

[s,0]≡s

We have already come across this with complex numbers containing a zero imaginary term:

a+bi=a,whenb=0

11.7 Multiplying a Quaternion by a Scalar

Intuition suggests that multiplying a quaternion by a scalar should obey the rule:

q=[s,v]λq=λ[s,v],λ∈R=[λs,λv]

For example:

q=3[2,3i+4j+5k]=[6,9i+12j+15k]

We can confirm our intuition by multiplying a quaternion by a scalar in the form of a real quaternion:

q=[s,v]λ=[λ,0]λq=[λ,0][s,v]=[λs,λv]

which is excellent confirmation.

11.8 Pure Quaternion

Hamilton  defined a pure quaternion as one having a zero scalar term:

q=xi+yj+zk

and is just a vector, but with imaginary qualities. Simon Altmann, and others, believe that this was a serious mistake on Hamilton’s part to call a quaternion with a zero real term, a vector.

The main issue is that there are two types of vectors: polar and axial, also called a pseudovector. Richard Feynman describes polar vectors as ‘honest’ vectors [7] and represent the every-day vectors of directed lines. Whereas, axial vectors are computed from polar vectors, such as in a vector product. However, these two types of vector do not behave in the same way when transformed. For example, given two ‘honest’, polar vectors a and b, we can compute the axial vector: c=a×b. Next, if we subject a and b to an inversion transform through the origin, such that a becomes -a, and b becomes -b, and compute their cross product (-a)×(-b), we still get c! Which implies that the axial vector c must not be transformed along with a and  b.

It could be argued that the inversion transform is not a ‘proper’ transform as it turns a right-handed set of axes into a left-handed set. But in physics, laws of nature are expected to work in either system. Unfortunately, Hamilton was not aware of this distinction, as he had only just invented vectors. However, in the intervening years, it has become evident that Hamilton’s quaternion vector is an axial vector, and not a polar vector.

As we will see, in 3D rotations quaternions take the form:

q=cosθ2,sinθ2v

where θ is the angle of rotation and v is the axis of rotation, and when we set θ=180∘, we get:

q=[0,v]

which remains a quaternion, even though it only contains a vector part.

Consequently, we define a pure quaternion as:

q=[0,v]

The product of two pure quaternions is:

qa=[0,a]qb=[0,b]qaqb=[0,a][0,b]=[-a·b,a×b]

which is no longer ‘pure’, as some of the original vector information has ‘tunnelled’ across into the real part via the dot product.

11.9 Unit Quaternion

Let’s  pursue this analysis further by introducing some familiar vector notation.

Give vector v, then:

v=λv^,whereλ=‖v‖and‖v^‖=1

Combining this with the definition of a pure quaternion we get:

q=[0,v]=[0,λv^]=λ[0,v^]

and reveals the object [0,v^] which is called the unit quaternion and comprises a zero scalar and a unit vector. It is convenient to identify this unit quaternion as q^:

q^=[0,v^]

So now we have a notation similar to that of vectors where a vector v is described in terms of its unit form:

v=λv^

and a quaternion q is also described in terms of its unit form:

q=λq^

Note that q^ is an imaginary object as it squares to -1:

q^2=[0,v^][0,v^]=[-v^·v^,v^×v^]=[-1,0]=-1

which is not too surprising, bearing in mind Hamilton’s original invention!

11.10 Additive Form of a Quaternion

We  now come to the idea of splitting a quaternion into its constituent parts: a real quaternion and a pure quaternion. Again, intuition suggests that we can write a quaternion as:

q=[s,v]=[s,0]+[0,v]

and we can test this by forming the algebraic product of two quaternions represented in this way:

qa=[sa,0]+[0,a]qb=[sb,0]+[0,b]qaqb=([sa,0]+[0,a])([sb,0]+[0,b])=[sa,0][sb,0]+[sa,0][0,b]+[0,a][sb,0]+[0,a][0,b]=[sasb,0]+[0,sab]+[0,sba]+[-a·b,a×b]=[sasb-a·b,sab+sba+a×b]

which is correct, and confirms that the additive form works.

11.11 Binary Form of a Quaternion

Having  shown that the additive form of a quaternion works, and discovered the unit quaternion, we can join the two objects together as follows:

q=[s,v]=[s,0]+[0,v]=[s,0]+λ[0,v^]=s+λq^

Just to recap, s is a scalar, λ is the length of the vector term, and q^ is the unit quaternion [0,v^].

Look how similar this notation is to a complex number:

z=a+biq=s+λq^

where a,b,s,λ are scalars, i is the unit imaginary and q^ is the unit quaternion.

11.12 The Complex Conjugate of a Quaternion

We  have already discovered that the conjugate of a complex number z=a+bi is given by:

z∗=a-bi

and is very useful in computing the inverse of z. The quaternion complex conjugate plays a similar role in computing the inverse of a quaternion. Therefore, given:

q=[s,v]

the quaternion conjugate is defined as:

q∗=[s,-v]

For example:

q=[2,3i-4j+5k]q∗=[2,-3i+4j-5k]

If we compute the product qq∗ we obtain:

qq∗=[s,v][s,-v]=s2-v·(-v),-sv+sv+v×(-v)=s2+v·v,0=s2+v2,0

Let’s show that qq∗=q∗q:

q∗q=[s,-v][s,v]=s2-(-v)·v,sv-sv+(-v)×v=s2+v·v,0=s2+v2,0=qq∗

Now let’s show that (qaqb)∗=qb∗qa∗:

qa=[sa,a]qb=[sb,b]qaqb=[sa,a][sb,b]=[sasb-a·b,sab+sba+a×b](qaqb)∗=[sasb-a·b,-sab-sba-a×b]

(11.10)

Next, we compute qb∗qa∗:

qa∗=[sa,-a]qb∗=[sb,-b]qb∗qa∗=[sb,-b][sa,-a]=[sasb-a·b,-sab-sba-a×b]

(11.11)

And as (11.10) equals (11.11), (qaqb)∗=qb∗qa∗.

11.13 Norm of a Quaternion

The  norm of a complex number z=a+bi is defined as:

|z|=a2+b2

which allows us to write:

zz∗=|z|2

Similarly, the norm of a quaternion q is defined as:

q=[s,v]=[s,λv^]|q|=s2+λ2

where λ=‖v‖ which allows us to write:

qq∗=|q|2

For example:

q=[1,4i+4j-4k]|q|=12+42+42+(-4)2=49=7

11.14 Normalised Quaternion

A  quaternion with a unit norm is called a normalised quaternion. For example, the quaternion q=[s,v] is normalised by dividing it by |q|:

q′=qs2+λ2

We must be careful not to confuse the unit quaternion with a unit-norm quaternion. The unit quaternion is [0,v^] with a unit-vector part, whereas a unit-norm quaternion is normalised such that s2+λ2=1.

I will be careful to distinguish between these two terms as many authors–including myself–use the term unit quaternion to describe a quaternion with a unit norm. For  example:

q=1,4i+4j-4k

has a norm of 7, and q is normalised by dividing by 7:

q′=171,4i+4j-4k

The type of unit-norm quaternion we will be using takes the form:

q=cosθ2,sinθ2v^

because cos2θ+sin2θ=1.

11.15 Quaternion Products

Having  shown that ordered pairs can represent a quaternion and its various manifestations, let’s summarise the products we will eventually encounter. To start, we have quaternion products:

qaqb=[sa,a][sb,b]=[sasb-a·b,sab+sba+a×b]

11.15.1 Product of Pure Quaternions

Given  two pure quaternions:

qa=[0,a]qb=[0,b]

their product is:

qaqb=[0,a][0,b]=[-a·b,a×b]

11.15.2 Product of Unit-Norm Quaternions

Given  two unit-norm quaternions:

qa=[sa,a]qb=[sb,b]

where |qa|=|qb|=1. Their product is another unit-norm quaternion, which is proved as follows.

We assume qc=[sc,c] and show that |qc|=sc2+c2=1 where:

[sc,c]=[sa,a][sb,b]=[sasb-a·b,sab+sba+a×b]

Let’s assume the angle between a and b is θ, which permits us to write:

sc=sasb-abcosθc=sabb^+sbaa^+absinθa^×b^

Therefore:

sc2=(sasb-abcosθ)(sasb-abcosθ)=sa2sb2-2sasbabcosθ+a2b2cos2θ

Figure 11.2 shows the geometry representing c.

d2=sb2a2+sa2b2-2sasbabcos(π-θ)=sb2a2+sa2b2+2sasbabcosθc2=d2+a2b2sin2θ=sb2a2+sa2b2+2sasbabcosθ+a2b2sin2θsc2+c2=sa2sb2-2sasbabcosθ+a2b2cos2θ+sb2a2+sa2b2+2sasbabcosθ+a2b2sin2θ=sa2sb2+a2b2+sb2a2+sa2b2=sa2sb2+b2+a2sb2+b2=sa2+a2=1

Fig. 11.2

Geometry for sabb^+sbaa^+absinθ(a^×b^)

Therefore, the product of two unit-norm quaternions is another unit-norm quaternion. Consequently, multiplying a quaternion by a unit-norm quaternion, does not change its norm:

qa=[sa,a]|qa|=1qb=[sb,b]|qaqb|=|qb|

11.15.3 Square of a Quaternion

The  square of a quaternion is given by:

v=xi+yj+zkq=[s,v]q2=[s,v][s,v]=s2-v·v,2sv+v×v=s2-v·v,2sv=s2-x2-y2-z2,2s(xi+yj+zk)

For example:

q=[7,2i+3j+4k]q2=72-22-32-42,14(2i+3j+4k)=[20,28i+42j+56k]

The square of a pure quaternion is:

v=xi+yj+zkq=[0,v]q2=[0,v][0,v]=[0-v·v,v×v]=[0-v·v,0]=-x2+y2+z2,0

which makes the square of a pure, unit-norm quaternion equal to -1, and was one of the results, to which some 19th-century mathematicians objected.

11.15.4 Norm of the Quaternion Product

In proving that the product of two unit-norm quaternions is another unit-norm quaternion we saw that:

qa=[sa,a]qb=[sb,b]qc=qaqb|qc|2=sa2sb2+b2+a2sb2+b2=sa2+a2sb2+b2

which, if we ignore the constraint of unit-norm quaternions, shows that the norm of a quaternion product equals the product of the individual norms:

|qaqb|2=|qa|2|qb|2|qaqb|=|qa||qb|

11.16 Inverse Quaternion

An  important feature of quaternion algebra is the ability to divide two quaternions qb/qa, as long as qa does not vanish.

By definition, the inverse quaternion q-1 of q satisfies:

qq-1=[1,0]=1

(11.12)

To isolate q-1, we multiply (11.12) by q∗:

|q∗qq-1=q∗q|2q-1=q∗

(11.13)

and from (11.13) we can write:

q-1=q∗|q|2

If q is a unit-norm quaternion, then:

q-1=q∗

which is useful in the context of rotations.

Furthermore, as:

(qaqb)∗=qb∗qa∗

then:

(qaqb)-1=qb-1qa-1

Note that qq-1=q-1q:

qq-1=qq∗|q|2=1q-1q=q∗q|q|2=1

Thus, we represent the quotient qb/qa as:

qc=qbqa=qbqa-1=qbqa∗|qa|2

For completeness let’s evaluate the inverse of q where:

q=1,13i+13j+13kq∗=1,-13i-13j-13k|q|2=1+13+13+13=2q-1=q∗|q|2=121,-13i-13j-13k

It should be clear that q-1q=1:

q-1q=121,-13i-13j-13k1,13i+13j+13k=121+13+13+13,0=1

11.17 Matrices

Matrices provide  another way to express a quaternion product. For convenience, let’s repeat (11.8) again and show it in matrix form:

sa,a[sb,b]=[sasb-xaxb-yayb-zazb,+saxbi+ybj+zbk+sb(xai+yaj+zak)+(yazb-ybza)i+(zaxb-zbxa)j+(xayb-xbya)k]=sa-xa-ya-zaxasa-zayayazasa-xaza-yaxasasbxbybzb

(11.14)

Let’s recompute the product qaqb using the above matrix:

qa=1,2i+3j+4kqb=2,3i+4j+5kqaqb=1-2-3-421-43341-24-3212345=-3661212=-36,6i+12j+12k

11.17.1 Orthogonal Matrix

We can demonstrate that the unit-norm quaternion matrix is orthogonal by showing that the product with its transpose equals the identity matrix. As we are dealing with matrices, Q will represent the matrix for q:

q=[s,xi+yj+zk]where1=s2+x2+y2+z2Q=s-x-y-zxs-zyyzs-xz-yxsQT=sxyz-xsz-y-y-zsx-zy-xsQQT=s-x-y-zxs-zyyzs-xz-yxssxyz-xsz-y-y-zsx-zy-xs=1000010000100001

For this to occur, QT=Q-1.

11.18 Basis for an Algebra

Ordered pairs provide a simple notation for representing quaternions, and allow us to represent the real unit 1 as [1,0], and the imaginaries i,j,k as [0,i],[0,j],[0,k] respectively. A quaternion then becomes a linear combination of these elements with associated real coefficients. Under such conditions, the elements form the basis for an algebra over the field of reals.

Furthermore, because quaternion algebra supports division, and obeys the normal axioms of algebra, except that multiplication is non-commutative, it is called a division algebra. The German mathematician Ferdinand Georg Frobenius (1849–1917) proved that only three such real associative division algebras exist: real numbers, complex numbers and quaternions [8]. 

The Cayley numbers O, constitute a real division algebra, but the Cayley numbers are 8-dimensional and are not associative, i.e. a(bc)≠(ab)c for all a,b,c∈O. 

11.19 Summary

Quaternions are very similar to complex numbers, apart from the fact that they have three imaginary terms, rather than one. Consequently, they inherit some of the properties associated with complex numbers, such as norm, complex conjugate, unit norm and inverse. They can also be added, subtracted, multiplied and divided. However, unlike complex numbers, they anti-commute when multiplied.

11.19.1 Summary of Definitions

Quaternion

qa=[sa,a]=sa,xai+yaj+zakqb=[sb,b]=sb,xbi+ybj+zbk

Adding and subtracting

qa±qb=[sa±sb,a±b]

Product

qaqb=[sa,a][sb,b]=[sasb-a·b,sab+sba+a×b]=sa-xa-ya-zaxasa-zayayazasa-xaza-yaxasasbxbybzb

Square

v=xi+yj+zkq2=[s,v][s,v]=s2-x2-y2-z2,2s(xi+yj+zk)

Pure

v=xi+yj+zkq2=[0,v][0,v]=-(x2+y2+z2),0

Norm

v=λv^q=[s,λv^]|q|=s2+λ2

Unit norm

|q|=s2+λ2=1

Conjugate

q∗=[s,-v](qaqb)∗=qb∗qa∗

Inverse

q-1=q∗|q|2(qaqb)-1=qb-1qa-1

11.20 Worked Examples

Here are some further worked examples that employ the ideas described above. In some cases, a test is included to confirm the result.

11.20.1 Adding and Subtracting Quaternions

Add  and subtract the following quaternions:

qa=[2,-2i+3j-4k]qb=[1,-2i+5j-6k]

Solution

qa+qb=[3,-4i+8j-10k]qa-qb=[1,0i-2j+2k]

11.20.2 Norm of a Quaternion

Find  the norm of the following quaternions:

qa=[2,-2i+3j-4k]qb=[1,-2i+5j-6k]

Solution

|qa|=22+(-2)2+32+(-4)2=33|qb|=12+(-2)2+52+(-6)2=66

11.20.3 Unit-norm Quaternions

Convert  these quaternions to their unit-norm form:

qa=[2,-2i+3j-4k]qb=[1,-2i+5j-6k]

Solution

|qa|=33|qb|=66qa′=133[2,-2i+3j-4k]qb′=166[1,-2i+5j-6k]

11.20.4 Quaternion Product

Compute  the product and reverse product of the following quaternions:

qa=[2,-2i+3j-4k]qb=[1,-2i+5j-6k]

Solution

qaqb=[2,-2i+3j-4k][1,-2i+5j-6k]=[2×1-((-2)×(-2)+3×5+(-4)×(-6)),+2(-2i+5j-6k)+1(-2i+3j-4k)+(3×(-6)-(-4)×5)i-((-2)×(-6)-(-4)×(-2))j+((-2)×5-3×(-2))k]=[-41,-6i+13j-16k+2i-4j-4k]=[-41,-4i+9j-20k]

qbqa=[1,-2i+5j-6k][2-2i+3j-4k]=[1×2-((-2)×(-2)+5×3+(-6)×(-4)),+1(-2i+3j-4k)+2(-2i+5j-6k)+(5×(-4)-(-6)×3)i-((-2)×(-4)-(-6)×(-2))j+((-2)×3-5×(-2))k]=[-41,-6i+13j-16k-2i+4j+4k]=[-41,-8i+17j-12k]

Note: The only thing that has changed in this computation is the sign of the cross-product axial vector.

11.20.5 Square of a Quaternion

Compute  the square of this quaternion:

q=[2,-2i+3j-4k]

Solution

q2=[2,-2i+3j-4k][2,-2i+3j-4k]=[2×2-((-2)×(-2)+3×3+(-4)×(-4)),+2×2(-2i+3j-4k)]=[-25,-8i+12j-16k]

11.20.6 Inverse of a Quaternion

Compute  the inverse of this quaternion:

q=[2,-2i+3j-4k]

Solution

q∗=[2,2i-3j+4k]|q|2=22+(-2)2+32+(-4)2=33q-1=133[2,2i-3j+4k]

References

1.

Hamilton WR (1844) On quaternions: or a new system of imaginaries in algebra. Phil Mag 3rd ser. 25

2.

Hamilton WR (1853) Lectures on quaternions. Hodges & Smith, Dublin

3.

Hamilton WR (1899–1901) Elements of quaternions, 2nd edn. In: Jolly CJ (ed), vol 2. Longmans, Green & Co., London

4.

Tait PG (1867) An Elementary treatise on quaternions. Cambridge University Press, Cambridge

5.

Gauss CF (1819) Mutation des Raumes In: Carl Friedrich Gauss W, Achter B (eds) pp. 357-361, König. Gesell. Wissen. Göttingen, 1900

6.

Wilson EB (1901) Vector analysis. Yale University Press, New Haven

7.

Feynman RP. Symmetry and physical laws. In: Feynman lectures in physics, vol. 1

8.

Altmann SL (2005) Rotations, quaternions and double groups. Dover, New York

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_12

12. Quaternions in Space

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

12.1 Introduction

In this chapter I show how quaternions are used to rotate vectors about an arbitrary axis. We begin by reviewing some of the history associated with quaternions, and the development of octonions.

We then examine various quaternion products to discover their rotational properties. This begins with two orthogonal quaternions, and moves towards the general case of using qpq-1 where q is a unit-norm quaternion, and p is a pure quaternion.

A technique shows how to express a quaternion product as a matrix.

We continue to represent a quaternion as an ordered pair, with italic, lower-case letters to represent quaternions, and bold lower-case letters to represent vectors.

12.2 Some History

Hamilton invented quaternions in October 1843, and by December of the same year, his friend, Irish mathematician John Thomas Graves (1806–1870), had invented octaves, which would eventually be called octonions. Arthur Cayley had also been intrigued by Hamilton’s quaternions, and independently invented octonions in 1845. Octonions eventually became known as Cayley numbers rather than octaves, simply because Graves did not publish his results until 1848 – three years after Cayley!

Just as quaternions can be defined in terms of ordered pairs of complex numbers, the octaves, or octonions, can be defined as ordered pairs of quaternions.   

12.3 Quaternion Products

A quaternion q is the union of a scalar s and a vector v:

q=[s,v],s∈IR,v∈IR3

If we express v in terms of its components, we have:

q=[s,xi+yj+zk],s,x,y,z∈IR

When two such quaternions are multiplied together, we obtain a third quaternion:

qa=[sa,va]qb=[sb,vb]qaqb=[sa,va][sb,vb]=[sasb-va·vb,savb+sbva+va×vb]

Naturally, if sa or sb are zero, as in the case of a pure quaternion, the product is simplified. Therefore, in future I will omit any zero terms, to simplify the algebra.

Hamilton had hoped that a quaternion could be used like a complex rotor, where:

Rθ=cosθ+isinθ

rotates a complex number by θ. Could a unit-norm quaternion q be used to rotate a vector stored as a pure quaternion p? Well yes, but only as a special case. To understand this, let’s construct the product of a unit-norm quaternion q and a pure quaternion p. The unit-norm quaternion q is defined as:

q=[s,λv^],s,λ∈IR,v^∈IR3‖v^‖=1s2+λ2=1

(12.1)

and the pure quaternion p stores the vector p to be rotated:

p=[0,p],p∈IR3

Let’s compute the product p′=qp and examine the vector part of p′ to see if p is rotated:

q=[s,λv^]p=[0,p]p′=qp=[s,λv^][0,p]=[-λv^·p,sp+λv^×p]

(12.2)

We can see from (12.2) that the result is a general quaternion with a scalar and a vector component.

12.3.1 Special Case

The special case referred to above is that v^ must be perpendicular to p, which makes the dot product term -λv^·p in (12.2) vanish, and we are left with the pure quaternion:

p′=[0,sp+λv^×p]

(12.3)

Fig. 12.1

Three orthogonal vectors p,v^ and v^×p

Figure 12.1 illustrates this scenario, where p is perpendicular to v^, and v^×p is perpendicular to the plane containing p and v^.

Now as v^ is a unit vector, ‖p‖=‖v^×p‖, which means that we have two orthogonal vectors, i.e. p and v^×p, with the same length. Therefore, to rotate p about v^, all that we have to do is make s=cosθ and λ=sinθ in (12.3):

p′=[0,p′]=[0,cosθp+sinθv^×p]

For example, to rotate a vector about the z-axis, q’s vector v^ must be aligned with the z-axis as shown in Fig. 12.2. If we make the angle of rotation θ=45∘ then:

q=[s,λv^]=[cosθ,sinθk]=22,22k=22[1,k]

Fig. 12.2

The vector 2i is rotated 45∘ by the quaternion q=22,22k

and if the vector to be rotated is p=2i, then:

p=[0,p]=[0,2i]=2[0,i]

There are now four product combinations worth exploring: qp, pq, q-1p and pq-1. It’s not worth considering qp-1 and p-1q as p-1 simply reverses the direction of p. Let’s start with qp:

q=22[1,k]p=2[0,i]p′=qp=2[1,k][0,i]=2[0,i+j]

and p has been rotated 45∘ to p′=2i+2j.

Next, pq:

p=2[0,i]q=22[1,k]p′=pq=2[0,i][1,k]=2[0,i+i×k]=2[0,i-j]

and p has been rotated -45∘ to p′=2i-2j.

Next, q-1p, and as q is a unit-norm quaternion, q-1=q∗:

q=22[1,k]q-1=22[1,-k]p=2[0,i]p′=q-1p=2[1,-k][0,i]=2[0,i-k×i]=2[0,i-j]

and p has been rotated -45∘ to p′=2i-2j.

Finally, pq-1:

p=2[0,i]q=22[1,k]q-1=22[1,-k]p′=pq-1=2[0,i][1,-k]=2[0,i-i×k]=2[0,i+j]

and p has been rotated 45∘ to p′=2i+2j. Thus, for orthogonal quaternions, θ is the angle of rotation, then:

qp=pq-1pq=q-1p

Before moving on, let’s see what happens to the product qp when θ=180∘:

q=[cosθ,sinθk]=[-1,0]p=2[0,i]p′=qp=2[-1,0][0,i]=2[0,-i+0×i]=[0,-2i]

and p has been rotated 180∘ to p′=-2i.

Note that in all the above products, the vector has not been scaled during the rotation. This is because q is a unit-norm quaternion.

Now let’s see what happens if we change the angle between v^ and p. Let’s reduce the angle to 45∘ and retain q’s unit vector, as shown in Fig. 12.3, such that v^ is directed along the z-axis, and p=i+k. Therefore:

v^=kq=cosθ,sinθv^p=[0,p]

Fig. 12.3

Rotating the vector p=i+k by the quaternion q=cosθ,sinθv^

This time we must include the dot product term -sinθv^·p, as it is no longer zero:

q=[cosθ,sinθv^]p=[0,p]p′=qp=[cosθ,sinθv^][0,p]=[-sinθv^·p,cosθp+sinθv^×p]

(12.4)

Substituting v^, p and θ=45∘ in (12.4), we have:

v^=kp=i+kp′=-22k·i+k,22(i+k)+22k×(i+k)=-22,22i+22k+22j=22[-1,i+j+k]

(12.5)

which, unfortunately, is no longer a pure quaternion. Multiplying the vector by a non-orthogonal quaternion has converted some of the vector information into the quaternion’s scalar component.

12.3.2 General Case

Not to worry. Could it be that an inverse quaternion reverses the operation? Let’s see what happens if we post-multiply qp by q-1.

Given:

q=cosθ,sinθk

then:

q-1=cosθ,-sinθk=22,-22k=22[1,-k]

Therefore, post-multiplying (12.5) by q-1 we have:

qp=22[-1,i+j+k]q-1=22[1,-k]qpq-1=22[-1,i+j+k]22[1,-k]=12[-1,i+j+k][1,-k]=12[-1+1,k+i+j+k+(i+j+k)×-k)]=12[0,i+j+2k-i+j]=[0,j+k]

(12.6)

Equation (12.6) is a pure quaternion, with a norm of 2, which is the same as p. However, the vector has been rotated 90∘ rather than 45∘, twice the desired angle, as shown in Fig. 12.4.

Fig. 12.4

The vector i+k is rotated 90∘ to j+k

If this ‘sandwiching’ of the vector in the form of a pure quaternion by q and q-1 is correct, it suggests that increasing θ to 90∘ should rotate p=i+k by 180∘ to -i+k. Let’s try this.

Let θ=90∘, therefore:

q=[cos90∘,sin90∘k]=[0,k]p=[0,i+k]qp=[0,k][0,i+k]=[-1,k×(i+k)]=[-1,j]

Next, we post-multiply qp by q-1:

q-1=[0,-k]qpq-1=[-1,j][0,-k]=[0,k+(j×-k)]=[0,-i+k]

which confirms our prediction and suggests that qpq-1 works.

12.3.3 Double-Angle

Now let’s show how this double-angle arises. We begin by defining a unit-norm quaternion q:

q=[s,λv^]

where s2+λ2=1. The vector p to be rotated is encoded as a pure quaternion:

p=[0,p]

and the inverse quaternion q-1 is:

q-1=[s,-λv^]

Therefore, the product qpq-1 is:

qpq-1=s,λv^[0,p][s,-λv^]=-λv^·p,sp+λv^×p[s,-λv^]=[-λsv^·p+λsp·v^+λ2(v^×p)·v^,+λ2(v^·p)v^+s2p+λsv^×p-λsp×v^-λ2(v^×p)×v^]=λ2(v^×p)·v^,λ2(v^·p)v^+s2p+2λsv^×p-λ2(v^×p)×v^

Note that:

(v^×p)·v^=0

and

(v^×p)×v^=(v^·v^)p-(p·v^)v^=p-(p·v^)v^

Therefore:

qpq-1=0,λ2v^·pv^+s2p+2λsv^×p-λ2p+λ2p·v^v^=0,2λ2v^·pv^+(s2-λ2)p+2λsv^×p

(12.7)

Clearly, (12.7) is a pure quaternion as the scalar component is zero. However, it is not obvious where the angle doubling comes from. But look what happens when we make s=cosθ and λ=sinθ:

qpq-1=0,2sin2θv^·pv^+(cos2θ-sin2θ)p+2sinθcosθv^×p=0,1-cos(2θ)v^·pv^+cos(2θ)p+sin(2θ)v^×p

The double-angle trigonometric terms emerge! Now, if we want this product to actually rotate the vector by θ, then we must build this in from the outset by halving θ in q:

q=cosθ2,sinθ2v^

(12.8)

which makes:

qpq-1=[0,1-cosθv^·pv^+cosθp+sinθv^×p]

(12.9)

The product qpq-1 was discovered by Hamilton who failed to publish the result. Cayley, also discovered the product and published the result in 1845 [1]. However, Altmann notes that ‘in Cayley’s collected papers he concedes priority to Hamilton.’ [2], which was a nice gesture. However, the person who had recognised the importance of the half-angle parameters in (12.8) before Hamilton and Cayley was Rodrigues—who published a solution that was not seen by Hamilton, but apparently, was seen by Cayley.  

Let’s test (12.9) using the previous example where we rotated a vector p=i+k, θ=90∘ about the quaternion’s vector v^=k.

qpq-1=0,(1-cosθ)(v^·p)v^+cosθp+sinθv^×p=0,(v^·p)v^+v^×p=0,(k·(i+k))k+j=0,j+k

which agrees with (12.6). Thus, when a unit-norm quaternion takes the form:

q=cosθ2,sinθ2v^

and a pure quaternion storing a vector to be rotated takes the form:

p=[0,p]

the pure quaternion:

p′=qpq-1

stores the rotated vector p′. Let’s show why this product preserves the magnitude of the rotated vector.

|p′|=|qp||q-1|=|q||p||q-1|=|q|2|p|

and if q is a unit-norm quaternion, |q|=1, then |p′|=|p|.

You may be wondering what happens if the product is reversed to q-1pq? A guess would suggest that the rotation sequence is reversed, but let’s see what an algebraic analysis confirms.

q-1pq=[s,-λv^][0,p][s,λv^]=[λv^·p,sp-λv^×p][s,λv^]=[λsv^·p-λsp·v^,λ2v^×p·v^+λ2v^·pv^+s2p-λsv^×p+λsp×v^-λ2v^×p×v^]=λ2(v^×p)·v^,λ2(v^·p)v^+s2p-2λsv^×p-λ2(v^×p)×v^

Once again:

(v^×p)·v^=0

and

(v^×p)×v^=p-(p·v^)v^

Therefore:

q-1pq=0,λ2(v^·p)v^+s2p-2λsv^×p-λ2p+λ2(p·v^)v^=0,2λ2(v^·p)v^+(s2-λ2)p-2λsv^×p

Again, let’s make s=cosθ and λ=sinθ:

q-1pq=0,(1-cos(2θ))(v^·p)v^+cos(2θ)p-sin(2θ)v^×p

and the only thing that has changed from qpq-1 is the sign of the cross-product term, which reverses the direction of its vector. However, we must remember to compensate for the angle-doubling by halving θ:

q-1pq=0,(1-cosθ)(v^·p)v^+cosθp-sinθv^×p

(12.10)

Let’s see what happens when we employ (12.10) to rotate p=i+k, 90∘ about the quaternion’s vector v^=k:

q-1pq=0,(k·(i+k)k)-j=0,-j+k

which has rotated p clockwise 90∘ about the quaternion’s vector. Therefore, the rotor qpq-1 rotates a vector counter-clockwise, and q-1pq rotates a vector clockwise:

qpq-1=0,(1-cosθ)(v^·p)v^+cosθp+sinθv^×pq-1pq=0,(1-cosθ)(v^·p)v^+cosθp-sinθv^×p

Let’s compute another example. Consider the point P(0, 1, 1) in Fig. 12.5 which is to be rotated 90∘ about the y-axis. We can see that the rotated point P′ has the coordinates (1, 1, 0) which we will confirm algebraically. The point P is represented by its position vector p in the pure quaternion:

p=[0,p]

The axis of rotation is v^=j, and the vector to be rotated is p=j+k. Therefore:

qpq-1=0,(1-cosθ)(v^·p)v^+cosθp+sinθv^×p=0,j·(j+k)j+j×(j+k)=0,i+j

and confirms that P is indeed rotated to (1, 1, 0).

Fig. 12.5

The point P(0, 1, 1) is rotated 90∘ to P′(1,1,0) about the y-axis

Now let’s explore how this product is represented in matrix form.

12.4 Quaternions in Matrix Form

Having discovered a vector equation to represent qpq-1, let’s continue and convert it into a matrix. We will explore two methods: the first is a simple vectorial method which translates the vector equation representing qpq-1 directly into matrix form. The second method uses matrix algebra to develop a rather cunning solution.

12.4.1 Vector Method

For the vector method it is convenient to describe the unit-norm quaternion as:

q=[s,v]=[s,xi+yj+zk]

where:

s2+‖v‖2=1

and the pure quaternion as:

p=[0,p]=[0,xpi+ypj+zpk]

A simple way to compute qpq-1 is to use (12.9) and substitute ‖v‖ for λ:

qpq-1=0,2λ2v^·pv^+(s2-λ2)p+2λsv^×p=0,2‖v‖2v^·pv^+(s2-‖v‖2)p+2‖v‖sv^×p

Next, we substitute v for ‖v‖v^:

qpq-1=0,2v·pv+(s2-‖v‖2)p+2sv×p

Finally, as we are working with unit-norm quaternions to prevent scaling:

s2+‖v‖2=1

and

s2-‖v‖2=2s2-1

therefore:

qpq-1=0,2(v·p)v+(2s2-1)p+2sv×p

If we let p′=qpq-1, which is a pure quaternion, we have:

p′=qpq-1=[0,p′]=0,2(v·p)v+(2s2-1)p+2sv×pp′=2(v·p)v+(2s2-1)p+2sv×p

We are only interested in the rotated vector p′ comprising the three terms 2(v·p)v, (2s2-1)p and 2sv×p, which can be represented by three individual matrices and summed together.

2(v·p)v=2(xxp+yyp+zzp)(xi+yj+zk)=2x22xy2xz2xy2y22yz2xz2yz2z2xpypzp2s2-1p=2s2-1xpi+2s2-1ypj+2s2-1zpk=2s2-10002s2-10002s2-1xpypzp2sv×p=2s((yzp-zyp)i+(zxp-xzp)j+(xyp-yxp)k)=0-2sz2sy2sz0-2sx-2sy2sx0xpypzp

Adding these matrices together:

p′=2s2+x2-12(xy-sz)2(xz+sy)2(xy+sz)2s2+y2-12(yz-sx)2(xz-sy)2(yz+sx)2s2+z2-1xpypzp

(12.11)

or

p′=1-2y2+z22(xy-sz)2(xz+sy)2(xy+sz)1-2x2+z22(yz-sx)2(xz-sy)2(yz+sx)1-2x2+y2xpypzp

(12.12)

where:

[0,p′]=qpq-1

Now let’s reverse the product. To compute the vector part of q-1pq all that we have to do is reverse the sign of 2sv×p:

p′=2s2+x2-12(xy+sz)2(xz-sy)2(xy-sz)2s2+y2-12(yz+sx)2(xz+sy)2(yz-sx)2s2+z2-1xpypzp

(12.13)

or

p′=1-2y2+z22(xy+sz)2(xz-sy)2(xy-sz)1-2x2+z22(yz+sx)2(xz+sy)2(yz-sx)1-2x2+y2xpypzp

(12.14)

where:

[0,p′]=q-1pq

Observe that (12.13) is the transpose of (12.11), and (12.14) is the transpose of (12.12).

12.4.2 Geometric Verification

Let’s illustrate the action of (12.11) by rotating the point (0,1,1),90∘ about the y-axis, as shown in Fig. 12.6. The quaternion takes the form:

q=cosθ2,sinθ2v^

which means that θ=90∘ and v^=j, therefore:

q=cos45∘,sin45∘j^

Consequently:

s=22,x=0,y=22,z=0

Substituting these values in (12.11) gives:

p′=2s2+x2-12(xy-sz)2(xz+sy)2(xy+sz)2s2+y2-12(yz-sx)2(xz-sy)2(yz+sx)2s2+z2-1xpypzp110=001010-100011

where (0,1,1) is rotated to (1,1,0), which is correct.

Fig. 12.6

The point P(0, 1, 1) is rotated 90∘ to P′(1,1,0) about the y-axis

So now we have a transform that rotates a point about an arbitrary axis intersecting the origin without the problems of gimbal lock associated with Euler transforms.

Before moving on, let’s evaluate one more example. Let’s perform a 180∘ rotation about a vector v=i+k. To begin with, we will deliberately forget to convert the v into a unit vector, just to see what happens to the final matrix. The quaternion takes the form:

q=cosθ2,sinθ2v^

but we will use v as specified. Therefore, with θ=180∘:

s=0,x=1,y=0,z=1

Substituting these values in (12.11) gives:

p′=2s2+x2-12(xy-sz)2(xz+sy)2(xy+sz)2s2+y2-12(yz-sx)2(xz-sy)2(yz+sx)2s2+z2-1xpypzp=1020-10201100

which looks nothing like a rotation matrix, and reminds us how important it is to have a unit vector to represent the axis. Let’s repeat these calculations normalising the vector to v^=22i+22k:

s=0,x=22,y=0,z=22

Substituting these values in (12.11) gives:

p′=2s2+x2-12xy-sz2xz+sy2xy+sz2s2+y2-12yz-sx2xz-sy2yz+sx2s2+z2-1xpypzp001=0010-10100100

which not only looks like a rotation matrix, but has a determinant of 1 and rotates the point (1,0,0) to (0,0,1) as shown in Fig. 12.7.

Fig. 12.7

The point P(1,0,0) is rotated 180∘ to P′(0,0,1) about v^

12.5 Multiple Rotations

Say a vector or frame of reference is subjected to two rotations specified by q1 followed by q2. There is a temptation to convert both quaternions to their respective matrix and multiply the matrices together. However, this not the most efficient way of combining the rotations. It is best to accumulate the multiple rotations as quaternions and then convert to matrix notation, if required.

To illustrate this, consider the pure quaternion p subjected to the first quaternion q1:

q1pq1-1

followed by a second quaternion q2:

q2q1pq1-1q2-1

which can be expressed as:

q2q1pq2q1-1

Extra quaternions can be added accordingly. Let’s illustrate this with two examples.

To keep things simple, the first quaternion q1 rotates 30∘ about the y-axis:

q1=cos15∘,sin15∘j

The second quaternion q2 rotates 60∘ also about the y-axis:

q2=cos30∘,sin30∘j

Together, the two quaternions rotate 90∘ about the y-axis. To accumulate these rotations, we multiply them together:

q1q2=cos15∘,sin15∘jcos30∘,sin30∘j=cos15∘cos30∘-sin15∘sin30∘,cos15∘sin30∘j+cos30∘sin15∘j=221,j

which is a quaternion that rotates 90∘ about the y-axis. Using the matrix (12.11) we have:

p′=2s2+x2-12xy-sz2xz+sy2xy+sz2s2+y2-12yz-sx2xz-sy2yz+sx2s2+z2-1xpypzp=001010-100xpypzp

which rotates points about the y-axis by 90∘.

For a second example, let’s just evaluate the quaternions. The first quaternion q1 rotates 90∘ about the x-axis, and q2 rotates 90∘ about the y-axis:

q1=221,iq2=221,jp=[0,i+j]

Therefore:

q2q1=221,i221,j=121,i+j-kq2q1-1=121,-i-j+kq2q1p=121,i+j-k0,i+j=12-2,(i+j)+i-j=-1,iq2q1p(q2q1)-1=12-1,i1,-i-j+k=12-1+1,i+j-k+i-j-k=0,i-k

Thus the point (1,1,0) is rotated to (1,0,-1), which is correct.

12.6 Rotating About an Off-Set Axis

Now that we have a matrix to represent a quaternion rotor, we can employ it to resolve problems such as rotating about an off-set axis using the same techniques associated with normal rotation transforms. We use the following notation to rotate a point about a fixed axis parallel with the y-axis:

x′y′z′1=T(tx,0,tz)Rβ,yT(-tx,0,-tz)xyz1

Therefore, by substituting the matrix qpq-1 for Rβ,y we have:

x′y′z′1=T(tx,0,tz)qpq-1T(-tx,0,-tz)xyz1

Let’s test this by rotating our unit cube 90∘ about the axis intersecting vertices 4 and 6 as shown in Fig. 12.8. The unit-norm quaternion to achieve this is:

Fig. 12.8

The cube is rotated 90∘ about the axis intersecting vertices 4 and 6

q=cos45∘,sin45∘j

with the pure quaternion:

p=[0,p]

Consequently:

s=22,x=0,y=22,z=0

and using (12.11) in a homogeneous form we have:

p′=2s2+x2-12(xy-sz)2(xz+sy)02(xy+sz)2s2+y2-12(yz-sx)02(xz-sy)2(yz+sx)2s2+z2-100001xpypzp1=00100100-10000001xpypzp1

The other two matrices are:

T(-tx,0,0)=100-1010000100001T(tx,0,0)=1001010000100001

Multiplying these three matrices together creates:

p′T(-tx,0,0)=00100100-10000001100-1010000100001=00100100-10010001T(tx,0,0)p′T(-tx,0,0)=100101000010000100100100-10010001=00110100-10010001

T(tx,0,0)p′T(-tx,0,0)=00110100-10010001

(12.15)

Although not mathematically correct, the following statement shows the matrix (12.15) and the array of coordinates representing a unit cube, followed by the rotated cube’s coordinates.

00110100-1001000100001111001100110101010111111111=12121212001100111111000011111111

These coordinates are confirmed by Fig. 12.8.

12.7 Converting a Rotation Matrix to a Quaternion

Very often one has a 3D rotation matrix which would be nice to see as a quaternion. So let’s see how this can be realised. The matrix transform equivalent to qpq-1 is:

qpq-1=2s2+x2-12(xy-sz)2(xz+sy)2(xy+sz)2s2+y2-12(yz-sx)2(xz-sy)2(yz+sx)2s2+z2-1xpypzp

(12.16)

=a11a12a13a21a22a23a31a32a33xpypzp

(12.17)

Inspection of (12.16) and (12.17) shows that by combining various elements we can isolate the terms of a quaternion s,x,y,z. For example, by adding the diagonal terms of (12.17): a11+a22+a33, we obtain:

a11+a22+a33=2s2+x2-1+2s2+y2-1+2s2+z2-1=6s2+2x2+y2+z2-3=4s2-1

therefore:

s=121+a11+a22+a33

To isolate x,y,z we employ:

x=14s(a32-a23)y=14s(a13-a31)z=14s(a21-a12)

12.8 Summary

This chapter has shown how a quaternion is used to rotate a vector about a quaternion’s vector. It would have been useful if this could have been achieved by the simple product qp, like complex numbers. But as we saw, this only works when the quaternion is orthogonal to the vector. The product qpq-1—discovered by Hamilton and Cayley—works for all orientations between a quaternion and a vector. It is also relatively easy to compute. We also saw that the product can be represented as a matrix, which can be integrated with other matrices.

Perhaps one of the most interesting features of quaternions that has emerged in this chapter, is that their imaginary qualities are not required in any calculations, because they are embedded within the algebra.

The reverse product q-1pq reverses the angle of rotation, and is equivalent to changing the sign of the rotation angle in qpq-1. Consequently, it can be used to rotate a frame of reference in the same direction as qpq-1.

12.8.1 Summary of Definitions

Rotating a vector by a quaternion

q=[s,v]s2+‖v‖2=1p=[0,p]qpq-1=0,2(v·p)v+2s2-1p+2sv×pq=cosθ2,sinθ2v^p=[0,p]qpq-1=0,(1-cosθ)(v^·p)v^+cosθp+sinθv^×p

Matrix for rotating a vector by a quaternion

p′=1-2y2+z22(xy-sz)2(xz+sy)2(xy+sz)1-2x2+z22(yz-sx)2(xz-sy)2(yz+sx)1-2x2+y2xpypzp

12.9 Worked Examples

Here are some further worked examples that employ the ideas described above.

12.9.1 Special Case Quaternion

Using the special case of qp, rotate [0,j] 90∘ about the xaxis.

Solution

Use qp to rotate p=[0,j] 90∘ about the x-axis.

For this to work q must be orthogonal to p:

q=cosθ,sinθi=[0,i]

and

p′=qp=[0,i][0,j]=[0,k]

12.9.2 Rotating a Vector Using a Quaternion

Use qpq-1 to rotate p=[0,j] 90∘ about the x-axis.

Solution

For this to work:

q=cosθ2,sinθ2i=22,22i=22[1,i]

and

p′=qpq-1=2222[1,i]0,j[1,-i]=120,j+k1,-i=120,j+k-j+k=0,k

12.9.3 Evaluate qpq-1

Evaluate qpq-1 for p=[0,p] and q=cosθ2,sinθ2v, where θ=360∘.

Solution

q=-1,0qpq-1=-1,0[0,p]-1,0=0,-p-1,0=0,p

which confirms that the vector remains unmoved, as expected.

12.9.4 Evaluate qpq-1 Using a Matrix

Compute the matrix for q=12,32k.

Solution

From q:

s=12,x=0,y=0,z=32

p′=2s2+x2-12(xy-sz)2(xz+sy)2(xy+sz)2s2+y2-12(yz-sx)2(xz-sy)2(yz+sx)2s2+z2-1xpypzp=-12-32032-120001xpypzp

If we plug in the point (1,0,0), it is rotated about the z-axis by 120∘:

-12321=-12-32032-120001100

References

1.

Cayley A (1848) The collected mathematical papers, vol. I, p. 586, note 20

2.

Altmann SL (1986) Rotations, quaternions and double groups. Dover Publications, p. 16

3.

Vince JA (2017) Mathematics for computer graphics, 5th edn. Springer

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_13

13. Interpolation

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

13.1 Introduction

This chapter covers linear and non-linear interpolation of scalars, and includes trigonometric and cubic polynomials. It also includes the interpolation of vectors and quaternions.

13.2 Background

Interpolation is not a branch of mathematics but rather a collection of techniques the reader will find useful when solving computer graphic problems. Basically, an interpolant is a strategy for selecting a number between two limits. For example, if the limits are 2 and 4, a parameter t can be used to select the sequence 2.0, 2.2, 2.4, 2.6, 2.8, 3.0, 3.2, 3.4, 3.6, 3.8, and 4. These numbers could then be used to translate, scale, rotate an object, move a virtual camera, or change the position, colour or brightness of a virtual light source.

To implement the above interpolant for different limits we require a general algorithm, which is one of the first exercises of this chapter. We also need to explore ways of controlling the spacing between the interpolated values. In animation, for example, we often need to move an object very slowly and gradually increase its speed. Conversely, we may want to bring an object to a halt, making its speed less and less. The interpolant function includes a parameter within its algorithm, which permits any interpolated value to be created at will. The parameter can depend upon time, or operate over a distance in space.

13.3 Linear Interpolation

A  linear interpolant generates equal spacing between the interpolated values for equal changes in the interpolating parameter. In the above example the increment 0.2 is calculated by subtracting the first number from the second and dividing the result by 10, i.e. (4-2)/10=0.2. Although this works, it is not in a very flexible form, so let’s express the problem differently.

Given two numbers n1 and n2, which represent the start and final values of the interpolant, we require an interpolated value controlled by a parameter t that varies between 0 and 1. When t=0, the result is n1, and when t=1, the result is n2. A solution to this problem is given by:

n=n1+t(n2-n1)

for when n1=2, n2=4 and t=0.5:

n=2+12(4-2)=3

which is a halfway point. Furthermore, when t=0, n=n1, and when t=1, n=n2, which confirms that we have a sound interpolant. However, it can be expressed differently:

n=n1(1-t)+n2t

(13.1)

which shows what is really going on, and forms the basis for further development. Figure 13.1 shows the graphs of n=1-t and n=t over the range 0≤t≤1.

Fig. 13.1

The graphs of n=1-t and n=t over the range 0≤t≤1

With reference to (13.1), we see that as t changes from 0 to 1, the (1-t) term varies from 1 to 0. This attenuates the value of n1 to zero over the range of t, while the t term scales n2 from zero to its actual value. Figure 13.2 illustrates these two actions with n1=1 and n2=5.

Fig. 13.2

The orange line shows the result of linearly interpolating between 1 and 5

Observe that the terms (1-t) and t sum to unity – this is not a coincidence. This type of interpolant ensures that if it takes a quarter of n1, it balances it with three-quarters of n2, and vice versa. Obviously we could design an interpolant that takes arbitrary portions of n1 and n2, but would lead to arbitrary results.

Although this interpolant is extremely simple, it is widely used in computer graphics software. Just to put it into context, consider the task of moving an object between two locations (x1,y1,z1) and (x2,y2,z2). The interpolated position is given by:

x=x1(1-t)+x2ty=y1(1-t)+y2tz=x1(1-t)+z2t0≤t≤1

The parameter t could be generated from two frame values within an animation. What is assured by this interpolant, is that equal steps in t result in equal steps in x, y, and z. Figure 13.3 illustrates this linear spacing with a 2D example where we interpolate between the points (1,1) and (4,5). Note the equal spacing between the intermediate interpolated points.

Fig. 13.3

Interpolating between the points (1,1) and (4,5)

We can write (13.1) in matrix form as follows:

n=[(1-t)t]n1n2

or as:

n=[t1]-1110n1n2

The reader can confirm that this generates identical results to the algebraic form.

13.4 Non-linear Interpolation

A linear interpolant ensures that equal steps in the parameter t give rise to equal steps in the interpolated values; but it is often required that equal steps in t give rise to unequal steps in the interpolated values. We can achieve this using a variety of mathematical techniques. For example, we could use trigonometric functions or polynomials. To begin with, let’s look at a trigonometric solution.

13.4.1 Trigonometric Interpolation

In  Chap. 4 we noted that sin2t+cos2t=1, which satisfies one of the requirements of an interpolant: the terms must sum to 1. If t varies between 0 and π/2, cos2t varies between 1 and 0, and sin2t varies between 0 and 1, which can be used to modify the two interpolated values n1 and n2 as follows:

n=n1cos2t+n2sin2t,0≤t≤π2

(13.2)

The interpolation curves are shown in Fig. 13.4.

Fig. 13.4

The curves for n=cos2t and n=sin2t

Fig. 13.5

The orange curve interpolates between 1 and 3

Fig. 13.6

Interpolating between two points (1,1) and (4,5)

If n1=1 and n2=3 in (13.2), we obtain the curves shown in Fig. 13.5. If we apply this interpolant to two 2D points in space: (1,1) and (4,5), we obtain a straight-line interpolation, but the distribution of points is non-linear, as shown in Fig. 13.6. In other words, equal steps in t give rise to unequal distances in space.

The main problem with this approach is that it is impossible to change the nature of the curve—it is a sinusoid, and its slope is determined by the interpolated values. One way of gaining control over the interpolated curve is to use a polynomial, which is the subject of the next section.

13.4.2 Cubic Interpolation

To  begin with, let’s develop a cubic blending function that will be similar to the previous sinusoidal one. This can then be extended to provide extra flexibility. A cubic polynomial will form the basis of the interpolant:

v1=at3+bt2+ct+d

and the final interpolant will be of the form:

n=[v1v2]n1n2

The task is to find the values of the constants associated with the polynomials v1 and v2. The requirements are:

1. The cubic function v2 must grow from 0 to 1 for 0≤t≤1.

2. The slope at a point t must equal the slope at the point (1-t). This ensures slope continuity over the range of the function.

3. The value v2 at any point t must also produce (1-v2) at (1-t). This ensures curve continuity.

∙   To satisfy the first requirement:

v2=at3+bt2+ct+d

and when t=0, v2=0 and d=0. Similarly, when t=1, v2=a+b+c.

∙   We now need some calculus, which is described in a later chapter. To satisfy the second requirement, differentiate v2 to obtain the slope:

dv2dt=3at2+2bt+c=3a(1-t)2+2b(1-t)+c

and equating constants we discover c=0 and 0=3a+2b.

∙   To satisfy the third requirement:

at3+bt2=1-[a(1-t)3+b(1-t)2]

where we discover 1=a+b. But 0=3a+2b, therefore a=2 and b=3.

Therefore:

v2=-2t3+3t2

(13.3)

To find the curve’s mirror curve, which starts at 1 and collapses to 0 as t moves from 0 to 1, we subtract (13.3) from 1:

v1=2t3-3t2+1

Therefore, the two polynomials are:

v1=2t3-3t2+1

(13.4)

v2=-2t3+3t2

(13.5)

and are shown in Fig. 13.7. They are used as interpolants as follows:

n=v1n1+v2n2

or in matrix form:

n=[2t3-3t2+1-2t3+3t2]n1n2n=[t3t2t1]2-2-330010n1n2

(13.6)

Fig. 13.7

Two cubic polynomials

If we let n1=1 and n2=3 we obtain the curves shown in Fig. 13.8. And if we apply the interpolant to the points (1,1) and (8,3) we obtain the line shown in Fig. 13.9. This interpolant can be used to blend any pair of numbers together.

Fig. 13.8

Interpolating between 1 and 3 using a cubic interpolant

Fig. 13.9

A cubic interpolant between points (1,1) and (8,3)

Now let’s examine the scenario where we interpolate between two points P1 and P2, and have to arrange that the interpolated curve is tangential with a vector at each point. Such tangent vectors forces the curve into a desired shape, as shown in Fig. 13.11. Unfortunately, calculus is required to compute the slope of the cubic polynomial, which is covered in a later chapter.

As this interpolant can be applied to 2D and 3D points, P1 and P2 are represented by their position vectors P1 and P2, which are unpacked for each Cartesian component.

We now have two position vectors P1 and P2 and their respective tangent vectors s1 and s2. The requirement is to modulate the interpolating curve in Fig. 13.8 with two further cubic curves. One that blends out the tangent vector s1 associated with P1, and the other that blends in the tangent vector s2 associated with P2. Let’s begin with a cubic polynomial to blend s1 to zero:

vout=at3+bt2+ct+d

vout must equal zero when t=0 and t=1, otherwise it will disturb the start and end values. Therefore d=0, and:

a+b+c=0

The rate of change of vout relative to t (i.e. dvout/dt) must equal 1 when t=0, so it can be used to multiply s1. When t=1, dvout/dt must equal 0 to attenuate any trace of s1:

dvoutdt=3at2+2bt+c

but dvout/dt=1 when t=0, and dvout/dt=0 when t=1. Therefore, c=1, and:

3a+2b+1=0

Using (13.6) implies that b=-2 and a=1. Therefore, the polynomial vout has the form:

vout=t3-2t2+t

(13.7)

Using a similar argument, one can prove that the function to blend in s2 equals:

vin=t3-t2

(13.8)

Graphs of (13.4), (13.5), (13.7) and (13.8) are shown in Fig. 13.10. The complete interpolating function looks like:

Fig. 13.10

The four Hermite interpolating curves

n=[2t3-3t2+1-2t3+3t2t3-2t2+tt3-t2]P1P2s1s2

and unpacking the constants and polynomial terms we obtain:

n=[t3t2t11]2-211-33-2-100101000P1P2s1s2

This type of interpolation is called Hermite interpolation, after the French mathematician Charles Hermite (1822–1901). Hermite also proved in 1873 that ‘e’ is transcendental.

Now let’s illustrate Hermite interpolation with a 2D example. It is also very easy to implement the same technique in 3D. Figure 13.11 shows how two points (0,0) and (1,1) are to be connected by a cubic curve that responds to the initial and final tangent vectors. At the start point (0,0) the tangent vector is [-50]T, and at the final point (1,1) the tangent vector is [0-5]T. The x and y interpolants are:

x=[t3t2t11]2-211-33-2-10010100001-50y=[t3t2t11]2-211-33-2-100101000010-5

which become:

x=[t3t2t11]-713-50=-7t3+13t2-5ty=[t3t2t11]-7800=-7t3+8t2

When these polynomials are plotted over the range 0≤t≤1 we obtain the curve shown in Fig. 13.11.

Fig. 13.11

A Hermite curve between the points (0,0) and (1,1) with tangent vectors [-50]T and [0-5]T not drawn to scale

We have now reached a point where we are starting to discover how parametric polynomials can be used to generate space curves, which is the subject of the next chapter. So, to conclude this chapter on interpolants, we will take a look at interpolating vectors.

13.5 Interpolating Vectors

So  far we have been interpolating between a pair of numbers. Now the question arises: can we use the same for interpolating vectors? We can if we interpolate both the magnitude and direction of a vector. However, if we linearly interpolate only the x- and y-components of two vectors, the in-between vectors would neither respect their orientation nor their magnitude. But if we defined two 2D vectors as l1,θ1 and l2,θ2, where l is the magnitude and θ the rotated angle, then a linearly interpolated vector is given by:

l=l1(1-t)+l2tθ=θ1(1-t)+θ2t

and the x- and y-components of the interpolated vector are:

lx=lcosθly=lsinθ

Figure 13.12 shows the trace of interpolating between vector 2,45∘ and vector 3,135∘. The half-way point, when t=0.5, generates the vector 2.5,90∘. The same technique can be used with 3D vectors using the equivalent polar notation.

Fig. 13.12

The trace of interpolating between vectors 2,45∘ and 3,135∘

Fig. 13.13

Vector v is derived from part a of of v1 and part b of v2

We can interpolate between x- y- and z-coordinates if we respect the magnitude and orientation of the encoded vectors using the following technique. Figure 13.13 shows two unit vectors v1 and v2 separated by an angle θ. The interpolated vector v is defined as a proportion of v1 and a proportion of v2:

v=av1+bv2

Let’s define the values of a and b such that they are a function of the separating angle θ. Vector v is tθ from v1 and (1-t)θ from v2, and it is evident from Fig. 13.13 that using the sine rule:

asin[(1-t)θ]=bsin(tθ)

(13.9)

and furthermore:

m=acos(tθ)n=bcos[(1-t)θ]

where:

m+n=1

(13.10)

From (13.9):

b=asin(tθ)sin[(1-t)θ]

and from (13.10) we get:

acos(tθ)+asin(tθ)cos[(1-t)θ]sin[(1-t)θ]=1

Solving for a we find:

a=sin[(1-t)θ]sinθb=sin(tθ)sinθ

Therefore, the final interpolant is:

v=sin[(1-t)θ]sinθv1+sin(tθ)sinθv2

(13.11)

To see how (13.11) operates, let’s consider a simple exercise of interpolating between two unit vectors [10]T and [-1/21/2]T. The angle between the vectors θ is 135∘. (13.11) is used to interpolate the x- and the y-components individually:

vx=sin[(1-t)135∘]sin135∘×(1)+sin(t135∘)sin135∘×-12vy=sin[(1-t)135∘]sin135∘×(0)+sin(t135∘)sin135∘×12

Figure 13.14 shows the interpolating curves and Fig. 13.15 shows a trace of the interpolated vectors.

Fig. 13.14

Curves of vx and vy using (13.11)

Two observations to note with (13.11):

∙ The angle θ is the angle between the two vectors, which, if not known, can be computed using the dot product.

∙ Secondly, the range of θ is given by 0≤θ≤180∘, but when θ=180∘ the denominator collapses to zero.

Fig. 13.15

A trace of the interpolated vectors [10]T and [-1/21/2]T

So far, we have only considered unit vectors. Now let’s see how the interpolant reacts to vectors of different magnitudes. As a test, we can input the following vectors to (13.11):

v1=[20]T,andv2=[01]T

The separating angle θ=90∘, and the result is shown in Fig. 13.16. Note how the initial length of v1 reduces from 2 to 1 over 90∘. It is left to the reader to examine other combinations of vectors. There is one more application for this interpolant, and that is with quaternions.

Fig. 13.16

Interpolating between the vectors [20]T and [01]T

13.6 Interpolating Quaternions

It  just so happens that the interpolant used for vectors also works with quaternions. Which means that, given two quaternions q1 and q2, the interpolated quaternion q is given by:

q=sin[(1-t)θ]sinθq1+sin(tθ)sinθq2

(13.12)

The interpolant is applied individually to the four terms of the quaternion.

When interpolating vectors, θ is the angle between the two vectors. If this is not known, it can be derived using the dot product formula:

cosθ=v1·v2‖v1‖‖v2‖=x1x2+y1y2+z1z2‖v1‖‖v2‖

Similarly, when interpolating quaternions, θ is computed by taking the 4-D dot product of the two quaternions:

cosθ=q1·q2|q1||q2|=s1s2+x1x2+y1y2+z1z2|q1||q2|

If we are using unit quaternions:

cosθ=s1s2+x1x2+y1y2+z1z2

(13.13)

We are now in a position to demonstrate how to interpolate between a pair of quaternions. For example, say we have two quaternions q1 and q2 that rotate 0∘ and 90∘ about the z-axis respectively:

q1=cos0∘2,sin0∘2(0i+0j+1k)q1=cos90∘2,sin90∘2(0i+0j+1k)

which become:

q1=[1,0i+0j+0k]q2≈[0.7071,0i+0j+0.7071k]

Any interpolated quaternion is found by the application of (13.12). But first, we need to find the value of θ using (13.13):

cosθ≈0.7071θ=45∘

Now when t=0.5, the interpolated quaternion is given by:

q≈sin(45∘/2)sin45∘[1,0i+0j+0k]+sin(45∘/2)sin45∘[0.7071,0i+0j+0.7071k]≈0.541196[1,0i+0j+0k]+0.541196[0.7071,0i+0j+0.7071k]≈[0.541196,0i+0j+0k]+[0.382683,0i+0j+0.382683k]≈[0.923879,0i+0j+0.382683k]

Although it is not obvious, this interpolated quaternion is also a unit quaternion, as the square root of the sum of the squares is 1. It should rotate a point about the z-axis, halfway between 0∘ and 90∘, i.e. 45∘. We can test that this works with a simple example.

Take the point (1,0,0) and subject it to the standard quaternion operation:

P′=qPq-1

To keep the arithmetic work to a minimum, we substitute a=0.923879 and b=0.382683. Therefore:

q=[a,0i+0j+bk]q-1=[a,-0i-0j-bk]P′=[a,0i+0j+bk][0,1i+0j+0k][a,-0i-0j-bk]=[0,ai+bj+0k][a,-0i-0j-bk]=[0,(a2-b2)i+2abj+0k]P′≈[0,0.7071i+0.7071j+0k]

Therefore, (1,0,0) is rotated to (0.7071,0.7071,0), which is correct!

13.7 Summary

This chapter has covered some very interesting, yet simple ideas about changing one number into another. In the following chapter we will develop these ideas and see how we design algebraic solutions to curves and surfaces.

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_14

14. Curves and Patches

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

14.1 Introduction

In this chapter we investigate the foundations of curves and surface patches. This is a very large and complex subject and it will be impossible to delve too deeply. However, we can explore many of the ideas that are essential to understanding the mathematics behind 2D and 3D curves and how they are developed to produce surface patches. Once you have understood these ideas you will be able to read more advanced texts and develop a wider knowledge of the subject.

14.2 Bézier Curves

   Two people, working for competing French car manufacturers, are associated with what are now called Bézier curves: the French physicist and mathematician Paul de Casteljau (1930–2022), who worked for Citröen, and the French engineer Pierre Bézier (1910–1999), who worked for Rénault. De Casteljau’s work was slightly ahead of Bézier’s, but because of Citröen’s policy of secrecy it was never published, so Bézier’s name has since been associated with the theory of polynomial curves and surfaces. Casteljau started his research work in 1959, but his reports were only discovered in 1975, by which time Bézier had become known for his special curves and surfaces.

In the previous chapter we saw how polynomials are used as interpolants and blending functions. We will now see how these form the basis of parametric curves and patches. To begin with, let’s start with the humble circle.

14.3 The Circle

The circle has a very simple equation:

x2+y2=r2

where r is the radius and (x,y) is a point on the circumference. Although this equation has its uses, it is not very convenient for drawing the curve. What we really want are two functions that generate the coordinates of any point on the circumference in terms of some parameter t. Figure 14.1 shows a scenario where the x- and y-coordinates are given by:

x=rcosty=rsint0≤t≤2π

By varying the parameter t over the range 0 to 2π, we trace out the curve of the circumference. In fact, by selecting a suitable range of t we can isolate any portion of the circle’s circumference.

Fig. 14.1

The circle is drawn by tracing out a series of points on the circumference

14.4 The Ellipse

The equation for an ellipse is:

x2rmaj2+y2rmin2=1

and its parametric form is:

x=rmajcosty=rminsint0≤t≤2π

where rmaj and rmin are the major and minor radii respectively, and (x,y) is a point on the circumference, as shown in Fig. 14.2. We now examine a very useful parametric curve called a Bézier curve.

Fig. 14.2

An ellipse showing the major and minor radii

14.5 Bézier Curves

14.5.1 Bernstein Polynomials

 Bézier curves employ Bernstein polynomials which were described by the Russian mathematician Sergei Bernstein (1880–1968) in 1912. They are expressed as follows:

Bin(t)=niti(1-t)n-i

(14.1)

where ni is shorthand for the number of selections of i different items from n distinguishable items when the order of selection is ignored, and equals:

ni=n!(n-i)!i!

(14.2)

where, for example, 3! (factorial 3) is shorthand for 3×2×1. When (14.2) is evaluated for different values of i and n, we discover the pattern of numbers shown in Table 14.1. This pattern of numbers is known as Pascal’s triangle. In western countries they are named after a 17th century French mathematician, even though they had been described in China as early as 1303 in Precious Mirror of the Four Elements by the Chinese mathematician Chu Shih-chieh. The pattern represents the coefficients found in binomial expansions. For example, the expansion of (x+a)n for different values of n is:

(x+a)0=1(x+a)1=1x+1a(x+a)2=1x2+2ax+1a2(x+a)3=1x3+3ax2+3a2x+1a3(x+a)4=1x4+4ax3+6a2x2+4a3x+1a4

which reveal Pascal’s triangle as coefficients of the polynomial terms. Thus the ni term in (14.1) is nothing more than a generator for Pascal’s triangle. The powers of t and (1-t) in (14.1) appear as shown in Table 14.2 for different values of n and i. When the two sets of results are combined we get the complete Bernstein polynomial terms shown in Table 14.3. One very important property of these terms is that they sum to unity, which is an important feature of any interpolant.

Table 14.1

Pascal’s triangle

i

n

0

1

2

3

4

5

6

0

1

1

1

1

2

1

2

1

3

1

3

3

1

4

1

4

6

4

1

5

1

5

10

10

5

1

6

1

6

15

20

15

6

1

Table 14.2

Expansion of the terms t and (1-t)

i

n

0

1

2

3

4

1

t

(1-t)

2

t2

t(1-t)

(1-t)2

3

t3

t2(1-t)

t(1-t)2

(1-t)3

4

t4

t3(1-t)

t2(1-t)2

t(1-t)3

(1-t)4

Table 14.3

The Bernstein polynomial terms

i

n

0

1

2

3

4

1

1t

1(1-t)

2

1t2

2t(1-t)

1(1-t)2

3

1t3

3t2(1-t)

3t(1-t)2

1(1-t)3

4

1t4

4t3(1-t)

6t2(1-t)2

4t(1-t)3

1(1-t)4

The sum of (1-t) and t is 1, therefore:

[(1-t)+t]n=1

(14.3)

which is why we can use the binomial expansion of (1-t) and t as interpolants. For example, when n=2 we obtain the quadratic form:

(1-t)2+2t(1-t)+t2=1

(14.4)

Figure 14.3 shows the graphs of the three polynomial terms of (14.4). The (1-t)2 graph starts at 1 and decays to zero, whereas the t2 graph starts at zero and rises to 1. The 2t(1-t) graph starts at zero reaches a maximum of 0.5 and returns to zero. Thus the central polynomial term has no influence at the end conditions, where t=0 and t=1. We can use these three terms to interpolate between a pair of values as follows:

v=v1(1-t)2+2t(1-t)+v2t2

Fig. 14.3

Graphs of the quadratic Bernstein polynomials

If v1=1 and v2=3 we obtain the curve shown in Fig. 14.4. However, there is nothing preventing us from multiplying the middle term 2t(1-t) by any arbitrary number vc:

v=v1(1-t)2+vc2t(1-t)+v2t2

(14.5)

Fig. 14.4

Bernstein interpolation between the values 1 and 3

For example, if vc=3, we obtain the graph shown in Fig. 14.5, which is totally different to the curve in Fig. 14.4. As Bézier observed, the value of vc provides an excellent mechanism for determining the rate of change between two values. Figure 14.6 shows a variety of graphs for different values of vc. A very interesting effect occurs when the value of vc is set midway between v1 and v2. For example, when v1=1, v2=3 and vc=2, we obtain linear interpolation between v1 and v2, as shown in Fig. 14.5.

Fig. 14.5

Bernstein interpolation between the values 1 and 3 with vc=3

Fig. 14.6

Bernstein interpolation between the values 1 for different values of vc

14.5.2 Quadratic Bézier Curves

 Quadratic Bézier curves are formed by using Bernstein polynomials to interpolate between the x-, y- and z-coordinates associated with the start- and end-points forming the curve. For example, we can draw a 2D quadratic Bézier curve between (1,1) and (4,3) using the following equations:

x=1(1-t)2+xc2t(1-t)+4t2

(14.6)

y=1(1-t)2+yc2t(1-t)+3t2

(14.7)

But what should be the values of (xc,yc)? Well, this is entirely up to us; the position of this control vertex determines how the curve moves between (1,1) and (4,3).

A Bézier curve possesses interpolating and approximating qualities: the interpolating feature ensures that the curve passes through the end points, while the approximating feature shows how the curve passes close to the control point. To illustrate this, if we make xc=3 and yc=4 we obtain the curve shown in Fig. 14.7, which shows how the curve intersects the end-points, but misses the control point. It also highlights two important features of Bézier curves: the convex hull property, and the end slopes of the curve.

Fig. 14.7

Quadratic Bézier curve between (1,1) and (4,3), with (3,4) as the control vertex

The convex hull property implies that the curve is always contained within the polygon connecting the start, end and control points. In this case the curve is inside the triangle formed by the vertices (1,1), (3,4) and (4,3). The slope of the curve at (1,1) is equal to the slope of the line connecting the start point to the control point (3,4), and the slope of the curve at (4,3) is equal to the slope of the line connecting the control point (3,4) to the end point (4,3). Naturally, these two qualities of Bézier curves can be proved mathematically.

14.5.3 Cubic Bernstein Polynomials

  Before moving on, there are two further points to note:

∙ No restrictions are placed upon the position of (xc,yc)—it can be anywhere.

∙ Simply including z-coordinates for the start, end and control vertices creates 3D curves.

One of the drawbacks with quadratic curves is that they are perhaps, too simple. If we want to construct a complex curve with several peaks and valleys, we would have to join together a large number of such curves. A cubic curve, on the other hand, naturally supports one peak and one valley, which simplifies the construction of more complex curves, and takes us to cubic Bernstein polynomials.

When n=3 in (14.3) we obtain the following terms:

[(1-t)+t]3=(1-t)3+3t(1-t)2+3t2(1-t)+t3

which can be used as a cubic interpolant, as:

v=v1(1-t)3+vc13t(1-t)2+vc23t2(1-t)+v2t3

Once more, the terms sum to unity, and the convex hull and slope properties also hold. Figure 14.8 shows the graphs of the four polynomial terms.

Fig. 14.8

The cubic Bernstein polynomial curves

This time we have two control values vc1 and vc2. These are set to any value, independent of the values chosen for v1 and v2. To illustrate this, let’s consider an example of blending between values 1 and 3, with vc1 and vc2 set to 2.5 and -2.5 respectively. The blending curve is shown in Fig. 14.9.

Fig. 14.9

The cubic Bernstein polynomial through the values 1, 2.5, −2.5, 3

The next step is to associate the blending polynomials with x- and y-coordinates:

x=x1(1-t)3+xc13t(1-t)2+xc23t2(1-t)+x2t3

(14.8)

y=y1(1-t)3+yc13t(1-t)2+yc23t2(1-t)+y2t3

(14.9)

Evaluating (14.8) and (14.9) with the following points:

(x1,y1)=(1,1),(x2,y2)=(4,3)(xc1,yc1)=(2,3),(xc2,yc2)=(3,-2)

we obtain the cubic Bézier curve shown in Fig. 14.10, which also shows the guidelines between the end and control points.

Fig. 14.10

A cubic Bézier curve

Just to show how consistent Bernstein polynomials are, let’s set the values to

(x1,y1)=(1,1),(x2,y2)=(4,3)(xc1,yc1)=(2,1.6¯),(xc2,yc2)=(3,2.3¯)

where (xc1,yc1) and (xc2,yc2) are points one-third and two-thirds respectively, between the start and final values. As we found in the quadratic case, where the single control point was halfway between the start and end values, we obtain linear interpolation as shown in Fig. 14.11.

Fig. 14.11

A cubic Bézier line

As mathematicians are interested in expressing a formula succinctly, there is an elegant way of abbreviating Bernstein polynomials. Equations (14.6) and (14.7) describe the three polynomial terms for generating a quadratic Bézier curve and (14.8) and (14.9) describe the four polynomial terms for generating a cubic Bézier curve. To begin with, quadratic equations are called second-degree equations, and cubics are called third-degree equations. In the original Bernstein formulation:

Bin(t)=niti(1-t)n-i

n represents the degree of the polynomial, and i, which has values between 0 and n, creates the individual polynomial terms. These terms are then used to multiply the coordinates of the end and control points. If these points are stored as a vector P, the position vector p(t) for a point on the curve is written:

p(t)=∑i=0nniti(1-t)n-iPi,0≤i≤n

(14.10)

or

p(t)=∑i=0nBin(t)Pi,0≤i≤n

(14.11)

For example, a point p(t) on a quadratic curve is represented by:

p(t)=1t0(1-t)2P0+2t1(1-t)1P1+1t2(1-t)0P2

You will discover (14.10) and (14.11) used in more advanced texts to describe Bézier curves. Although they initially appear intimidating, you should now find them relatively easy to understand.

14.6 A Recursive Bézier Formula

Note that (14.10) explicitly describes the polynomial terms needed to construct the blending terms. With the use of a recursive Bézier formula (a recursive function is a function that calls itself), it is possible to arrive at another formulation that leads towards an understanding of B-splines. To begin, we need to express ni in terms of lower terms, and because the coefficients of any row in Pascal’s triangle are the sum of the two coefficients immediately above, we can write:

ni=n-1i+n-1i-1

Therefore, we can write:

Bin(t)=n-1iti(1-t)n-i+n-1i-1ti(1-t)n-iBin(t)=(1-t)Bin-1(t)+tBi-1n-1(t)

As with all recursive functions, some condition must terminate the process; in this case, it is when the degree is zero. Consequently, B00(t)=1 and Bjn(t)=0 for j<0.

14.7 Bézier Curves Using Matrices

As we have already seen, matrices provide a very compact notation for algebraic formulae. So let’s see how Bernstein polynomials lend themselves to this form of notation. Recall (14.4) which defines the three terms associated with a quadratic Bernstein polynomial. These are expanded to:

1-2t+t2,2t-2t2,t2

and written as the product:

t2t11-21-220100

This means that (14.5) can be written:

v=t2t11-21-220100v1vcv2

or

p(t)=t2t11-21-220100P1PcP2

where p(t) points to any point on the curve, and P1, Pc and P2 point to the start, control and end points respectively.

A similar development is used for a cubic Bézier curve, which has the following matrix formulation:

p(t)=t3t2t1-13-313-630-33001000P1Pc1Pc2P2

There is no doubt that Bézier curves are very useful, and they find their way into all sorts of applications. But, perhaps their one weakness is that whenever an end or control vertex is repositioned, the entire curve is modified. So let’s examine another type of curve that prevents this from happening—B-splines. But before we consider this form, let’s revisit linear interpolation between multiple values.

14.7.1 Linear Interpolation

  To linearly interpolate between two numbers v0 and v1, we use the following interpolant:

v(t)=v0(1-t)+v1t,0≤t≤1

But say we have to interpolate continuously between three values on a linear basis, i.e. v0,v1,v2, with the possibility of extending the technique to any number of values. One solution is to use a sequence of parameter values t1,  t2,  t3 that are associated with the given values of v, as shown in Fig. 14.12. For the sake of symmetry:

This sequence of parameters is called a knot vector. The only assumption we make about the knot vector is that t0≤t1≤t2≤, etc.

Fig. 14.12

Linearly interpolating between several values

Now let’s invent a linear blending function Bi1(t) whose subscript i is used to reference values in the knot vector. We want to use the blending function to compute the influence of the three values on any interpolated value v(t) as follows:

v(t)=B01(t)v0+B11(t)v1+B21(t)v2.

(14.12)

It’s obvious from this arrangement that v0 will influence v(t) only when t is between t0 and t2. Similarly, v1 and v2 will influence v(t) only when t is between t1 and t3, and t2 and t4 respectively.

To understand the action of the blending function let’s concentrate upon one particular value B11(t). When t is less than t1 or greater than t3, the function B11(t) must be zero. When t1≤t≤t3, the function must return a value reflecting the proportion of v1 that influences v(t). During the span t1≤t≤t2, v1 has to be blended in, and during the span t1≤t≤t3, v1 has to be blended out. The blending in is effected by the ratio:

t-t1t2-t1

and the blending out is effected by the ratio:

t3-tt3-t2

Thus B11(t) has to incorporate both ratios, but it must ensure that they only become active during the appropriate range of t. Let’s remind ourselves of this requirement by subscripting the ratios accordingly:

B11(t)=t-t1t2-t11,2+t3-tt3-t22,3

We can now write the other two blending terms B01(t) and B21(t) as:

B01(t)=t-t0t1-t00,1+t2-tt2-t11,2B21(t)=t-t2t3-t22,3+t4-tt4-t33,4

You should be able to see a pattern linking the variables with their subscripts, and the possibility of writing a general linear blending term Bi1(t) as:

Bi1(t)=t-titi+1-tii,i+1+ti+2-tti+2-ti+1i+1,i+2

This enables us to write (14.12) in a general form as:

v(t)=∑i=02Bi1(t)vi

But there is still a problem concerning the values associated with the knot vector. Fortunately, there is an easy solution. One simple approach is to keep the differences between t1, t2 and t3 whole numbers, e.g. 0, 1 and 2. But what about the end conditions t0 and t4? To understand the resolution of this problem let’s examine the action of the three terms over the range of the parameter t. The three terms are:

t-t0t1-t00,1+t2-tt2-t11,2v0

(14.13)

t-t1t2-t11,2+t3-tt3-t22,3v1

(14.14)

t-t2t3-t22,3+t4-tt4-t33,4v2

(14.15)

and I propose to initialise the knot vector as shown in Table 14.4:

Table 14.4

Knot vector

t0

t1

t2

t3

t4

0

0

1

2

2

This process results in a linear interpolation between v0, v1 and v2. If (14.13), (14.14) and (14.15) are applied to coordinate values, the result is two straight lines. This seems like a lot of work just to draw two lines, but the beauty of the technique is that it will work with any number of points, and can be developed for quadratic and higher order interpolants.

The New Zealand mathematician Alexander Aitken (1895–1967), developed the following recursive interpolant:

pir(t)=ti+r-tti+r-tipir-1(t)+t-titi+r-tipi+1r-1(t)r=1,..ni=0,..n-r

which interpolates between a series of points using repeated linear interpolation.

14.8 B-Splines

B-splines, like Bézier curves, use polynomials to generate a curve segment. But, unlike Bézier curves, B-splines employ a series of control points that determine the curve’s local geometry. This feature ensures that only a small portion of the curve is changed when a control point is moved.

There are two types of B-splines: rational and non-rational splines, which divide into two further categories: uniform and non-uniform. Rational B-splines are formed from the ratio of two polynomials such as:

x(t)=X(t)W(t),y(t)=Y(t)W(t),z(t)=Z(t)W(t)

Although this appears to introduce an unnecessary complication, the division by a second polynomial brings certain advantages:

An explanation of uniform and non-uniform types is best left until you understand the idea of splines. So, without knowing the meaning of uniform, let’s begin with uniform B-splines.

Fig. 14.13

The construction of a uniform non-rational B-spline curve

14.8.1 B-Spline Basis Functions

  A B-spline is constructed from a string of curve segments whose geometry is determined by a group of local control points. These curves are known as piecewise polynomials. A curve segment does not have to pass through a control point, although this may be desirable at the two end points.

Cubic B-splines are very common, as they provide a geometry that is one step away from simple quadratics, and possess continuity characteristics that make the joins between the segments invisible. In order to understand their construction consider the scenario in Fig. 14.13. Here we see a group of (m+1) control points P0, P1, P2, ..., Pm which determine the shape of a cubic curve constructed from a series of curve segments S0, S1, S2, ..., Sm-3.

As the curve is cubic, curve segment Si is influenced by Pi, Pi+1, Pi+2, Pi+3, and curve segment Si+1 is influenced by Pi+1, Pi+2, Pi+3, Pi+4. And as there are (m+1) control points, there are (m-2) curve segments.

A single segment Si(t) of a B-spline curve is defined by:

Si(t)=∑r=03Pi+rBr(t),0≤t≤1

where:

B0(t)=16-t3+3t2-3t+1=16(1-t)3

(14.16)

B1(t)=163t3-6t2+4

(14.17)

B2(t)=16-3t3+3t2+3t+1

(14.18)

B3(t)=16t3

(14.19)

These are the B-spline basis functions and are shown in Fig. 14.14.

Fig. 14.14

The B-spline basis functions

Although it is not apparent, these four curve segments are part of one curve. The basis function B3(t) starts at zero and rises to 0.16¯ at t=1. It is taken over by B2(t) at t=0, which rises to 0.6¯ at t=1. The next segment is B1(t) and takes over at t=0 and falls to 0.16¯ at t=1. Finally, B0(t) takes over at 0.16¯ and falls to zero at t=1. Equations (14.16)–(14.19) are represented in matrix form by:

Q1(t)=16t3t2t1-13-313-630-30301410PiPi+1Pi+2Pi+3

(14.20)

Let’s now illustrate how (14.20) works. We first identify the control points Pi, Pi+1, Pi+2, etc. Let these be (0,1),  (1,3),  (2,0),  (4,1),  (4,3),  (2,2) and (2,3). They can be seen in Fig. 14.15 connected together by straight lines. If we take the first four control points: (0,1),(1,3),(2,0),(4,1), and subject the x- and y-coordinates to the matrix in (14.20) over the range 0≤t≤1 we obtain the first B-spline curve segment shown in Fig. 14.15. If we move along one control point and take the next group of control points (1,3),(2,0),(4,1),(4,3), we obtain the second B-spline curve segment. This is repeated a further two times.

Figure 14.15 shows the four curve segments, and it is obvious that even though there are four discrete segments, they join together perfectly. This is no accident. The slopes at the end points of the basis curves are designed to match the slopes of their neighbours and ultimately keep the geometric curve continuous.

Fig. 14.15

Four curve segments forming a B-spline curve

14.8.2 Geometric Continuity

    In order to explain continuity, it is necessary to employ differentiation. Therefore, you may wish to read the chapter on calculus before continuing.

Constructing curves from several segments can only succeed if the slope of the abutting curves match. As we are dealing with curves whose slopes are changing everywhere, it will be necessary to ensure that even the rate of change of slopes is matched at the join. This aspect of curve design is called geometric continuity and is determined by the continuity properties of the basis function. Let’s explore such features.

The first level of curve continuity C0, ensures that the physical end of one basis curve corresponds with the following, e.g. Si(1)=Si+1(0). We know that this occurs from the basis graphs shown in Fig. 14.14. The second level of curve continuity C1, ensures that the slope at the end of one basis curve matches that of the following curve. This is confirmed by differentiating the basis functions (14.16)–(14.19):

B0′(t)=16-3t2+6t-3

(14.21)

B1′(t)=169t2-12t

(14.22)

B2′(t)=16-9t2+6t+3

(14.23)

B3′(t)=163t2

(14.24)

Evaluating (14.21)–(14.24) for t=0 and t=1, we discover the slopes 0.5,0,-0.5,0 for the joins between B3, B2, B1, B0. The third level of curve continuity C2, ensures that the rate of change of slope at the end of one basis curve matches that of the following curve. This is confirmed by differentiating (14.21)–(14.24):

B0′′(t)=-t+1

(14.25)

B1′′(t)=3t-2

(14.26)

B2′′(t)=-3t+1

(14.27)

B3′′(t)=t

(14.28)

Evaluating (14.25)–(14.28) for t=0 and t=1, we discover the values 1,2,1,0 for the joins between B3, B2, B1, B0. These combined continuity results are tabulated in Table 14.5.

Table 14.5

Continuity properties of cubic B-splines

t

t

t

C0

0

1

C1

0

1

C2

0

1

B3(t)

0

1/6

B3′(t)

0

0.5

B3′′(t)

0

1

B2(t)

1/6

2/3

B2′(t)

0.5

0

B2′′(t)

1

-2

B1(t)

2/3

1/6

B1′(t)

0

-0.5

B1′′(t)

-2

1

B0(t)

1/6

0

B0′(t)

-0.5

0

B0′′(t)

1

0

14.8.3 Non-uniform B-Splines

  Uniform B-splines are constructed from curve segments where the parameter spacing is at equal intervals. Non-uniform B-splines, with the support of a knot vector, provide extra shape control and the possibility of drawing periodic shapes. Unfortunately an explanation of the underlying mathematics would take us beyond the introductory nature of this text, and readers are advised to seek out other books dealing in such matters.

14.8.4 Non-uniform Rational B-Splines

 Non-uniform rational B-splines (NURBS) combine the advantages of non-uniform B-splines and rational polynomials: they support periodic shapes such as circles, and they accurately describe curves associated with the conic sections. They also play a very important role in describing geometry used in the modeling of computer animation characters.

NURBS surfaces also have a patch formulation and play a very important role in surface modelling in computer animation and CAD. However, tempting though it is to give a description of NURBS surfaces here, they have been omitted because their inclusion would unbalance the introductory nature of this text.

14.9 Surface Patches

14.9.1 Planar Surface Patch

  The simplest form of surface geometry consists of a patchwork of polygons or triangles, where three or more vertices provide the basis for describing the associated planar surface patch. For example, given four vertices P00, P10, P01, P11 as shown in Fig. 14.16, a point Puv can be defined as follows. To begin with, a point along the edge P00–P10 is defined as:

Pu1=(1-u)P00+uP10

and a point along the edge P01–P11 is defined as:

Pu2=(1-u)P01+uP11

Therefore, any point Puv is defined as:

Puv=(1-v)Pu1+vPu2=(1-v)[(1-u)P00+uP10]+v[(1-u)P01+uP11]=(1-u)(1-v)P00+u(1-v)P10+v(1-u)P01+uvP11

and is written in matrix form as:

Puv=[1-uu]P00P01P10P111-vv

which expands to:

Puv=[u1]-1110P00P01P10P11-1110v1

Fig. 14.16

A flat patch defined by u and v parameters

Let’s illustrate this with an example. Given the following four points: P00=(0,0,0), P10=(0,0,4), P01=(2,2,1), P11=(2,2,3), we can write the coordinates of any point on the patch as:

xuv=[u1]-11100202-1110v1yuv=[u1]-11100202-1110v1zuv=[u1]-11100143-1110v1

xuv=2v

(14.29)

yuv=2v

(14.30)

zuv=u(4-2v)+v

(14.31)

By substituting values of u and v in (14.29)–(14.31) between the range 0≤(u,v)≤1, we obtain the coordinates of any point on the surface of the patch.

If we now introduce the ideas of Bézier control points into a surface patch definition, we provide a very powerful way of creating smooth 3D surface patches.

14.9.2 Quadratic Bézier Surface Patch

  Bézier proposed a matrix of nine control points to determine the geometry of a quadratic surface patch, as shown in Fig. 14.17. Any point on the patch is defined by:

Puv=u2u11-21-220100P00P01P02P10P11P12P20P21P221-21-220100v2v1

Fig. 14.17

A quadratic Bézier surface patch

The individual x-, y- and z-coordinates are obtained by substituting the x-, y- and z-values for the central P matrix.

Let’s illustrate the process with an example. Given the following points:

P00=(0,0,0),P01=(1,1,0),P02=(2,0,0)P10=(0,1,1),P11=(1,2,1),P12=(2,1,1)P20=(0,0,2),P21=(1,1,2),P22=(2,0,2)

we can write:

xuv=u2u11-21-2201000120120121-21-220100v2v1xuv=u2u1000000020v2v1xuv=2vyuv=u2u11-21-2201000101210101-21-220100v2v1yuv=u2u100-2002-220v2v1yuv=2u+v-u2-v2zuv=u2u11-21-2201000001112221-21-220100v2v1zuv=u2u1000002000v2v1zuv=2u

Therefore, any point on the surface patch has coordinates:

xuv=2v,yuv=2u+v-u2-v2,zuv=2u

Table 14.6 shows the coordinate values for different values of u and v. In this example, the y-coordinates provide the surface curvature, which could be enhanced by modifying the y-coordinates of the control points.

Table 14.6

The x-, y-, z-coordinates for different values of u and v

v

0

0.5

1

0

(0,0,0)

(1,0.5,0)

(2,0,0)

u

0.5

(0,0.5,1)

(1,0.5,1)

(2,0.5,1)

1

(0,0,2)

(1,0.5,2)

(2,0,2)

14.9.3 Cubic Bézier Surface Patch

 As we saw earlier in this chapter, cubic Bézier curves require two end-points, and two central control points. In the cubic Bézier surface patch formulation a 4×4 matrix is required as follows:

Puv=u3u2u1-13-313-630-33001000P00P01P02P03P10P11P12P13P20P21P22P23P30P31P32P33-13-313-630-33001000v3v2v1

which is illustrated with an example.

Given the points:

P00=(0,0,0),P01=(1,1,0),P02=(2,1,0),P03=(3,0,0)P10=(0,1,1),P11=(1,2,1),P12=(2,2,1),P13=(3,1,1)P20=(0,1,2),P21=(1,2,2),P22=(2,2,2),P23=(3,1,2)P30=(0,0,3),P31=(1,1,3),P32=(2,1,3),P33=(3,0,3)

we can write the following matrix equations:

xuv=u3u2u1-13-313-630-330010000123012301230123-13-313-630-33001000v3v2v1xuv=u3u2u10000000000000030v3v2v1xuv=3vyuv=u3u2u1-13-313-630-330010000110122112210110-13-313-630-33001000v3v2v1yuv=u3u2u10000000-300030-330v3v2v1

zuv=u3u2u1-13-313-630-330010000000111122223333-13-313-630-33001000v3v2v1zuv=u3u2u10000000000030000v3v2v1

Therefore, any point on the surface patch has coordinates:

xuv=3v,yuv=3u+v-u2-v2,zuv=3u

Table 14.7 shows the coordinate values for different values of u and v. In this example, the y-coordinates provide the surface curvature, which could be enhanced by modifying the y-coordinates of the control points.

Complex 3D surfaces are readily modelled using Bézier patches. One simply creates a mesh of patches such that their control points are shared at the joins. Surface continuity is controlled using the same mechanism for curves. But where the slopes of trailing and starting control edges apply for curves, the corresponding slopes of control tiles apply for patches.

Table 14.7

The x-, y-, z-coordinates for different values of u and v

v

0

0.5

1

0

(0,0,0)

(1.5,0.75,0)

(3,0,0)

u

0.5

(0,0.75,1.5

(1.5,1.5,1.5)

(3,0.75,1.5)

1

(0,0,3)

(1.5,0.75,3)

(3,0,3)

14.10 Summary

This subject has been the most challenging one to describe. On the one hand, the subject is vital to every aspect of computer graphics, and on the other, the reader is required to wrestle with cubic polynomials and a little calculus. However, I do hope that I have managed to communicate some essential concepts behind curves and surfaces, and that you will be tempted to implement some of the mathematics.

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_15

15. Analytic Geometry

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

15.1 Introduction

This chapter explores some basic elements of geometry and analytic geometry that are frequently encountered in computer graphics. For completeness, I have included a short review of important elements of Euclidean geometry with which you should be familiar. Perhaps the most important topics that you should try to understand concern the definitions of straight lines in space, 3D planes, and how points of intersection are computed. Another useful topic is the role of parameters in describing lines and line segments, and their intersection.

15.2 Background

In the third century BCE, Euclid laid the foundations of geometry that have been taught in schools for centuries. In the 19th century, mathematicians such as Bernhard Riemann (1809–1900) and Nikolai Lobachevsky transformed this Euclidean geometry with ideas such as curved space, and spaces with higher dimensions. Although none of these developments affect computer graphics, they do place Euclid’s theorems in a specific context: a set of axioms that apply to flat surfaces. We have probably all been taught that parallel lines never meet, and that the internal angles of a triangle sum to 180∘, but these are only true in specific situations. As soon as the surface or space becomes curved, such rules break down. So let’s review some rules and observations that apply to shapes drawn on a flat surface.

15.2.1 Angles

By definition, 360∘ or 2π [radians] measure one revolution. You should be familiar with both units of measurement, and how to convert from one to the other. Figure 15.1 shows examples of adjacent / supplementary angles (sum to 180∘), opposite angles (equal), and complementary angles (sum to 90∘).

Fig. 15.1

Examples of adjacent, supplementary, opposite and complementary angles

Fig. 15.2

The first intercept theorem

15.2.2 Intercept Theorems

The intercept theorems are attributed to the Greek philosopher and mathematician Thales of Miletus (c.624–c.546 BC) and involve intersecting and parallel lines. Figures 15.2 and 15.3 show two scenarios that give rise to the following observations:

∙ First intercept theorem:

a+ba=c+dc,ba=dc

∙ Second intercept theorem:

ab=cd

Fig. 15.3

The second intercept theorem

15.2.3 Golden Section

The golden section is widely used in art and architecture to represent an ‘ideal’ ratio for the height and width of an object. Its origins stem from the interaction between a circle and triangle and give rise to the following relationship:

b=a25-1≈0.618a

The rectangle in Fig. 15.4 has proportions:

height=0.618×width

Fig. 15.4

A rectangle with a height to width ratio equal to the golden section

15.2.4 Interior and Exterior Angles of a Triangle

The rules  associated with interior and exterior angles of a triangle are very useful in solving all sorts of geometric problems. Figure 15.5 shows two diagrams identifying interior and exterior angles. We can see that the sum of the interior angles is 180∘, and that the exterior angles of a triangle are equal to the sum of the opposite angles:

α+β+θ=180∘α′=θ+ββ′=α+θθ′=α+β

Fig. 15.5

Relationship between interior and exterior angles

15.2.5 Centre of Gravity of a Triangle

A median is  a straight line joining a vertex of a triangle to the mid-point of the opposite side. When all three medians are drawn, they intersect at a common point, which is also the triangle’s centre of gravity. The centre of gravity divides all the medians in the ratio 2 : 1. Figure 15.6 illustrates this arrangement.

Fig. 15.6

The three medians of a triangle intersect at its centre of gravity

Fig. 15.7

An isosceles triangle

15.2.6 Isosceles Triangle

Figure 15.7 shows  an isosceles triangle, which has two equal sides of length l and equal base angles α. The triangle’s altitude and area are:

h=l2-c22,A=12ch

15.2.7 Equilateral Triangle

An  equilateral triangle has three equal sides of length l and equal angles of 60∘. The triangle’s altitude and area are:

h=32l,A=34l2

15.2.8 Right Triangle

Figure 15.8 shows  a right triangle with its obligatory right angle. The triangle’s altitude and area are:

h=abc,A=12ab

Fig. 15.8

A right triangle

Fig. 15.9

The theorem of Thales

15.2.9 Theorem of Thales

Figure 15.9 illustrates the theorem of Thales, which states that the right angle of a right triangle lies on the circumcircle over the hypotenuse.

Fig. 15.10

The theorem of Pythagoras states that a2=b2+c2

15.2.10 Theorem of Pythagoras

Although the theorem of Pythagoras is named after Pythagoras, there is substantial evidence to show that it was known by the Babylonians a millennium earlier. However, Pythagoras is credited with its proof. Figure 15.10 illustrates the well-known relationship:

a2=b2+c2

from which one can show that:

sin2θ+cos2θ=1

15.2.11 Quadrilateral

Quadrilaterals have four sides and include the square, rectangle, trapezoid, parallelogram and rhombus, whose interior angles sum to 360∘. As the square and rectangle are familiar shapes, we will only consider the other three.

15.2.12 Trapezoid

Figure 15.11 shows a trapezoid which has one pair of parallel sides h apart. The mid-line m and area are given by:

m=12(a+b)A=mh

Fig. 15.11

A trapezoid with one pair of parallel sides

15.2.13 Parallelogram

Figure 15.12 shows a parallelogram, which is formed from two pairs of intersecting parallel lines, so it has equal opposite sides and equal opposite angles. The altitude, diagonal lengths and area are given by:

h=bsinαd1,2=a2+b2±2ab2-h2A=ah

Fig. 15.12

A parallelogram formed by two pairs of parallel lines

15.2.14 Rhombus

Figure 15.13 shows a rhombus, which is a parallelogram with four sides of equal length a. The area is given by:

A=a2sinα=12d1d2

Fig. 15.13

A rhombus is a parallelogram with four equal sides

15.2.15 Regular Polygon

Figure 15.14 shows part of a regular n-gon with outer radius Ro, inner radius Ri and edge length an. Table 15.1 shows the relationship between the area, an, Ri and Ro for different polygons.

Fig. 15.14

Part of a regular gon showing the inner and outer radii and the edge length

Table 15.1

The area An, edge length an, inner radius Ri, and outer radius Ro for different polygons

n

an=2Ritan(180∘/n)

Ri=Rocos(180∘/n)

Ro2=Ri2+14an2

n

An=n4an2cot(180∘/n)

An=n2Ro2sin(360∘/n)

An=nRi2tan(180∘/n)

5

a5=2Ri5-25

Ri=Ro4(5+1)

Ro=Ri(5-1)

5

A5=a52425+105

A5=58Ro210+25

A5=5Ri25-25

6

a6=23Ri3

Ri=Ro23

Ro=23Ri3

6

A6=32a623

A6=32Ro23

A6=2Ri23

8

a8=2Ri(2-1)

Ri=Ro22+2

Ro=Ri4-22

8

A8=2a822+1

A8=2Ro22

A8=8Ri22-1

10

a10=25Ri25-105

Ri=Ro410+25

Ro=Ri550-105

10

A10=52a1025+25

A10=54Ro210-25

A10=2Ri225-105

15.2.16 Circle

The circumference C and area A of a circle are given by:

C=πd=2πrA=πr2=14πd2

where the diameter d=2r.

An annulus is the area between two concentric circles as shown in Fig. 15.15, and its area A is given by:

A=πR2-r2=14πD2-d2

where D=2R and d=2r

Fig. 15.15

An annulus formed from two concentric circles

Figure 15.16 shows a sector of a circle, whose area is given by:

A=α∘360∘πr2

Fig. 15.16

A sector of a circle defined by the angle α

Figure 15.17 shows a segment of a circle, whose area is given by:

A=12r2(α-sinα),whereαisinradians

Fig. 15.17

A segment of a circle defined by the angle α

The area of an ellipse with major and minor radii a and b is:

A=πab

15.3 2D Analytic Geometry

In this section we briefly examine familiar descriptions of geometric elements and ways of computing intersections.

15.3.1 Equation of a Straight Line

The well-known equation of a straight line is:

y=mx+c

where m is the slope and c the intersection with the y-axis, as shown in Fig. 15.18. This is called the normal form.

Fig. 15.18

The normal form of the straight line is y=mx+c

Given two points (x1,y1) and (x2,y2) we can state that for any other point (x,y):

y-y1x-x1=y2-y1x2-x1

which yields:

y=(x-x1)y2-y1x2-x1+y1

Although these equations have their uses, the more general form is much more convenient:

ax+by+c=0

As we shall see, this equation possesses some interesting qualities.

Fig. 15.19

The orientation of a line can be controlled by a normal vector n and a distance d

15.3.2 The Hessian Normal Form

Figure 15.19 is the Hessian normal form of a straight line, and shows a line whose orientation is controlled by a normal unit vector n=[ab]T. If P(x,y) is any point on the line, then p is a position vector where p=[xy]T and d is the perpendicular distance from the origin to the line. Therefore:

d‖p‖=cosα

and

d=‖p‖cosα

But the dot product n·p is given by:

n·p=‖n‖‖p‖cosα=ax+by

which implies that:

ax+by=d‖n‖

and because ‖n‖=1 we can write:

ax+by-d=0

where (x,y) is a point on the line, a and b are the components of a unit vector normal to the line, and d is the perpendicular distance from the origin to the line. The distance d is positive when the normal vector points away from the origin, otherwise it is negative. For example, let’s find the equation of a line whose normal vector is [34]T and the perpendicular distance from the origin to the line is 1.

We begin by normalising the normal vector to its unit form. Therefore, if n=[34]T, ‖n‖=32+42=5, the equation of the line is:

35x+45y-1=0

Similarly, let’s find the Hessian normal form of y=2x+1. Rearranging the equation we get:

2x-y=-1

which gives a negative distance. If we want the normal vector to point away from the origin we multiply by -1:

-2x+y-1=0

Normalise the normal vector to a unit form:

i.e.(-2)2+12=5

-25x+15y-15=0

Therefore, the perpendicular distance from the origin to the line, and the unit normal vector are respectively:

15and-2515T

As the Hessian normal form involves a unit normal vector, we can incorporate the vector’s direction cosines within the equation:

xcosα+ysinα-d=0

where α is the angle between the normal vector and the x-axis.

Fig. 15.20

The Hessian normal form of the line equation partitions space into two zones

15.3.3 Space Partitioning

The Hessian normal form provides a very useful way of partitioning space into two zones: the partition that includes the normal vector, and the opposite partition. This is illustrated in Fig. 15.20.

Given the equation:

ax+by-d=0

a point (x,y) on the line satisfies the equation. But if the point (x,y) is in the partition in the direction of the normal vector, it creates the inequality:

ax+by-d>0

Conversely, if (x,y) is in the partition opposite to the direction of the normal vector creates the inequality:

ax+by-d<0

This space-partitioning feature of the Hessian normal form is useful in clipping lines against polygonal windows.

15.3.4 The Hessian Normal Form from Two Points

Given two points (x1,y1) and (x2,y2) we compute the values of a, b and d for the Hessian normal form from two points as follows.

The vector joining the two points is v=[ΔxΔy]T where:

Δx=x2-x1Δy=y2-y1‖v‖=Δx2+Δy2

The unit vector normal to v is n=[-Δy′Δx′]T, where:

Δx′=Δx‖v‖Δy′=Δy‖v‖

Therefore, let p=[xy]T be any point on the line, and using the Hessian Normal Form, we can write:

n·p=-Δy′x+Δx′y=-Δy′x1+Δx′y1

and

-Δy′x+Δx′y+(Δy′x1-Δx′y1)=0

(15.1)

For example, given the following points: (x1,y1)=(0,1) and (x2,y2)=(1,0); then Δx′=1/2 and Δy′=-1/2. Therefore, using (15.1):

x2+y2+0×-12-1×12=0x2+y2-12=0

15.4 Intersection Points

15.4.1 Intersecting Straight Lines

  Given two intersecting straight lines of the form:

a1x+b1y+d1=0a2x+b2y+d2=0

the intersection point (xi,yi) is given by:

xi=b1d2-b2d1a1b2-a2b1yi=d1a2-d2a1a1b2-a2b1

or using determinants:

xi=b1d1b2d2a1b1a2b2yi=d1a1d2a2a1b1a2b2

If the denominator is zero, the equations are linearly dependent, indicating that there is no intersection.

15.4.2 Intersecting Line Segments

We are often concerned with intersecting line segments in computer graphics as they represent the edges of shapes and objects. So let’s investigate how to compute the intersection of two 2D-line segments. Figure 15.21 shows two line segments defined by their end points P1, P2, P3, P4 and respective position vectors p1, p2, p3 and p4. We can write the following vector equations to identify the point of intersection:

pi=p1+t(p2-p1)

(15.2)

pi=p3+s(p4-p3)

(15.3)

Fig. 15.21

Two line segments with their associated position vectors

where parameters s and t vary between 0 and 1. For the point of intersection, we can write:

p1+t(p2-p1)=p3+s(p4-p3)

Therefore, the parameters s and t are given by:

s=(p1-p3)+t(p2-p1)p4-p3

(15.4)

t=(p3-p1)+s(p4-p3)p2-p1

(15.5)

From (15.5) we can write:

t=(x3-x1)+s(x4-x3)x2-x1t=(y3-y1)+s(y4-y3)y2-y1

which yields:

s=x1(y3-y2)+x2(y3-y1)+x3(y2-y1)(x2-x1)(y4-y3)-(x4-x3)(y2-y1)

(15.6)

Similarly:

t=x1(y4-y3)+x3(y1-y4)+x4(y3-y1)(x4-x3)(y2-y1)-(x2-x1)(y4-y3)

(15.7)

Let’s test (15.6) and (15.7) with two examples to illustrate how the equations are used in practice. The first example demonstrates an intersection condition, and the second demonstrates a touching condition.

Figure 15.22a shows two line segments intersecting, with an obvious intersection point of (1.5,0). The coordinates of the line segments are:

(x1,y1)=(1,0),(x2,y2)=(2,0)(x3,y3)=(1.5,-1),(x4,y4)=(1.5,1)

therefore:

t=1(1-(-1))+1.5(0-1)+1.5(-1-0)(0-0)(1.5-1.5)-(2-1)(1-(-1))=0.5

and

s=1(-1-0)+2(0-(-1))+1.5(0-0)(1-(-1))(2-1)-(1.5-1.5)(0-0)=0.5

Substituting s and t in (15.2) and (15.3) we get (xi,yi)=(1.5,0) as predicted.

Figure 15.22b shows two line segments touching at (1.5,0). The coordinates of the line segments are:

(x1,y1)=(1,0),(x2,y2)=(2,0)(x3,y3)=(1.5,0),(x4,y4)=(1.5,1)

therefore:

t=1(1-0)+1.5(0-1)+1.5(0-0)(0-0)(1.5-1.5)-(2-1)(1-0)=0.5

and

s=1(0-0)+2(0-0)+1.5(0-0)(1-0)(2-1)-(1.5-1.5)(0-0)=0

The zero value of s confirms that the lines touch, rather than intersect, and t=0.5 confirms that the touching takes place halfway along the line segment.

Fig. 15.22

a Shows two line segments intersecting b Shows two line segments touching

15.5 Point Inside a Triangle

We often require to test whether a point is inside a triangle, outside or touching. Let’s examine two ways of performing this operation. The first is related to finding the area of a triangle.

Fig. 15.23

The area of the triangle is computed by subtracting the smaller triangles from the rectangular area

15.5.1 Area of a Triangle

Let’s declare a triangle formed by the anti-clockwise points P1(x1,y1), P2(x2,y2) and P3(x3,y3) as shown in Fig. 15.23. The area of the triangle is given by:

A=(x2-x1)(y3-y1)-12(x2-x1)(y2-y1)-12(x2-x3)(y3-y2)-12(x3-x1)(y3-y1)

which simplifies to:

A=12[x1(y2-y3)+x2(y3-y1)+x3(y1-y2)]

and this can be further simplified to:

A=12x1y11x2y21x3y31

Figure 15.24 shows two triangles with opposing vertex sequences. If we calculate the area of the top triangle with anticlockwise vertices, we obtain:

A=12[1(2-4)+3(4-2)+2(2-2)]=2

whereas the area of the bottom triangle with clockwise vertices is:

A=12[1(2-0)+3(0-2)+2(2-2)]=-2

which shows that the technique is sensitive to vertex direction. We can exploit this sensitivity to test if a point is inside or outside a triangle.

Fig. 15.24

The top triangle has anti-clockwise vertices, and the bottom triangle clockwise vertices

Consider the scenario shown in Fig. 15.25, where the point Pt is inside the triangle (P1,P2,P3).

If all the above tests are positive, Pt is inside the triangle. Furthermore, if one area is zero and the other areas are positive, the point is on the boundary, and if two areas are zero and the other positive, the point is on a vertex.

Fig. 15.25

If the point Pt is inside the triangle, it is always to the left as the boundary is traversed in an anti-clockwise direction

Let’s now investigate how the Hessian normal form provides a similar function.

15.5.2 Hessian Normal Form

We can determine whether a point is inside, touching or outside a triangle by representing the triangle’s edges in the Hessian normal form, and testing in which partition the point is located. If we arrange that the normal vectors are pointing towards the inside of the triangle, any point inside the triangle will create a positive result when tested against the edge equation. In the following calculations there is no need to ensure that the normal vector is a unit vector, therefore (15.1) can be written:

-Δyx+Δxy+(Δyx1-Δxy1)=0

To illustrate this, consider the scenario shown in Fig. 15.26 where a triangle is formed by the points (1,1), (3,1) and (2,3). With reference to (15.1) we compute the three line equations.

The line between (1,1) and (3,1):

Δx=2Δy=0-0×x+2×y-2×1=02y-2=0

The line between (3,1) and (2,3):

Δx=-1Δy=2-2×x-1×y+(2×3+1×1)=0-2x-y+7=0

The line between (2,3) and (1,1):

Δx=-1Δy=-22×x-1×y+(-2×2-1×3)=02x-y-1=0

Thus the three line equations for the triangle are:

2y-2=0-2x-y+7=02x-y-1=0

We are only interested in the signs of the equations:

2y-2

(15.8)

-2x-y+7

(15.9)

2x-y-1

(15.10)

which can be tested for any arbitrary point (x,y). If they are all positive, the point is inside the triangle. If one expression is negative, the point is outside. If one expression is zero, the point is on an edge, and if two expressions are zero, the point is on a vertex.

Fig. 15.26

The triangle is represented by three line equations expressed in the Hessian normal form. Any point inside the triangle is found by evaluating their equations

Just as a quick test, consider the point (2,2). The three expressions (15.8) to (15.10) are positive, which confirms that the point is inside the triangle. The point (3,3) is obviously outside the triangle, which is confirmed by two positive results and one negative. Finally, the point (2,3), which is a vertex, creates one positive result and two zero results.

15.6 Intersection of a Circle with a Straight Line

The equation of a circle has already been given in the previous chapter, so we will now consider how to compute its intersection of a circle with a straight line. We begin by testing the equation of a circle with the normal form of the line equation:

x2+y2=r2andy=mx+c

By substituting the line equation in the circle’s equation we discover the two intersection points:

x1,2=-mc±r2(1+m2)-c21+m2

(15.11)

y1,2=c±mr2(1+m2)-c21+m2

(15.12)

Let’s test this result with the scenario shown in Fig. 15.27. Using the normal form of the line equation we have:

y=x+1,m=1,andc=1

Substituting these values in (15.11) and (15.12) yields:

x1,2=-1,0,y1,2=0,1

The actual points of intersection are (-1,0) and (0,1).

Fig. 15.27

The intersection of a circle with a straight line

Testing the equation of the circle with the general equation of the line ax+by+c=0 yields intersections given by:

x1,2=-ac±br2(a2+b2)-c2a2+b2

(15.13)

y1,2=-bc±ar2(a2+b2)-c2a2+b2

(15.14)

The general form of the line equation y=x+1 is:

x-y+1=0wherea=1,b=-1andc=1

Substituting these values in (15.13) and (15.14) yields:

x1,2=-1,0,andy1,2=0,1

which gives the same intersection points found above.

Finally, using the Hessian normal form of the line ax+by-d=0 yields intersections given by:

x1,2=ad±br2-d2

(15.15)

y1,2=bd±ar2-d2

(15.16)

The Hessian normal form of the line equation x-y+1=0 is:

-0.707x+0.707y-0.707≈0

where a≈-0.707,b≈0.707 and d≈0.707. Substituting these values in (15.15) and (15.16) yields:

x1,2=-1,0andy1,2=0,1

which gives the same intersection points found above. One can readily see the computational benefits of using the Hessian normal form over the other forms of equations.

15.7 3D Geometry

3D straight lines are best described using vector notation, and readers are urged to develop strong skills in these techniques if they wish to solve problems in 3D geometry. Let’s begin this short survey of 3D analytic geometry by describing the equation of a straight line.

Fig. 15.28

The line equation is based upon the point a and the vector b

15.7.1 Equation of a Straight Line

We start by using a vector b to define the orientation of the line, and a point a in space through which the line passes. This scenario is shown in Fig. 15.28. Given another point P on the line we can define a vector tb between a and P, where t is a scalar. The position vector p for P is given by:

p=a+tb

from which we can obtain the coordinates of the point P:

xp=xa+txbyp=ya+tybzp=za+tzb

For example, if b=[123]T and a=(2,3,4), then by setting t=1 we can identify a second point on the line:

xp=2+1=3yp=3+2=5zp=4+3=7

In fact, by using different values of t we can slide up and down the line with ease.

If we have two points P1 and P2, such as the vertices of an edge, we can represent the line equation using the above vector technique:

p=p1+t(p2-p1)

where p1 and p2 are position vectors to their respective points. Once more, we can write the coordinates of any point P as follows:

xp=x1+t(x2-x1)yp=y1+t(y2-y1)zp=z1+t(z2-z1)

15.7.2 Intersecting Two Straight Lines

Given two straight lines we can test for a point of intersection, but must be prepared for three results:

If the line equations are of the form:

p=a1+rb1p=a2+rb2

for an intersection we can write:

a1+rb1=a2+sb2

which yields:

xa1+rxb1=xa2+sxb2

(15.17)

ya1+ryb1=ya2+syb2

(15.18)

za1+rzb1=za2+szb2

(15.19)

We now have three equations in two unknowns, and any value of r and s must hold for all three equations. We begin by selecting two equations that are linearly independent (i.e. one equation is not a scalar multiple of the other) and solve for r and s, which must then satisfy the third equation. If this final substitution fails, then there is no intersection. If all three equations are linearly dependent, they describe two parallel lines, which can never intersect.

To check for linear dependency we rearrange (15.17) to (15.19) as follows:

rxb1-sxb2=xa2-xa1

(15.20)

ryb1-syb2=ya2-ya1

(15.21)

rzb1-szb2=za2-za1

(15.22)

If the determinant Δ of any pair of these equations is zero, then they are dependent. For example, (15.20) and (15.21) form the determinant:

Δ=xb1-xb2yb1-yb2

which, if zero, implies that the two equations can not yield a solution. As it is impossible to predict which pair of equations from (15.20) to (15.22) will be independent, let’s express two independent equations as follows:

ra11-sa12=b1ra21-sa22=b2

which yields:

r=a22b1-a12b2Δs=a21b1-a11b2Δ

where:

Δ=a11a12a21a22

Solving for r and s we obtain:

r=yb2(xa2-xa1)-xb2(ya2-ya1)xb1yb2-yb1xb2

(15.23)

s=yb1(xa2-xa1)-xb1(ya2-ya1)xb1yb2-yb1xb2

(15.24)

As a quick test, consider the intersection of the lines encoded by the following vectors:

a1=010,b1=333,a2=00.50,b2=232

Substituting the x- and y-components in (15.23) and (15.24) we discover:

r=13ands=12

but for these to be consistent, they must satisfy the z-component of the original equation:

rzb1-szb2=za2-za1

13×3-12×2=0

which is correct. Therefore, the point of intersection is given by either:

pi=a1+rb1,orpi=a2+sb2

Let’s try both, just to prove the point:

xi=0+133=1,xi=0+122=1yi=1+133=2,yi=12+123=2zi=0+133=1,zi=0+122=1

Therefore, the point of intersection point is (1,2,1):

Now let’s take two lines that don’t intersect, and also exhibit some linear dependency:

a1=010,b1=220,a2=020,b2=221

Taking the x- and y-components we discover that the determinant Δ is zero, which has identified the linear dependency. Taking the y- and z-components the determinant is non-zero, which permits us to compute r and s using:

r=zb2(ya2-ya1)-yb2(za2-za1)yb1zb2-zb1yb2s=zb1(ya2-ya1)-yb1(za2-za1)yb1zb2-zb1yb2r=1(2-1)-2(0-0)2×1-0×2=12s=0(2-1)-2(0-0)2×1-0×2=0

But these values of r and s must also apply to the x-components:

rxb1-sxb2=xa2-xa1

12×2-0×2≠0

which they clearly do not, therefore the lines do not intersect.

Now let’s proceed with the equation of a plane, and then look at how to compute the intersection of a line with a plane using a similar technique.

15.8 Equation of a Plane

We now consider four ways of representing an equation of a plane: the Cartesian form, general form, parametric form and a plane from three points.

15.8.1 Cartesian Form of the Plane Equation

One popular method of representing a plane equation is the Cartesian form, which employs a vector normal to the plane’s surface and a point on the plane. The equation is derived as follows.

Let n be a nonzero vector normal to the plane and P0(x0,y0,z0) a point on the plane. P(x,y,z) is any other point on the plane. Figure 15.29 illustrates the scenario. The normal vector is defined as:

n=ai+bj+ck

Fig. 15.29

The vector n is normal to the plane, which contains a point P0. P is any other point on the plane

and the position vectors for P0 and P are:

p0=x0i+y0j+z0kp=xi+yj+zk

respectively. From Fig. 15.29 we observe that:

q=p-p0

and as n is orthogonal to q:

n·q=0

therefore:

n·(p-p0)=0

which expands into:

n·p=n·p0

(15.25)

Writing (15.25) in its Cartesian form we obtain:

ax+by+cz=ax0+by0+cz0

but ax0+by0+cz0 is a scalar quantity associated with the plane and can be replaced by d. Therefore:

ax+by+cz=d

(15.26)

which is the Cartesian form of the plane equation.

The value of d has the following geometric interpretation.

In Fig. 15.29 the perpendicular distance from the origin to the plane is:

h=‖p0‖cosα

therefore:

n·p0=‖n‖‖p0‖cosα=h‖n‖

therefore, the plane equation is also expressed as:

ax+by+cz=h‖n‖

(15.27)

Dividing (15.27) by ‖n‖ we obtain:

a‖n‖x+b‖n‖y+c‖n‖z=h

where:

‖n‖=a2+b2+c2

This means that when a unit normal vector is used, h is the perpendicular distance from the origin to the plane. Let’s investigate this equation with an example.

Figure 15.30 shows a plane represented by the normal vector n=j+k and a point on the plane P0(0,1,0). Using (15.26) we have:

0x+1y+1z=0×0+1×1+1×0=1

therefore, the plane equation is:

y+z=1

If we normalise the equation to create a unit normal vector, we have:

y2+z2=12

where the perpendicular distance from the origin to the plane is 1/2.

Fig. 15.30

A plane represented by the normal vector n and a point P0(0,1,0)

15.8.2 General Form of the Plane Equation

The general form of the equation of a plane is expressed as:

Ax+By+Cz+D=0

which means that the Cartesian form is translated into the general form by making:

A=a,B=b,C=c,D=-d

15.8.3 Parametric Form of the Plane Equation

Another way is to represent a plane equation parametrically is to employ two vectors and a point that lie on the plane. Figure 15.31 illustrates a scenario where vectors a and b, and the point T(xt,yt,zt) lie on a plane. We now identify any other point on the plane P(xp,yp,zp) with its associated position vector p. The point T also has its associated position vector t.

Fig. 15.31

A plane is defined by the vectors a and b and the point T(xt,yt,zt)

Using vector addition we can write:

c=λa+ϵb

where λ and ϵ are two scalars such that c locates the point P. We can now write:

p=t+c

(15.28)

therefore:

xp=xt+λxa+ϵxbyp=yt+λya+ϵybzp=zt+λza+ϵzb

which means that the coordinates of any point on the plane are formed from the coordinates of the known point on the plane, and a linear mixture of the components of the two vectors. Let’s illustrate this vector approach with an example.

Fig. 15.32

The plane is defined by the vectors a and b and the point T(1,1,1)

Figure 15.32 shows a plane containing the vectors a=i and b=k, and the point T(1,1,1) with its position vector t=i+j+k . By inspection, the plane is parallel with the xz-plane and intersects the y-axis at y=1.

From (15.28) we can write:

p=t+λa+ϵb

where λ and ϵ are arbitrary scalars.

For example, if λ=2 and ϵ=1:

xp=1+2×1+1×0=3yp=1+2×0+1×0=1zp=1+2×0+1×1=2

Therefore, the point (3,1,2) is on the plane.

15.8.4 Converting from the Parametric to the General Form

It is possible to convert from the parametric form to the general form of the plane equation using the following formulae:

λ=(a·b)(b·t)-(a·t)‖b‖2‖a‖2‖b‖2-(a·b)2ϵ=(a·b)(a·t)-(b·t)‖a‖2‖a‖2‖b‖2-(a·b)2

The resulting point P(xp,yp,zp) is perpendicular to the origin.

If vectors a and b are unit vectors, λ and ϵ become:

λ=(a·b)(b·t)-a·t1-(a·b)2

(15.29)

ϵ=(a·b)(a·t)-b·t1-(a·b)2

(15.30)

P’s position vector p is also the plane’s normal vector. Therefore:

xp=xt+λxa+ϵxbyp=yt+λya+ϵybzp=zt+λza+ϵzb

The normal vector is:

p=xpi+ypj+zpk

and because ‖p‖ is the perpendicular distance from the plane to the origin we can state:

xp‖p‖x+yp‖p‖y+zp‖p‖z=‖p‖

or in the general form of the plane equation:

Ax+By+Cz+D=0

where:

A=xp‖p‖,B=yp‖p‖,C=zp‖p‖,D=-‖p‖

Fig. 15.33

The vectors a and b are parallel to the plane and the point (0,0,1) is on the plane

As an example, Fig. 15.33 shows a plane inclined 45∘ to the y- and z-axis and parallel with the x-axis. The vectors for the parametric equation are:

a=j-kb=it=k

Substituting these components in (15.29) and (15.30) we have:

λ=(0)(0)-(-1)×12×1-(0)=0.5ϵ=(0)(-1)-(0)×22×1-(0)=0

Therefore:

xp=0+0.5×0+0×1=0yp=0+0.5×1+0×0=0.5zp=1+0.5×(-1)+0×0=0.5

The point (0,0.5,0.5) has position vector p, where:

‖p‖=02+0.52+0.52=22

the plane equation is:

0x+0.52/2y+0.52/2z-2/2=0

which simplifies to:

y+z-1=0

15.8.5 Plane Equation from Three Points

Very often in computer graphics problems we need to find the plane equation from three points. To begin with, the three points must be distinct and not lie on a line. Figure 15.34 shows three points R, S and T, from which we create two vectors u=RS→ and v=RT→. The vector product u×v then provides a vector normal to the plane containing the original points. We now take another point P(x,y,z) and form a vector w=RP→. The scalar product w·(u×v)=0 if P is in the plane containing the original points. This condition can be expressed as a determinant and converted into the general equation of a plane. The three points are assumed to be in an anticlockwise sequence viewed from the direction of the surface normal.

Fig. 15.34

The vectors used to determine a plane equation from three points R,S and T

We begin with:

u×v=ijkxuyuzuxvyvzv

As w is perpendicular to u×v:

w·(u×v)=xwywzwxuyuzuxvyvzv=0

Expanding the determinant we obtain:

xwyuzuyvzv+ywzuxuzvxv+zwxuyuxvyv=0

which becomes:

(x-xR)yS-yRzS-zRyT-yRzT-zR+(y-yR)zS-zRxS-xRzT-zRxT-xR+(z-zR)xS-xRyS-yRxT-xRyT-yR=0

This can be arranged in the form ax+by+cz+d=0 where:

a=yS-yRzS-zRyT-yRzT-zR,b=zS-zRxS-xRxT-zRxT-xRc=xS-xRyS-yRxT-xRyT-yR,d=-(axR+byR+czR)

or

a=1yRzR1ySzS1yTzT,b=xR1zRxS1zSxT1zT,c=xRyR1xSyS1xTyT1d=-(axR+byR+czR)

As an example, consider the three points R(0,0,1),S(1,0,0),T(0,1,0). Therefore:

a=101100110=1,b=011110010=1,c=001101011=1d=-(1×0+1×0+1×1)=-1

and the plane equation is:

x+y+z-1=0

15.9 Intersecting Planes

When two non-parallel planes intersect, they form a straight line at the intersection, which is parallel to both planes. This line can be represented as a vector, whose direction is revealed by the vector product of the planes’ surface normals. However, we require a point on this line to establish a unique vector equation; a useful point is chosen as P0 , whose position vector p0 is perpendicular to the line.

Fig. 15.35

Two intersecting planes create a line of intersection

Figure 15.35 shows two planes with normal vectors n1 and n2 intersecting to create a line represented by n3, whilst P0(x0,y0,z0) is a particular point on n3 and P(x,y,z) is any point on the line.

We start the analysis by defining the surface normals:

n1=a1i+b1j+c1kn2=a2i+b2j+c2k

next we define p and p0:

p=xi+yj+zkp0=x0i+y0j+z0k

Now we state the plane equations in vector form:

n1·p+d1=0n2·p+d2=0

The geometric significance of the scalars d1 and d2 has already been described above. Let’s now define the line of intersection as:

p=p0+λn3

where λ is a scalar.

As the line of intersection must be orthogonal to n1 and n2:

n3=a3i+b3j+c3k=n1×n2

Now we introduce P0 as this must satisfy both plane equations, therefore:

n1·p0=-d1

(15.31)

n2·p0=-d2

(15.32)

and as P0 is such that p0 is orthogonal to n3:

n3·p0=0

(15.33)

Equations (15.31)–(15.33) form three simultaneous equations, which reveal the point P0. These are represented in matrix form as:

-d1-d20=a1b1c1a2b2c2a3b3c3x0y0z0

or

d1d20=-a1b1c1a2b2c2a3b3c3x0y0z0

therefore:

x0d1b1c1d2b2c20b3c3=y0a1d1c1a2d2c2a30c3=z0a1b1d1a2b2d2a3b30=-1DET

which enables us to state:

x0=d2b1c1b3c3-d1b2c2b3c3DETy0=d2a3c3a1c1-d1a3c3a2c2DET

z0=d2a1b1a3b3-d1a2b2a3b3DET

where:

DET=a1b1c1a2b2c2a3b3c3

The line of intersection is then given by:

p=p0+λn3

If DET=0 the line and plane are parallel.

Fig. 15.36

Two intersecting planes creating a line of intersection coincident with the y-axis

To illustrate this, let the two intersecting planes be the xy-plane and the yz-plane, which means that the line of intersection will be the y-axis, as shown in Fig. 15.36.

The plane equations are z=0 and x=0, therefore:

n1=kn2=i

and d1=d2=0.

We now compute n3, DET, x0, y0, z0:

n3=ijk001100=jDET=001100010=1x0=00110-000101=0y0=00001-000101=0z0=00001-010011=0

Therefore, the line equation is p=λn3, where n3=j, which is the y-axis.

Fig. 15.37

Three mutually intersecting planes

15.9.1 Intersection of Three Planes

Three mutually intersecting planes will intersect at a point as shown in Fig. 15.37, and we can find this point by using a similar strategy to the one used in two intersecting planes by creating three simultaneous plane equations using determinants.

Figure 15.37 shows the common point P(x,y,z) . The three planes can be defined by the following equations:

a1x+b1y+c1z+d1=0a2x+b1y+c2z+d2=0a3x+b1y+c3z+d3=0

which means that they can be rewritten as:

-d1-d2-d3=a1b1c1a2b2c2a3b3c3xyz

or

d1d2d3=-a1b1c1a2b2c2a3b3c3xyz

or in determinant form:

xd1b1c1d2b2c2d3b3c3=ya1d1c1a2d2c2a3d3c3=za1b1d1a2b2d2a3b3d3=-1DET

where:

DET=a1b1c1a2b2c2a3b3c3

Therefore, we can state that:

x=-d1b1c1d2b2c2d3b3c3DETy=-a1d1c1a2d2c2a3d3c3DETz=-a1b1d1a2b2d2a3b3d3DET

If DET=0, two of the planes at least, are parallel. Let’s test these equations with a simple example.

Fig. 15.38

Three planes intersecting at a point P

The planes shown in Fig. 15.38 have the following equations:

x+y+z-2=0z=0y-1=0

therefore:

DET=111001010=-1x=--211001-110-1=1y=-1-210010-10-1=1z=-11-200001-1-1=0

which means that the intersection point is (1,1,0), which is correct.

Fig. 15.39

The angle between two planes is the angle between their surface normals

15.9.2 Angle Between Two Planes

Calculating the angle between two planes is relatively easy and can be found by taking the dot product of the planes’ normals. Figure 15.39 shows two planes with α representing the angle between the two surface normals n1 and n2.

Let the plane equations be:

ax1+by1+cz1+d1=0ax2+by2+cz2+d2=0

therefore, their surface normals are:

n1=a1i+b1j+c1kn2=a2i+b2j+c2k

Taking the dot product of n1 and n2:

n1·n2=‖n1‖‖n2‖cosα

and

α=cos-1n1·n2‖n1‖‖n2‖

Fig. 15.40

α is the angle between two planes

For example, Fig. 15.40 shows two planes with normal vectors n1 and n2.

The plane equations are:

x+y+z-1=0z=0

therefore:

n1=i+j+kn2=k

therefore:

‖n1‖=3‖n2‖=1

and

α=cos-113≈54.74∘

15.9.3 Angle Between a Line and a Plane

The angle between a line and a plane is calculated using a similar technique used for calculating the angle between two planes. If the line equation employs a direction vector, the angle is determined by taking the dot product of this vector and between the plane’s normal. Figure 15.41 shows such a scenario where n is the plane’s surface normal and v is the line’s direction vector.

Fig. 15.41

α is the angle between the plane’s surface normal and the line’s direction vector

Let the plane equation be:

ax+by+cz+d=0

then its surface normal is:

n=ai+bj+ck

Let the line’s direction vector be v and T(xtyt,zt) is a point on the line, then any point on the line is given by the position vector p:

p=t+λv

therefore, we can write:

n·v=‖n‖‖v‖cosαα=cos-1n·v‖n‖‖v‖

When the line is parallel to the plane n·v=0.

Fig. 15.42

The required angle is between a and b

Consider the scenario illustrated in Fig. 15.42 where the plane equation is:

x+y+z-1=0

therefore, the surface normal is given by n:

n=i+j+k

and the line’s direction vector is a:

a=i+j

therefore:

‖n‖=3‖a‖=2

and

α=cos-126≈35.26∘

15.9.4 Intersection of a Line with a Plane

Given a line and a plane, they will either intersect, or not, if they are parallel. Either way, both conditions can be found using some simple vector analysis, as shown in Fig. 15.43. The objective is to identify a point P that is on the line and the plane.

Fig. 15.43

The vectors required to determine whether a line and plane intersect

Let the plane equation be:

ax+by+cz+d=0

where:

n=ai+bj+ck

P is a point on the plane with position vector:

p=xi+yj+zk

therefore:

n·p+d=0

Let the line equation be:

p=t+λv

where:

t=xti+ytj+ztk

and

v=xvi+yvj+zvk

therefore, the line and plane will intersect for some λ such that:

n·(t+λv)+d=n·t+λn·v+d=0

Therefore:

λ=-(n·t+d)n·v

for the intersection point. The position vector for P is p=t+λv.

If n·v=0 the line and plane are parallel.

Let’s test this result with the scenario shown in Fig. 15.44.

Fig. 15.44

P identifies the intersection point of the line and the plane

Given the plane:

x+y+z-1=0Xn=i+j+k

and the line:

p=t+λv

where:

t=0v=i+j

then:

λ=-(1×0+1×0+1×0-1)1×1+1×1+1×0=0.5

and the point of intersection is P(0.5,0.5,0).

15.10 Summary

Mixing vectors with geometry is a powerful analytical tool, and helps us solve many problems associated with computer graphics, encountered in rendering, modelling, collision detection and physically-based animation. Unfortunately, there has not been space to investigate every topic, but hopefully, what has been covered, will enable the reader solve other problems with greater confidence.

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_16

16. Statistics

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

16.1 Introduction

This chapter revises some statistical techniques and concepts, with which, the reader should be familiar. It covers data sets, frequency tables, stem and leaf diagrams, frequency histograms, scatter diagrams, mean, median, mode, range, variance, standard deviation, normal distribution, normal distribution tables, covariance, correlation, regression and the least squares fit. The chapter concludes with some worked examples.

16.2 What Is Statistics?

Statistics comprises a collection of mathematical techniques associated with data sets belonging to populations. Such populations may be complete or sampled, but in either case, we are interested in drawing a conclusion about the population, and if possible, knowing the degree of confidence associated with this conclusion. If a population is sampled, we must expect any conclusion to vary randomly from sample to sample.

16.3 Presentation of Data

The presentation of data depends upon the nature of the data. For example, the use of frequency tables, stem and leaf diagrams, frequency histograms, and scatter diagrams, are best used for particular types of data. These are described next, and are intended to complement the standard graphical techniques.

16.3.1 Data Sets

Before covering the ways of displaying data, a brief word about data sets. A data set is nothing more than a set of data, either the population itself, or a sample of the population. I will tend to employ set notation when defining a data set.

16.3.2 Frequency Table

A frequency table displays how many times a particular feature of a data set occurs. For example, say the weight (kg) of similar objects is recorded as follows:

W=105104100105105102103100105100102100104105103101102100102103104104

or using set notation:

W={105,104,100,105,105,102,103,100,105,100,102,100,104,105,103,101,102,100,102,103,104,104}

(16.1)

A frequency table of (16.1) is shown in Table 16.1, where each column records the number of times a particular number occurs.

Table 16.1

A frequency table of (16.1)

x

100

101

102

103

104

105

f

5

1

4

3

4

5

Table 16.2

A frequency table of (16.2)

x

30

40

50

60

70

80

f

1

5

10

14

6

4

Next, we consider another data set concerned with the mark out of 100, for a group of students studying computer science. The set S of marks are as follows:

S={57,80,72,56,70,50,49,83,81,69,56,63,62,41,44,59,56,64,73,69,55,64,60,44,72,70,69,66,61,62,83,68,59,68,71,66,39,45,53,55}

(16.2)

A frequency table of (16.2) is shown in Table 16.2. In both examples, the very nature of the table, hides a feature of the data.

16.3.3 Stem and Leaf Diagram

A stem and leaf diagram records 13 as two elements: stem | leaf, i.e. 1 | 3. Such a diagram of (16.1) is shown in Table 16.3. The diagram does not lend itself to the data set, and does not add anything to the frequency table.

Table 16.3

A stem and leaf diagram of (16.1)

10

0

0

0

0

0

10

1

10

2

2

2

2

10

3

3

3

10

4

4

4

4

10

5

5

5

5

5

A similar diagram of (16.2) is shown in Table 16.4, which is much more useful, perhaps because the data are sorted.

Table 16.4

A sorted stem and leaf diagram of (16.2)

3

9

4

1

4

4

5

9

5

0

3

5

5

6

6

6

7

9

9

6

0

1

2

2

3

4

4

6

6

8

8

9

9

9

7

0

0

1

2

2

3

8

0

1

3

3

16.3.4 Frequency Histogram

  A frequency histogram shows the data set as a histogram. Figure 16.1 shows a frequency histogram of (16.1), which for me, communicates the data set.

A frequency histogram can be drawn in different ways, and in each way would reflect the nature of the original set of data.

16.3.5 Scatter Diagram

A scatter diagram is a diagram linking an independent variable with a dependent variable. For example, Fig. 16.2 shows a scatter diagram where there is an approximate linear relationship between x and y.

16.4 Mean, Median, Mode and Range

The mean, median and mode generate a single number to represent a data set. This number attempts to show something about the data, which generally decides which one should be used.

Fig. 16.1

A frequency histogram of (16.1)

Fig. 16.2

A scatter diagram

16.4.1 Mean

There are two types of mean: population mean and sample mean. When using the data set for the entire population, we use the following formula:

μ=1N∑i=1Nxi

where N is the size of the population. The population mean of the 40 computer science students is:

μ=140∑i=140si=248440=62.1

which is in the row beginning with 6 in the sorted stem and leaf Table 16.4.

When presented with a sample of a data set taken from a population, we call it x¯ instead of μ:

x¯=1n∑i=1nxi

where:

xiisamemberofthedatasetdataset.nisthenumberofsampleelements.

The mean of the sample 3,4,-2,0,5,4 is calculated as follows:

x¯=3+4-2+0+5+46=146=2.3¯

Remember that ∑ is a ‘capital sigma’ and stands for the ‘the sum of’.

Using a frequency table, where the frequency of a particular number is referenced, as in Table 16.1, the population mean is evaluated as follows:

μ=5×100+101+4×102+3×103+4×104+5×1055+1+4+3+4+5=500+101+408+309+416+52522=225922≈102.68

16.4.2 Median

The median of a data set is the middle value separating the two equal data sets. Naturally, this is a particular value for an odd data set, but has to be halved for an even data set:

nisodd,median(n)=x(n+1)/2niseven,median(n)=x(n/2)+x((n/2)+1)2

For example, if n is 5, and the data is 6,7,8,10,12, the median is 8. Whereas, if n is 8, and the data are 2,4,7,8,12,16,20,22, the median is 8+122=10. Notice that before starting calculating the median, the data must be sorted.

16.4.3 Mode

 The mode of a data set identifies the most frequent value of the data set.

Figure 16.3 shows the mode, median and mean for an imaginary data set. Data may be such that there is no mode, or more than two.

Fig. 16.3

The difference between mode, median and mean

16.4.4 Range

The range of a data set X is given by:

R=xmax-xmin

For example, given the data set X={6,8,12,16,20}, where xmax=20 and xmin=6, and R=14.

16.5 Random Variable

A random variable is a quantity that cannot be defined with any certainty, and perhaps, is best defined using a probability distribution. Random variables can be divided into two groups: discrete and continuous, either possessing their own probability distribution. Discrete distributions arise from counting exercises. For example, in the recent Covid-19 epidemic, data was generally, made available every day showing the accumulated deaths on a country-wide basis. Such data is described as discrete as it was accrued by counting the number of people dying every day. Continuous distributions arise from experiments where something is monitored, like a smart gas or electricity meter, which displays the consumption of gas and electricity for a particular period. For the moment, we’ll only consider discrete random variables.

16.6 Variance

Let’s assume a discrete random variable X with values x1,x2,x3,⋯,xn. For X to take on a particular value is called the expected value or expectation of X, and equals the mean of X. It is written E[X], and defined as:

E[X]=1n∑i=1nxi=x1+x2+x3+⋯+xnn

where E[X]≡μ.

There are two ways of defining variance of a random variable X. The first is equal to the mean of the square of X minus the square of the mean of X. i.e.

Var(X)=E[X2]-E[X]2

(16.3)

Equation (16.3) is also written:

Var(X)=E[(X-E[X])2]

(16.4)

Equations (16.3) and (16.4) are shown to be equivalent as follows:

Var(X)=E[(X-E[X])2]=E[X2-2XE[X]+E[X]2]=E[X2]-2E[X]E[X]+E[X]2=E[X2]-E[X]2

For example, using (16.4) where X={30,36,42,40,44,48}. The expected mean of X is:

μ=16∑i=16xi=2406=40

Next, we compute x-μ and (x-μ)2 for each member of X in Table 16.5.

Table 16.5

A table showing x-μ and (x-μ)2 for each x

x

30

36

42

40

44

48

x-μ

−10

−4

2

0

4

8

(x-μ)2

100

16

4

0

16

64

The variance of X is:

Var(X)=16∑i=16(xi-μ)2=100+16+4+0+16+646=2006=33.3¯

Next, let’s show that using (16.3) gives the same result.

Table 16.6

A table showing x and x2

x

30

36

42

40

44

48

x2

900

1296

1764

1600

1936

2304

Table 16.6 shows x and x2. Taking the mean of X2 we have:

E[X2]=900+1296+1764+1600+1936+23046=1633.3¯E[X]2=μ2=402=1600E[X2]-E[X]2=1633.3¯-1600=33.3¯

which agrees with the value of variance computed with Var(X)=E[(X-E[X])2].

Variance is also known by S2, σ2 and V(X). σ is ‘lower-case sigma’.

The second definition of variance relies on the definition of standard deviation, and is defined as follows: the variance of the random variable X is the expected value of the squared deviation from the mean of X:

Var(X)=E[(X-E[X])2]

where E[X]=μ, which is Eq. (16.4).

16.6.1 Variance with a Probability Distribution

      To calculate the variance of a discrete random variable with a probability function, we incorporate the probability function with our definition of variance, and leave out the multiplication by 1/n:

Var(X)=∑i=1npi·(xi-μ)2

where pi is the probability function whose sum is 1, μ is the expected value for the mean of X, xi is a value of X, n is the number of values in X and p.

For example, let’s calculate the variance of the value of rolling a fair six-sided die. We know from our definition of the die that the probability function that:

p=16,16,16,16,16,16

and

μ=16∑(1+2+3+4+5+6)=216=72

therefore:

Var(X)=∑i=16pi·xi-722=16∑i=16xi-722=16-522+-322+-122+122+322+522=16254+94+14+14+94+254=16·704=2.916¯

The variance of rolling a true die is approximately 2.92 [1].

Let’s imagine that the die is faulty, and never shows a 3, but a 6 instead. How does this affect the variance?

To begin with, we must calculate a new expected value of X:

μ=16∑(1+2+6+4+5+6)=246=4

Next, we need a new probability function, one that reflects the untrue die:

p=16,16,0,16,16,26

therefore:

Var(X)=∑i=16pi·xi-42=16-32+16-22+012+1602+1612+2622=96+46+0+0+16+86=226=3.6¯

The variance of rolling a faulty die is approximately 3.67.

16.7 Standard Deviation

The standard deviation is a measure of the dispersion of the sampled data. A low standard deviation indicates that the data are close to the mean, whereas a high standard deviation indicates that the data are away from the mean. The standard deviation of a random variable X is given by:

σ=Var(X)

For the data set shown in Table 16.6 where X={30,36,42,40,44,48}, and the variance equals 33.3¯, the standard deviation is the square-root of 33.3¯, and equals approximately 5.77.

The standard deviation is written:

σ=1n∑i=1n(xi-μ)2

where μ is the expected mean of X, xi is a value in X and n is the number of values in the data set.

Note that the squaring operation used in computing the variance, ensures that it is always positive.

As an illustration of standard deviation, consider the data set X={1,4,5,4,1}, whose expected mean equals μ=3. The variance of X is computed using Table 16.7. The numbers in X have been chosen to make μ=3.

Table 16.7

A table showing x-μ and (x-μ)2 for each x

x

1

4

5

4

1

x-μ

−2

1

2

1

2

(x-μ)2

4

1

4

1

4

The standard deviation of X:

σ=15∑i=15(xi-μ)2=4+1+4+1+45≈1.67

the standard deviation of X is approximately 1.67.

Now let’s consider the data set Y={3,4.5,5,4.5,3}, whose expected mean equals μ=4. The values of Y have been chosen to make μ=4.

The variance of Y is computed using Table 16.8.

Table 16.8

A table showing y-μ and (y-μ)2 for each y

y

3

4.5

5

4.5

3

y-μ

−1

0.5

1

0.5

−1

(y-μ)2

1

0.25

1

0.25

1

The standard deviation of Y:

σ=15∑i=15(yi-μ)2=1+0.25+1+0.25+15≈0.8367

the standard deviation of Y is approximately 0.8367.

Thus a data set with values close to the mean, has a lower standard deviation.

Please note that the above examples form the complete population, and it is normal to divide by n, the number of data points. When the data are taken randomly from a complete population, one divides by n-1 to give what is called an unbiased estimate of the variance. Readers wishing to know more about this subject should investigate [2].

16.8 Normal Distribution

  A normal distribution is a mathematical function that shows the characteristics of some populations. A variety of ways exist to generate these curves, but the one we should know about is the Gaussian distribution [3]:

f(x)=1σ2πe-12x-μσ2

(16.5)

Equation (16.5) is known as a Gaussian distribution.

Fig. 16.4

A Gaussian function

The equation for the curve shown in Fig. 16.4 is (16.6) and is known as the standard normal distribution or unit normal distribution: 

φ(x)=e-x222π

(16.6)

which peaks at 0.4, and is ±1 standard deviation from the mean when ±x=1, and ±2 standard deviations from the mean when ±x=2, etc. It has a total area of 1, and is used to solve probability problems where it is assumed that the data are normally distributed. φ stands for ‘phi’, which is often written as ϕ.

Approximately 68% (2×34.1) of values drawn from a standard normal distribution are within ±1σ away from the mean; approximately 95% (2×47.7) of values are within ±2σ; and approximately 99.7% (2×49.8) of values are within ±3σ.

For example, a set of students studying computer science are normally distributed with a mean mark of 65% and a standard deviation of 10%. Let a group of students chosen randomly from the set. What is the probability of the group of students having a mark less than 55%, and greater than 85%?

Knowing that the set of students is normally distributed permits us to solve the problem. 55% is one standard deviation from the mean of 65%, which represents 34.1% of the data. As the total area of the standard normal distribution equals 1, there must be 15.9% beneath the first standard deviation, therefore the answer is 0.159. 85% is two standard deviations above the mean, there must be 2.3% above the first two standard deviations, therefore the answer is 0.023.

Let’s find for the same group of students the probability of exceeding 65% but less than 75%. 75% is one standard deviation above the mean, which covers 34.1% of the standard normal curve, therefore the answer is 0.341.

16.8.1 Normal Distribution Table

A Normal Distribution Table provides the area of the Standard Normal Distribution curve left of the central mean, for solving problems where fractional values of standard deviations [4].

Table 16.9 shows such a table, but only includes halves of standard deviations.

Table 16.9

A Standard Normal Distribution Table

Z

.00

.01

.02

.03

.04

.05

.06

.07

.08

.09

-3.5

.0002

.0002

.0002

.0002

.0002

.0002

.0002

.0002

.0002

.0002

-3.0

.0014

.0013

.0012

.0012

.0012

.0011

.0011

.0011

.0010

.0010

-2.5

.0062

.0060

.0059

.0057

.0055

.0054

.0052

.0051

.0049

.0048

-2.0

.0228

.0222

.0217

.0219

.0207

.0202

.0197

.0192

.0188

.0183

-1.5

.0668

.0655

.0643

.0630

.0618

.0606

.0594

.0582

.0571

.0559

-1.0

.1587

.1563

.1539

.1515

.1492

.1469

.1446

.1423

.1401

.1379

-0.5

.3085

.3050

.3015

.2981

.2946

.2912

.2877

.2843

.2810

.2776

-0.0

.5000

.4960

.4920

.4880

.4841

.4801

.4761

.4721

.4681

.4641

For example, a set of students studying computer science are normally distributed with a mean mark of 65% and a standard deviation of 10%. Let a group of students chosen randomly from the set. What is the probability of the student group has a mark less than 50%?

Knowing that the set of students is normally distributed permits us to solve the problem. 50% is 1.5 standard deviations from the mean of 65%, and looking up Table 16.9 shows that the entry for -1.5 is 0.0668. Therefore the answer is 0.0668.

16.9 Covariance and Correlation

16.9.1 Covariance

 Covariance in statistics is a measure of how much two random variables vary together, whereas variance measures how much a single variable varies. Figure 16.5 shows three types of covariance. A large negative covariance results when a small value in X corresponds with a high value in Y, and a high value in X corresponds with a small value in Y. This results in points having a negative slope. A large positive covariance results when a small value in X corresponds with a small value in Y, and a high value in X corresponds with a high value in Y. This results in points having a positive slope. A near zero covariance results when there is no correspondence between X and Y [5].

Fig. 16.5

Three types of covariance

Covariance is defined for discrete random variables by:

Cov(X,Y)=1n∑i=1n(xi-μX)(yi-μY)

where X and Y are the discrete random variables, μX is the expected mean of X, μY is the expected mean of Y, xi is a value in X, yi is a value in Y, and 1/n is the equal probability in xi or yi.

For example, to calculate the covariance of X={2,2.5,3.5,4} and Y={8,9,10,13}.

The expected mean of X is μX=3, and the expected mean of Y is μY=10.

Next, we compute x-μX and y-μY for each member of X and Y, in Table 16.10.

Table 16.10

A table used to calculate the covariance of X and Y

x

2

2.5

3.5

4

y

8

9

10

13

x-μX

−1

−0.5

0.5

1

y-μY

−2

−1

0

3

(x-μX)(y-μY)

2

0.5

0

3

Finally, we sum (x-μX)(y-μY) and divide by 4:

Cov(X,Y)=2+0.5+0+34=5.54=1.375

The covariance is positive, therefore X and Y are positively related, with a value of 1.375.

One should be careful computing covariance as its value is influenced by the axis units. For example, say we want to find the relationship between some goods and their prices. We could compute the covariance using pounds or pence, and get two different values.

16.9.2 Correlation

   Correlation determines whether two random variables are linearly related, and perhaps the most useful quantity is Pearson’s product-moment correlation coefficient (PPMCC), also called the correlation coefficient.

The English mathematician Karl Pearson (1857–1936), is credited with creating the discipline of mathematical statistics and the coefficient, which bears his name.

The population correlation coefficient ρX,Y between two random variables X and Y is defined as:

ρX,Y=Corr(X,Y)=Cov(X,Y)σXσY=E[(X-μX)(Y-μY)]σXσY,ifσXσY>0

where:

μXistheexpectedmeanofX.μYistheexpectedmeanofY.σXisthestandarddeviationofX.σYisthestandarddeviationofY.

Let’s find the correlation coefficient of X={2,2.5,3.5,4} and Y={8,9,10,13} in the previous example where Cov(X,Y)=1.375, and the expected mean for μX=3 and μY=10. Next, we must find the standard deviations σX and σY.

The standard deviation of X using Table 16.11 is calculated as follows:

σX=14∑i=14(xi-3)2=1+0.25+0.25+14≈0.79

Table 16.11

A table for calculating the standard deviation of X and Y

x

2

2.5

3.5

4

y

8

9

10

13

x-μX

−1

−0.5

0.5

1

(x-μX)2

1

0.25

0.25

1

y-μY

−2

−1

0

3

(y-μY)2

4

1

0

9

The standard deviation of Y using Table 16.11 is calculated as follows:

σY=14∑i=14(yi-10)2=4+1+0+94≈1.87

the standard deviation of X and Y is approximately 0.79 and 1.87 respectively.

Dividing 1.375 by σX=0.79 and σY=1.87 we have:

ρX,Y=1.3750.79×1.87≈0.93

therefore, the correlation coefficient ρX,Y≈0.93, which confirms that X and Y are related.

Let’s calculate the correlation coefficient for two random variables that are almost unrelated: X={1,2,3,4} and Y={4,0,3,1} using Table 16.12 as follows:

μX=104=2.5μY=84=2Cov(X,Y)=14∑i=14(xi-μX)(yi-μY)=-34=-0.75

Table 16.12

A table showing calculations for Cov(X, Y) and the standard deviation

x

1

2

3

4

y

4

0

3

1

x-μX

−1.5

−0.5

0.5

1.5

y-μY

2

−2

1

−1

(x-μX)(y-μY)

−3

1

0.5

−1.5

(x-μX)2

2.25

0.25

0.25

2.25

(y-μY)2

4

4

1

1

The standard deviation of X:

σX=14∑i=14(xi-μX)2=54≈1.12

the standard deviation of X is approximately 1.12.

The standard deviation of Y:

σY=14∑i=14(yi-μY)2=104≈1.58

the standard deviation of Y is approximately 1.58. Therefore, the correlation coefficient is:

-0.751.12×1.58≈-0.424

which is almost unrelated.

16.10 Regression

Regression analysis is a statistical technique where we attempt to discover the degree of association between two variables. For example, we may perform an experiment which generates values of a dependent variable from values of a set of independent variables. This results in a set of values that may have an underlying association that links the values together with a straight line, a quadratic curve, or a higher degree polynomial.

Simple regression analysis permits us to create a straight line equation, which, within reason, allows us to predict how the model behaves for different combination of values. Such an equation, creates a regression line linking the two variables y=f(x), where x is the independent variable, and y is the dependent variable. Consequently, the regression line represented by y=f(x) is known as a regression line of y on x.

16.10.1 Least Squares

Figure 16.6 shows points P1,P2 and Pn that are the result of some experiment. The object is to draw a straight line with equation y=mx+c, such that it minimises the square of the vertical lines between any two points Pn and Qn. Consequently, the technique is called the line of least squares. For example, the point Q1 has coordinates (x1,mx1+c), Q2 has coordinates (x2,mx2+c), and for any point Qn(xn,mxn+c). The distances of the lines joining any two points are:

y1-c-mx1,y2-c-mx2,y3-c-mx3,⋯,yn-c-mxn

The square of these distances is taken to ensure that they are always positive.

Fig. 16.6

A diagram for least squares

Partial differentiation is used to solve this problem, and those readers wishing to investigate this should look at [6]. For us, the solution to the least squares problem is:

(μx,μy)=(meanofx,meanofy)y=mx+cm=∑xyn-∑xn∑yn∑x2n-∑xn2m=Sxyσx2=Cov(X,Y)Var(X)a=μY-bμX

where y=mx+c is the straight line equation of the least squares, Cov(X,Y)/Var(X), and c=μY-mμX.

Table 16.13

A table for calculating Cov(X, Y) and Var(X)

x

1

3

5

7

y

0.5

3

2

4

x-μX

−3

−1

1

3

y-μY

−1.875

−0.625

0.375

1.625

(x-μX)(y-μY)

5.625

0.625

0.375

4.875

(x-μX)(x-μX)

9

1

1

9

Let’s test this with an example. Table 16.13 shows the relevant computations, there are 4 points with coordinates:

X={1,3,5,7}Y={0.5,3,2,4}μX=4μY=2.375Cov(X,Y)=5.625+0.625+0.375+4.8754=2.875Var(X)=9+1+1+94=5m=2.8755=0.575c=2.375-0.575×4=-0.075y=0.575x-0.075

Figure 16.7 shows the original 4 points, and the best fit equation, y=0.575x-0.075.

Fig. 16.7

A straight line through 4 points using least squares

The Worked Example reverses the y-coordinates. For a complete discussion on this algorithm refer to [7].

16.11 Summary

Statistics is a very large subject, and hopefully this short chapter has given you a flavour of the subject.

16.12 Worked Examples

16.12.1 Frequency Table

Use a frequency table to display X.

X={206,203,200,204,206,201,203,200,205,200,202,201,205,204,203,202,202,200,203,204,205,202}

Solution

Table 16.14 shows a frequency table of X.

Table 16.14

A frequency table of X

x

200

201

202

203

204

205

206

f

4

2

4

4

3

3

2

16.12.2 Stem and Leaf Diagram

Use a stem and leaf diagram to display a sorted Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

Sort Y:

Y′=(38,44,46,46,46,49,51,51,53,54,55,55,56,57,57,58,59,59,60,62,63,64,66,67,68,68,68,68,69,69,69,70,71,71,73,75,79,81,81,82)

Table 16.15 shows a sorted stem and leaf diagram of Y.

Table 16.15

A sorted stem and leaf diagram of Y

3

8

4

4

6

6

6

9

5

1

1

3

4

5

5

6

7

7

8

9

9

6

0

2

3

4

6

7

8

8

8

8

9

9

9

7

0

1

1

3

5

9

8

1

1

2

16.12.3 Frequency Histogram

Use a frequency histogram to display Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

Sort Y:

Y′=(38,44,46,46,46,49,51,51,53,54,55,55,56,57,57,58,59,59,60,62,63,64,66,67,68,68,68,68,69,69,69,70,71,71,73,75,79,81,81,82)

Figure 16.8 shows a frequency histogram of Y.

Fig. 16.8

A frequency histogram of Y

16.12.4 Mean

Calculate the mean of Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

μ=140∑i=140yi=242340=60.575

The mean of Y is approximately 60.58.

16.12.5 Median

Calculate the median of Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

Sort Y:

Y′=(38,44,46,46,46,49,51,51,53,54,55,55,56,57,57,58,59,59,60,62,63,64,66,67,68,68,68,68,69,69,69,70,71,71,73,75,79,81,81,82)

There are 40 numbers in Y, which is even. Therefore:

median(Y′)=y(20)′+y(21)′2=62+632=62.5

The median of Y is 62.5.

16.12.6 Mode

Calculate the mode of Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

Sort Y:

Y′=(38,44,46,46,46,49,51,51,53,54,55,55,56,57,57,58,59,59,60,62,63,64,66,67,68,68,68,68,69,69,69,70,71,71,73,75,79,81,81,82)

The mode of Y is 68.

16.12.7 Range

Calculate the range of Y.

Y={56,79,73,55,71,49,51,82,81,68,57,64,60,44,46,58,54,62,75,68,53,66,59,46,71,70,67,68,59,63,81,69,57,69,69,68,38,46,51,55}

Solution

Sort Y:

Y′=(38,44,46,46,46,49,51,51,53,54,55,55,56,57,57,58,59,59,60,62,63,64,66,67,68,68,68,68,69,69,69,70,71,71,73,75,79,81,81,82)

The range of Y is 82-38=44.

16.12.8 Variance

Calculate the variance of X.

X={50,55,56,71,73,79}

Solution

μ=16∑i=16xi=3846=64

The mean of X is 64.

Table 16.16

A table showing the calculations for variance

x

50

55

56

71

73

79

x-μ

−14

−9

−8

7

11

15

(x-μ)2

196

81

64

49

121

225

Next, we compute x-μ and (x-μ)2 for each member of X in Table 16.16.

The variance of X is:

Var(X)=16∑i=16(xi-μ)2=196+81+64+49+121+2256=7366=122.6¯

The variance of X is approximately 122.67.

16.12.9 Standard Deviation

Calculate the standard deviation of X.

X={52,55,56,58,61,66}

Solution

μ=16∑i=16xi=3486=58

The expected mean of X is 58.

Next, we compute x-μ and (x-μ)2 for each member of X in Table 16.17.

Var(X)=16∑i=16(xi-μ)2=36+9+4+0+9+646=1226=20.3¯

Table 16.17

A table showing the calculations for standard deviation

x

52

55

56

58

61

66

x-μ

−6

−3

−2

0

3

8

(x-μ)2

36

9

4

0

9

64

The variance of X is 20.3¯, and the standard deviation is approximately 4.51.

16.12.10 Normal Distribution

A set of students studying maths are normally distributed with a mean mark of 60% and a standard deviation of 10%. Let a group of students chosen randomly from the set. What is the probability of the group of students having a mark less than 50%, and greater than 80%?

Solution

50% is one standard deviation from the mean of 60%, which represents 34.1% of the data. As the total area of the standard normal distribution equals 1, there must be 15.9% beneath the first standard deviation, therefore the answer is 0.159. 80% is two standard deviations above the mean, there must be 2.3% above the first two standard deviations, therefore the answer is 0.023.

16.12.11 Normal Distribution Table

A set of students studying maths are normally distributed with a mean mark of 60% and a standard deviation of 10%. Let a group of students chosen randomly from the set. What is the probability of the group of students having a mark less than 55%?

Solution

55% is one-half standard deviation from the mean of 60%, and looking up Table 16.9 shows that the entry for -0.5 is 0.3085. Therefore the answer is 0.3085.

16.12.12 Covariance

Calculate the covariance of A={2,2.5,3.5,4} and B={13,10,9,8}.

Solution

μA=3, and μB=10. Next, we compute a-μA and b-μB for each member of A and B, in Table 16.18.

Table 16.18

A table showing the calculations for covariance

a

2

2.5

3.5

4

b

13

10

9

8

a-μA

−1

−0.5

0.5

1

b-μB

3

0

−1

−2

(a-μA)(b-μB)

−3

0

−0.5

−2

Finally, we sum (a-μA)(b-μB) and divide by 4:

Cov(A,B)=-3-0-0.5-24=-5.54=-1.375

The covariance is negative, therefore A and B are negatively related, with a value of approximately -1.375.

16.12.13 Correlation Coefficient

Calculate the correlation coefficient for two random variables: X={10,2,8,4} and Y={4,10,3,7}.

Solution

Using Table 16.19 as follows:

μX=244=6μY=244=6Cov(X,Y)=14∑i=14(xi-μX)(yi-μY)=-324=-8

Table 16.19

A table showing calculations for Cov(X, Y) and the standard deviation

x

10

2

8

4

y

4

10

3

7

x-μX

4

−4

2

−2

y-μY

−2

4

−3

1

(x-μX)(y-μY)

−8

−16

−6

−2

(x-μX)2

16

16

4

4

(y-μY)2

4

16

9

1

The standard deviation of X:

σX=14∑i=14(xi-μX)2=404≈3.16

The standard deviation of X is approximately 3.16.

The standard deviation of Y:

σY=14∑i=14(yi-μY)2=304≈2.74

The standard deviation of Y is approximately 2.74. Therefore, the correlation coefficient is:

-83.16×2.74≈-0.924

The correlation coefficient is approximately -0.924.

16.12.14 Least Squares

Calculate the equation of a straight line the passes through the points stored in X and Y using the least squares algorithm.

X={1,3,5,7}Y={4,2,3,0.5}

Solution

Table 16.20 contains the relevant calculations.

μX=4μY=2.375Cov(X,Y)=-4.875-0.375-0.625-5.6254=-2.875Var(X)=9+1+1+94=5m=-2.8755=-0.575c=2.375+0.575×4=4.675y=-0.575x+4.675

Figure 16.9 shows the original 4 points, and the best fit equation, y=-0.575x+4.675.

Table 16.20

Calculations for the covariance and variance of X and Y

x

1

3

5

7

y

4

2

3

0.5

x-μX

−3

−1

1

3

y-μY

1.625

0.375

−0.625

−1.875

(x-μX)(y-μY)

−4.875

−0.375

−0.625

−5.625

(x-μX)(x-μX)

9

1

1

9

Fig. 16.9

A straight line through 4 points using least squares

References

1.

https://​en.​wikipedia.​org/​wiki/​Variance

2.

https://​en.​wikipedia.​org/​wiki/​Standard_​deviation

3.

https://​en.​wikipedia.​org/​wiki/​Normal_​distribution

4.

https://​www.​math.​arizona.​edu/​jwatkins/​normal-table.​pdf

5.

https://​www.​statisticshowto.​com/​probability-and-statistics/​statistics-definitions/​covariance/​

6.

https://​en.​wikipedia.​org/​wiki/​Least_​squares

7.

https://​www.​ncl.​ac.​uk/​webtemplate/​ask-assets/​external/​maths-resources/​images/​Regression_​and_​Correlation.​pdf

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_17

17. Barycentric Coordinates

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

17.1 Introduction

Cartesian coordinates  are a fundamental concept in mathematics and are central to computer graphics. Such rectangular coordinates are just offsets relative to some origin. Other coordinate systems also exist such as polar, spherical and cylindrical coordinates, and they too, require an origin. Barycentric coordinates, on the other hand, locate points relative to existing points, rather than to an origin and are known as local coordinates.

17.2 Background

The German mathematician August Möbius is credited with their discovery. ‘barus’ is the Greek entomological root for ‘heavy’, and barycentric coordinates were originally used for identifying the centre of mass of shapes and objects. It is interesting to note that the prefixes ‘bari’, ‘bary’ and ‘baro’ have also influenced other words such as baritone, baryon (heavy atomic particle) and barometer.

Although barycentric coordinates are used in geometry, computer graphics, relativity and global time systems, they do not appear to be a major topic in a typical math syllabus. Nevertheless, they are important and I would like to describe what they are and how they can be used in computer graphics.

The idea behind barycentric coordinates can be approached from different directions, and I have chosen mass points and linear interpolation. But before we begin this analysis, it will be useful to investigate a rather elegant theorem known as Ceva’s Theorem, which we will invoke later in this chapter.

17.3 Ceva’s Theorem

   The Italian mathematician Giovanni Ceva (1647–1734) is credited with a theorem associated with the concurrency of lines in a triangle. It states that: In a triangle ΔABC, the lines AA′, BB′ and CC′, where A′, B′ and C′ are points on the opposite sides facing vertices A, B and C respectively, are concurrent (intersect at a common point) if, and only if:

AC′C′B·BA′A′C·CB′B′A=1

Figure 17.1 shows such a scenario.

Fig. 17.1

The geometry associated with Ceva’s Theorem

There are various ways of proving this theorem, and Alfred Posamentier provides one [1]; but perhaps the simplest proof is as follows.

Fig. 17.2

The geometry for proving Ceva’s Theorem

Figure 17.2 shows triangle ΔABC with line AA′ extended to R and BB′ extended to S, where line SR is parallel to line AB. The resulting geometry creates a number of similar triangles:

ΔABA′:ΔRCA′⇒A′CBA′=CRAB

(17.1)

ΔABB′:ΔCSB′⇒B′ACB′=ABSC

(17.2)

ΔBPC′:ΔCSP⇒C′BSC=C′PPC

(17.3)

ΔAC′P:ΔRCP⇒AC′CR=C′PPC

(17.4)

From (17.3) and (17.4) we get:

C′BSC=AC′CR

which can be rewritten as:

C′BAC′=SCCR

(17.5)

The product of (17.1), (17.2) and (17.5) is:

A′CBA′·B′ACB′·C′BAC′=CRAB·ABSC·SCCR=1

(17.6)

Rearranging the terms of (17.6) we get:

AC′C′B·BA′A′C·CB′B′A=1

which is rather an elegant relationship.

17.4 Ratios and Proportion

Central to barycentric coordinates are ratios and proportion, so let’s begin by revising some fundamental formulae used in calculating ratios.

Imagine the problem of dividing £100 between two people in the ratio 2 : 3. The solution lies in the fact that the money is divided into 5 parts (2+3), where 2 parts go to one person and 3 parts to the other person. In this case, one person receives £40 and the other £60. At a formal level, we can describe this as follows.

A scalar A can be divided into the ratio r : s using the following expressions:

rr+sAandsr+sA

Note that:

rr+s+sr+s=1

and

1-rr+s=sr+s

Furthermore, the above formulae can be extended to incorporate any number of ratio divisions. For example, A can be divided into the ratio r : s : t by the following:

rr+s+tA,sr+s+tAandtr+s+tA

similarly:

rr+s+t+sr+s+t+tr+s+t=1

These expressions are very important as they show the emergence of barycentric coordinates. For the moment though, just remember their structure and we will investigate some ideas associated with balancing weights.

Fig. 17.3

Two masses fixed at the ends of a massless rod

Fig. 17.4

The geometry used for equating turning moments

17.5 Barycentric Coordinates

We begin by calculating the centre of mass—the centroid—of two masses. Consider the scenario shown in Fig. 17.3 where two masses mA and mB are placed at the ends of a massless rod.

If mA=mB a state of equilibrium is achieved by placing the fulcrum mid-way between the masses. If the fulcrum is moved towards mA, mass mB will have a turning advantage and the rod rotates clockwise.

To calculate a state of equilibrium for a general system of masses, consider the geometry illustrated in Fig. 17.4, where two masses mA and mB are positioned xA and xB at A and B respectively. When the system is in balance we can replace the two masses by a single mass mA+mB at the centroid denoted by x¯ (pronounced ‘x bar’).

A balance condition arises when the LHS turning moment equals the RHS turning moment. The turning moment being the product of a mass by its offset from the fulcrum. Equating turning moments, equilibrium is reached when:

mB(xB-x¯)=mA(x¯-xA)mBxB-mBx¯=mAx¯-mAxA(mA+mB)x¯=mAxA+mBxB

x¯=mAxA+mBxBmA+mB=mAmA+mBxA+mBmA+mBxB

(17.7)

For example, if mA=6 and mB=12, and positioned at xA=0 and xB=12 respectively, the centroid is located at:

x¯=618×0+1218×12=8

Thus we can replace the two masses by a single mass of 18 located at x¯=8.

Note that the terms in (17.7) mA/(mA+mB) and mB/(mA+mB) sum to 1 and are identical to those used above for calculating ratios. They are also called the barycentric coordinates of x¯ relative to the points A and B.

Using the general form of (17.7) any number of masses can be analysed using:

x¯=∑i=1nmixi∑i=1nmi

where mi is a mass located at xi. Furthermore, we can compute the y-component of the centroid y¯ using:

y¯=∑i=1nmiyi∑i=1nmi

and in 3D the z-component of the centroid z¯ is:

z¯=∑i=1nmizi∑i=1nmi

To recap, (17.7) states that:

x¯=mAmA+mBxA+mBmA+mBxB

therefore, we can write:

y¯=mAmA+mByA+mBmA+mByB

which allows us to state:

P¯=mAmA+mBA+mBmA+mBB

where A and B are the position vectors for the mass locations A and B respectively, and P¯ is the position vector for the centroid P¯.

If we extend the number of masses to three: mA, mB and mC, which are organised as a triangle, then we can write:

P¯=mAmA+mB+mCA+mBmA+mB+mCB+mCmA+mB+mCC

(17.8)

The three multipliers of A, B and C are the barycentric coordinates of P¯ relative to the points A, B and C. Note that the number of coordinates is not associated with the number of spatial dimensions, but the number of reference points.

Fig. 17.5

The geometry used for equating turning moments

Now consider the scenario shown in Fig. 17.5. If mA=mB=mC then we can determine the location of A′, B′ and C′ as follows:

1.

We begin by placing a fulcrum under A mid-way along BC as shown in Fig. 17.6.

The triangle will balance because mB=mC and A′ is 12a from C and 12a from B.

2.

Now we place the fulcrum under B mid-way along CA as shown in Fig. 17.7.

Once more the triangle will balance, because mC=mA and B′ is 12b from C and 12b from A.

3.

Finally, we do the same for C and AB. Figure 17.8 shows the final scenario.

Fig. 17.6

Balancing the triangle along AA′

Fig. 17.7

Balancing the triangle along BB′

Fig. 17.8

P¯ is the centroid of the triangle

Ceva’s Theorem confirms that the medians AA′, BB′ and CC′ are concurrent at P¯ because:

AC′C′B·BA′A′C·CB′B′A=12c12c·12a12a·12b12b=1

Arbitrarily, we select the median C′C. At C′ we have an effective mass of mA+mB and mC at C. For a balance condition:

(mA+mB)×C′P¯=mC×P¯C

and as the masses are equal, C′P¯ must be 13 along the median C′C.

If we use (17.8) we obtain:

P¯=13A+13B+13C

which locates the coordinates of the centroid correctly.

Fig. 17.9

How the masses determine the positions of A′, B′ and C′

Fig. 17.10

How the masses determine the positions of A′, B′ and C′

Now let’s consider another example where mA=1, mB=2 and mC=3, as shown in Fig. 17.9. For a balance condition A′ must be 35a from B and 25a from C. Equally, B′ must be 14b from C and 34b from A. Similarly, C′ must be 23c from A and 13c from B.

Ceva’s Theorem confirms that the lines AA′, BB′ and CC′ are concurrent at P¯ because:

AC′C′B·BA′A′C·CB′B′A=23c13c·35a25a·14b34b=1

Arbitrarily select C′C. At C′ we have an effective mass of 3 (1+2) and 3 at C, which means that for a balance condition P¯ is mid-way along C′C. Similarly, P¯ is 16 along A′A and 13 along B′B.

Once more, using (17.8) in this scenario we obtain:

P¯=16A+13B+12C

Note that the multipliers of A, B and C are identical to the proportions of P¯ along A′A, B′B and C′C. Let’s prove why this is so.

Figure 17.10 shows three masses with the triangle’s sides divided into their various proportions to derive P¯.

On the line A′A we have mA at A and effectively mB+mC at A′, which means that P¯ divides A′A in the ratio mA/(mA+mB+mC):(mB+mC)/(mA+mB+mC).

On the line B′B we have mB at B and effectively mA+mC at B′, which means that P¯ divides B′B in the ratio mB/(mA+mB+mC):(mA+mC)/(mA+mB+mC).

Similarly, on the line C′C we have mC at C and effectively mA+mB at C′, which means that P¯ divides C′C in the ratio mC/(mA+mB+mC):(mA+mB)/(mA+mB+mC).

To summarise, given three masses mA, mB and mC located at A, B and C respectively, the centroid P¯ is given by:

P¯=mAmA+mB+mCA+mBmA+mB+mCB+mCmA+mB+mCC

(17.9)

If we accept that mA, mB and mC can have any value, including zero, then the barycentric coordinates of P¯ will be affected by these values. For example, if mB=mC=0 and mA=1, then P¯ will be located at A with barycentric coordinates (1,0,0). Similarly, if mA=mC=0 and mB=1, then P¯ will be located at B with barycentric coordinates (0,1,0). And if mA=mB=0 and mC=1, then P¯ will be located at C with barycentric coordinates (0,0,1).

Fig. 17.11

Three masses can be represented by a single mass located at the centroid

Now let’s examine a 3D example as illustrated in Fig. 17.11. The figure shows three masses 4, 8 and 12 and their equivalent mass 24 located at (x¯,y¯,z¯).

Table 17.1

The magnitude and coordinates of three masses

mi

ti

xi

yi

zi

tixi

tiyi

tizi

12

12

8

6

2

4

3

1

8

13

2

3

3

23

1

1

4

16

2

6

6

13

1

1

x¯=5

y¯=5

z¯=3

The magnitude and coordinates of three masses are shown in Table 17.1, together with the barycentric coordinate ti. The column headed ti expresses the masses as fractions of the total mass: i.e.:

ti=mim1+m2+m3

and we see that the centroid is located at (5,5,3).

Having discovered barycentric coordinates in weight balancing, let’s see how they emerge in linear interpolation.

17.6 Linear Interpolation

Suppose that we wish to find a value mid-way between two scalars A and B. We could proceed as follows:

V=A+12(B-A)=12A+12B

which seems rather obvious. Similarly, to find a value one-third between A and B, we can write:

V=A+13(B-A)=23A+13B

Generalising, to find some fraction t between A and B we can write:

V=(1-t)A+tB

(17.10)

For example, to find a value 34 between 10 and 18 we have:

V=1-34×10+34×18=16

Although this is a trivial formula, it is very useful when interpolating between two numerical values. Let us explore (17.10) in greater detail.

To begin with, it is worth noting that the multipliers of A and B sum to 1:

(1-t)+t=1

Rather than using (1-t) as a multiplier, it is convenient to make a substitution such as s=1-t , and we have:

V=sA+tB

where:

s=1-t

and

s+t=1

Equation (17.10) is called a linear interpolant as it linearly interpolates between A and B using the parameter t. It is also known as a lerp. The terms s and t are the barycentric coordinates of V as they determine the value of V relative to A and B.

Now let’s see what happens when we substitute coordinates for scalars. We start with 2D coordinates A(xA,yA) and B(xB,yB), and position vectors A, B and C and the following linear interpolant:

V=sA+tB

where:

s=1-t

and

s+t=1

then:

xV=sxA+txByV=syA+tyB

Fig. 17.12

The position of V slides between A and B as t varies between 0 and 1

Figure 17.12 illustrates what happens when t varies between 0 and 1.

The point V slides along the line connecting A and B. When t=0, V is coincident with A, and when t=1, V is coincident with B. You should not be surprised that the same technique works in 3D.

Now let’s extend the number of vertices to three in the form of a triangle as shown in Fig. 17.13. This time we will use r, s and t to control the interpolation. We would start as follows:

V=rA+sB+tC

where A, B and C are the position vectors for A, B and C respectively, and V is the position vector for the point V.

Fig. 17.13

The position of V moves between A, B and C depending on the value r, s and t

Let:

r=1-s-t

and

r+s+t=1

Once more, we begin with 2D coordinates A(xA,yA), B(xB,yB) and C(xC,yC) where:

xV=rxA+sxB+txCyV=ryA+syB+tyC

When:

r=1,ViscoincidentwithAs=1,ViscoincidentwithBt=1,ViscoincidentwithC

Similarly, when:

r=0,VislocatedontheedgeBCs=0,VislocatedontheedgeCAt=0,VislocatedontheedgeAB

For all other values of r, s and t, where r+s+t=1 and 0≤r,s,t≤1, V is inside triangle ΔABC , otherwise it is outside the triangle.

The triple (r,s,t) are barycentric coordinates and locate points relative to A, B and C, rather than an origin. For example, the barycentric coordinates of A, B and C are (1,0,0), (0,1,0) and (0,0,1) respectively.

All of the above formulae work equally well in three dimensions, so let’s investigate how barycentric coordinates can locate points inside a 3D triangle. However, before we start, let’s clarify what we mean by inside a triangle. Fortunately, barycentric coordinates can distinguish points within the triangle’s three sides; points coincident with the sides; and points outside the triangle’s boundary. The range and value of the barycentric coordinates provide the mechanism for detecting these three conditions.

Fig. 17.14

A 3D triangle

As an example, Fig. 17.14 illustrates a scenario with the points P1(x1,y1,z1), P2(x2,y2,z2) and P3(x3,y3,z3). Using barycentric coordinates we can state that any point P0(x0,y0,z0) inside or on the edge of triangle ΔP1P2P3 is defined by

x0=rx1+sx2+tx3y0=ry1+sy2+ty3z0=rz1+sx2+tz3

where r+s+t=1 and 0≤r,s,t,≤1.

If the triangle’s vertices are P1(0,2,0), P2(0,0,4) and P3(3,1,2) then we can choose different values of r, s and t to locate P0 inside the triangle. However, I would also like to confirm that P0 lies on the plane containing the three points. To do this we require the plane equation for the three points, which can be derived as follows.

Given P1(x1,y1,z1), P2(x2,y2,z2) and P3(x3,y3,z3), and the target plane equation ax+by+cz+d=0, then:

a=1y1z11y2z21y3z3b=x11z1x21z2x31z3c=x1y11x2y21x3z21d=-(ax1+by1+cz1)

thus:

a=120104112=0b=010014312=12c=021001311=6d=-24

therefore, the plane equation is:

12y+6z=24

(17.11)

If we substitute a point (x0,y0,z0) in the LHS of (17.11) and obtain a value of 24, then the point is on the plane.

Table 17.2 shows various values of r, s and t, and the corresponding position of P0. The table also confirms that P0 is always on the plane containing the three points.

Table 17.2

The barycentric coordinates of P0

r

s

t

x0

y0

z0

12y0+6z0

1

0

0

0

2

0

24

0

1

0

0

0

4

24

0

0

1

3

1

2

24

14

14

12

112

1

2

24

0

12

12

112

12

3

24

12

12

0

0

1

2

24

13

13

13

1

1

2

24

Now we are in a position to test whether a point is inside, on the boundary or outside a 3D triangle.

We begin by writing the three simultaneous equations defining P0 in matrix form:

x0y0z0=x1x2x3y1y2y3z1z2z3rst

therefore:

rx0x2x3y0y2y3z0z2z3=sx1x0x3y1y0y3z1z0z3=tx1x2x0y1y2y0z1z2z0=1x1x2x3y1y2y3z1z2z3

and

r=x0x2x3y0y2y3z0z2z3DETs=x1x0x3y1y0y3z1z0z3DETt=x1x2x0y1y2y0z1z2z0DETDET=x1x2x3y1y2y3z1z2z3

Using the three points P1(0,2,0), P2(0,0,4), P3(3,1,2) and arbitrary positions of P0, the values of r, s and t identify whether P0 is inside or outside triangle ΔABC. For example, the point P0(0,2,0) is a vertex and is classified as being on the boundary. To confirm this we calculate r, s and t, and show that r+s+t=1:

DET=003201042=24r=00320104224=1s=00322100224=0t=00020204024=0

therefore r+s+t=1, but both s and t are zero which confirms that the point (0,2,0) is on the boundary. In fact, as both coordinates are zero it confirms that the point is located on a vertex.

Now let’s deliberately choose a point outside the triangle. For example, P0(4,0,3) is outside the triangle, which is confirmed by the corresponding values of r, s and t:

r=40300134224=-23s=04320103224=34t=00420004324=43

therefore:

r+s+t=-23+34+43=1512

which confirms that the point (4,0,3) is outside the triangle. Note that r<0 and t>1 , which individually confirm that the point is outside the triangle’s boundary.

Fig. 17.15

A concave polygon

17.7 Convex Hull Property

We have already shown that it is possible to determine whether a point is inside or outside a triangle. But remember that triangles are always convex. So can we test whether a point is inside or outside any polygon? Well the answer is no, unless the polygon is convex. The reason for this can be understood by considering the concave polygon shown in Fig. 17.15.

Let the barycentric coordinates for a point P0 be:

P0=rA+sB+tC+uD

where r+s+t+u=1. When t=0, P0 can exist anywhere inside triangle ΔABD. Thus, if any vertex creates a concavity, it will be ignored by barycentric coordinates.

17.8 Areas

Barycentric coordinates are also known as areal coordinates due to their area dividing properties. For example, in Fig. 17.16 the areas of the three internal triangles are in proportion to the barycentric coordinates of the point P.

To prove this, let P have barycentric coordinates:

P=rA+sB+tC

where:

r+s+t=1,and0≤(r,s,t)≤1

Fig. 17.16

The areas of the internal triangles are directly proportional to the barycentric coordinates of P

If we use the notation area(ΔABC) to represent the area of the triangle formed from the vertices A, B and C then area(ΔABC) is the sum of the areas of the smaller triangles:

area(ΔABC)=area(ΔABP)+area(ΔBCP)+area(ΔCAP)

But the area of any 2D triangle ΔP1P2P3 is:

area(ΔP1P2P3)=12x1y11x2y21x3y31

therefore:

area(ΔABP)=12xAyA1xByB1xPyP1

but:

xP=rxA+sxB+txC

and

yP=ryA+syB+tyC

therefore:

area(ΔABP)=12xAyA1xByB1rxA+sxB+txCryA+syB+tyC1

which expands to:

and simplifies to:

area(ΔABP)=12txAyA1xByB1xCyC1=t×area(ΔABC)

therefore:

t=area(ΔABP)area(ΔABC)

similarly:

area(ΔBCP)=12rxAyA1xByB1xCyC1=r×area(ΔABC)

r=area(ΔBCP)area(ΔABC)

and

area(ΔCAP)=12sxAyA1xByB1xCyC1=s×area(ΔABC)

s=area(ΔCAP)area(ΔABC)

Thus, we see that the areas of the internal triangles are directly proportional to the barycentric coordinates of P.

Fig. 17.17

The inscribed circle in triangle ΔABC

This is quite a useful relationship and can be used to resolve various geometric problems. For example, let’s use it to find the radius and centre of the inscribed circle for a triangle. We could approach this problem using classical Euclidean geometry, but barycentric coordinates provide a powerful analytical tool for resolving the problem very quickly.  Consider triangle ΔABC with sides a, b and c as shown in Fig. 17.17. The point P is the centre of the inscribed circle with radius R. From our knowledge of barycentric coordinates we know that:

P=rA+sB+tC

where:

r+s+t=1

(17.12)

We also know that the area properties of barycentric coordinates permit us to state

area(ΔBCP)=r×area(ΔABC)=12aRarea(ΔCAP)=s×area(ΔABC)=12bRarea(ΔABP)=t×area(ΔABC)=12cR

therefore:

r=aR2×area(ΔABC),s=bR2×area(ΔABC),t=cR2×area(ΔABC)

substituting r, s and t in (17.12) we get:

R2×area(ΔABC)(a+b+c)=1

and

R=2×area(ΔABC)a+b+c

Substituting R in the definitions of r, s and t we obtain:

r=aa+b+cs=ba+b+ct=ca+b+c

and

xP=rxA+sxB+txCyP=ryA+syB+tyC

Fig. 17.18

The inscribed circle for a triangle

To test this solution, consider the right-angled triangle in Fig. 17.18, where a=200, b=10, c=10 and area(ΔABC)=50. Therefore:

R=2×5010+10+200≈2.929

and

r=20034.1421≈0.4142,s=1034.1421≈0.2929,t=1034.1421≈0.2929

therefore:

xP=0.4142×0+0.2929×10+0.2929×0≈2.929yP=0.4142×0+0.2929×0+0.2929×0≈2.929

Therefore, the inscribed circle has a radius of 2.929 and a centre with coordinates (2.929,2.929).

Let’s explore another example where we determine the barycentric coordinates of a point using virtual mass points.

Figure 17.19 shows triangle ΔABC where A′, B′ and C′ divide BC, CA and AB respectively, in the ratio 1 : 2. The objective is to find the barycentric coordinates of D, E and F, and the area of triangle ΔDEF as a proportion of triangle ΔABC.

Fig. 17.19

Triangle ΔABC with sides divided in the ratio 1 : 2

We can approach the problem using mass points. For example, if we assume D is the centroid, all we have to do is determine the mass points that create this situation. Then the barycentric coordinates of D are given by (17.8). We proceed as follows.

The point D is on the intersection of lines CC′ and AA′. Therefore, we begin by placing a mass of 1 at C. Then, for line BC to balance at A′ a mass of 2 must be placed at B. Similarly, for line AB to balance at C′ a mass of 4 must be placed at A. This configuration is shown in Fig. 17.20.

Fig. 17.20

The masses assigned to A, B and C to determine D

The total mass is 7=(1+2+4), therefore:

D=47A+27B+17C

The point E is on the intersection of lines BB′ and AA′. Therefore, we begin by placing a mass of 1 at A. Then, for line CA to balance at B′ a mass of 2 must be placed at C. Similarly, for line BC to balance at A′ a mass of 4 must be placed at B. This configuration is shown in Fig. 17.21. The total mass is still 7, therefore:

Fig. 17.21

The masses assigned to A, B and C to determine E

E=17A+47B+27C

From the symmetry of the triangle we can state that:

F=27A+17B+47C

Thus we can locate the points and using the vector equations:

D=47A+27B+17CE=17A+47B+27CF=27A+17B+47C

The important feature of these equations is that the barycentric coordinates of D, E and F are independent of A, B and C they arise from the ratio used to divide the triangle’s sides.

Although it was not the original intention, we can quickly explore what the barycentric coordinates of D, E and F would be if the triangle’s sides had been 1 : 3 instead of 1 : 2. Without repeating all of the above steps, we would proceed as follows.

The point D is on the intersection of lines CC′ and AA′. Therefore, we begin by placing a mass of 1 at C. Then, for line BC to balance at A′ a mass of 3 must be placed at B. Similarly, for line AB to balance at C′ a mass of 9 must be placed at A. This configuration is shown in Fig. 17.22. The total mass is 13=(1+3+9), therefore,

Fig. 17.22

The masses assigned to A, B and C to determine D

D=913A+313B+113CE=113A+913B+313CF=313A+113B+913C

We could even develop the general equations for a ratio 1 : n. It is left to the reader to show that:

D=n2n2+n+1A+nn2+n+1B+1n2+n+1CE=1n2+n+1A+n2n2+n+1B+nn2+n+1CF=nn2+n+1A+1n2+n+1B+n2n2+n+1C

As a quick test for the above equations, let n=1, which make D, E and F concurrent at the triangle’s centroid:

D=13A+13B+13CE=13A+13B+13CF=13A+13B+13C

which is rather reassuring!

Fig. 17.23

Triangle ΔABC divides into four triangles ΔABE, ΔBCF, ΔCAD and ΔDEF

Now let’s return to the final part of the problem and determine the area of triangle ΔDEF in terms of ΔABC. The strategy is to split triangle ΔABC into four triangles: ΔBCF, ΔCAD, ΔABE and ΔDEF as shown in Fig. 17.23.

Therefore:

area(ΔABC)=area(ΔBCF)+area(ΔCAD)+area(ΔABE)+area(ΔDEF)

and

1=area(ΔBCF)area(ΔABC)+area(ΔCAD)area(ΔABC)+area(ΔABE)area(ΔABC)+area(ΔDEF)area(ΔABC)

(17.13)

But we have just discovered that the barycentric coordinates are intimately connected with the ratios of triangles. For example, if F has barycentric coordinates (rF,sF,tF) relative to the points A, B and C respectively, then:

rF=area(ΔBCF)area(ΔABC)

And if D has barycentric coordinates (rD,sD,tD) relative to the points A, B and C respectively, then:

sD=area(ΔCAD)area(ΔABC)

Similarly, if E has barycentric coordinates (rE,sE,tE) relative to the points A, B and C respectively, then:

tE=area(ΔABE)area(ΔABC)

Substituting rF, sE and tD in () we obtain:

1=rF+sD+tE+area(ΔDEF)area(ΔABC)

From (17.12) we see that:

rF=27,sD=27,tE=27

therefore:

1=67+area(ΔDEF)area(ΔABC)

and

area(ΔDEF)=17area(ΔABC)

which is rather neat!

Before we leave this example, let’s state a general expression for the area(ΔDEF) for a triangle whose sides are divided in the ratio 1 : n. Once again, I’ll leave it to the reader to prove that:

area(ΔDEF)=n2-2n+1n2+n+1×area(ΔABC)

Note that when n=1, area(ΔDEF)=0, which is correct.

[Hint: The corresponding values of rF, sD and tE are n/(n2+n+1).]

17.9 Volumes

We have now seen that barycentric coordinates can be used to locate a scalar within a 1D domain, a point within a 2D area, so it seems logical that the description should extend to volumes, which is the case.

Fig. 17.24

A tetrahedron

To demonstrate this, consider the tetrahedron shown in Fig. 17.24. The volume of a tetrahedron is give by:

V=16x1y1z1x2y2z2x3y3z3

where [x1y1z1]T, [x2y2z2]T and [x3y3z3]T are the three vectors extending from the fourth vertex to the other three vertices. However, if we locate the fourth vertex at the origin, (x1,y1,z1), (x2,y2,z2) and (x3,y3,z3) become the coordinates of the three vertices.

Let’s locate a point P(xP,yP,zP) inside the tetrahedron with the following barycentric definition:

P=rP1+sP2+tP3+uP0

(17.14)

where P, P1, P2, P3 and P0 are the position vectors for P, P1, P2, P3 and P0 respectively. The fourth barycentric term uP0 can be omitted as P0 has coordinates (0,0,0).

Therefore, we can state that the volume of the tetrahedron formed by the three vectors P, P2 and P3 is given by:

V=16xPyPzPx2y2z2x3y3z3

(17.15)

Substituting (17.14) in (17.15) we obtain:

V=16rx1+sx2+tx3ry1+sy2+ty3rz1+sz2+tz3x2y2z2x3y3z3

(17.16)

which expands to:

V=16y2z3(rx1+sx2+tx3)+x2y3(rz1+sz2+tz3)+x3z2(ry1+sy2+ty3)-y3z2(rx1+sx2+tx3)-x3y2(rz1+sz2+tz3)-x2z3(ry1+sy2+ty3)=16r(x1y2z3+x2y3z1+x3y1z2-x1y3z2-x3y2z1-x2y1z3)+s(x2y2z3+x2y3z2+x3y1z2-x2y3z2-x3y1z2-x2y2z3)+t(x3y2z3+x2y3z3+x3y3z2-x3y3z2-x3y2z3-x2y3z3)

and simplifies to:

V=16rx1y1z1x2y2z2x3y3z3

This states that the volume of the smaller tetrahedron is r times the volume of the larger tetrahedron VT, where r is the barycentric coordinate modifying the vertex not included in the volume. By a similar process we can develop volumes for the other tetrahedra:

V(P,P2,P4,P3)=rVTV(P,P1,P3,P4)=sVTV(P,P1,P2,P4)=tVTV(P,P1,P2,P3)=uVT

where r+s+t+u=1. Similarly, the barycentric coordinates of a point inside the volume sum to unity.

Let’s test the above statements with an example. Given P1(0,0,1),P2(1,0,0), P3(0,1,0) and P13,13,13 which is located inside the tetrahedron, the volume of the tetrahedron VT is:

VT=16001100010=16

r=V(P,P2,P4,P3)VT=6623-13-13-13-13-13-1323-13=13s=V(P,P1,P3,P4)VT=66-13-1323-1323-13-13-13-13=13t=V(P,P1,P2,P4)VT=66-13-132323-13-13-13-13-13=13u=V(P,P1,P2,P3)VT=66-13-132323-13-13-1323-13=0

The barycentric coordinates (r,s,t,u) confirm that the point is located at the centre of triangle ΔP1P2P3. Note that the above determinants will create a negative volume if the vector sequences are reversed.

17.10 Bézier Curves and Patches

 In Chap. 14 we examined Bézier curves and patches which are based on Bernstein polynomials:

Bin(t)=niti(1-t)n-i

We discovered that these polynomials create the quadratic terms:

(1-t)2,2t(1-t),t2

and the cubic terms:

(1-t)3,3t(1-t)2,3t2(1-t),t3

which are used as scalars to multiply sequences of control points to create a parametric curve. Furthermore, these terms sum to unity, therefore they are also another form of barycentric coordinates. The only difference between these terms and the others described above is that they are controlled by a common parameter t. Another property of Bézier curves and patches is that they are constrained within the convex hull formed by the control points, which is also a property of barycentric coordinates.

17.11 Summary

Barycentric coordinates provide another way to locate points in space, which permit them to be used for ratios and proportion, areas, volumes, and centres of gravity.

Reference

1.

Posamentier A (2008) Advanced Euclidean geometry. Blackwell

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_18

18. Geometric Algebra

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

18.1 Introduction

This can only be a brief introduction to geometric algebra as the subject really demands an entire book. Those readers who wish to pursue the subject further should consult the author’s books [1, 2].

18.2 Background

Although geometric algebra introduces some new ideas, the subject should not be regarded as difficult. If you have read and understood the previous chapters, you should be familiar with vectors, vector products, transforms, and the idea that the product of two transforms is sensitive to the transform sequence. For example, in general, scaling an object after it has been translated, is not the same as translating an object after it has been scaled. Similarly, given two vectors r and s their vector product r×s creates a third vector t, using the right-hand rule, perpendicular to the plane containing r and s. However, just by reversing the vectors to s×r, creates a similar vector but in the opposite direction -t.

We regard vectors as directed lines or oriented lines, but if they exist, why shouldn’t oriented planes and oriented volumes exist? Well, the answer to this question is that they do, which is what geometric algebra is about. Unfortunately, when vectors were invented, geometric algebra was overlooked, and it has taken a further century for it to emerge through the work of William Kingdon Clifford and the theoretical physicist David Hestenes (1933–). So let’s continue and discover an exciting new algebra that will, in time, be embraced by the computer graphics community.

18.3 Symmetric and Antisymmetric Functions

It   is possible to classify functions into two categories: symmetric (even) and antisymmetric (odd) functions. For example, given two symmetric functions f(x) and f(x,y):

f(-x)=f(x)

and

f(y,x)=f(x,y)

an example being cosx where cos(-x)=cosx. Figure 18.1 illustrates how the cosine function is reflected about the origin. However, if the functions are antisymmetric:

f(-x)=-f(x)

and

f(y,x)=-f(x,y)

an example being sinx where sin(-x)=-sinx. Figure 18.2 illustrates how the sine function is reflected about the origin.

Fig. 18.1

The graph of the symmetric cosine function

Fig. 18.2

The graph of the antisymmetric sine function

The reason why we have covered symmetric and antisymmetric functions is that they play an important role in geometric algebra. Now let’s continue with this introduction and explore some important trigonometric foundations.

18.4 Trigonometric Foundations

Figure 18.3 shows two line segments a and b with coordinates (a1,a2), (b1,b2) respectively. The lines are separated by an angle θ, and we will compute the expressions abcosθ and absinθ, as these play an important role in geometric algebra.

Fig. 18.3

Two line segments a and b separated by +θ

Using the trigonometric identities:

sin(θ+ϕ)=sinθcosϕ+cosθsinϕ

(18.1)

cos(θ+ϕ)=cosθcosϕ-sinθsinϕ

(18.2)

and the following observations:

cosϕ=a1a,sinϕ=a2a,cos(θ+ϕ)=b1b,sin(θ+ϕ)=b2b

we can rewrite (18.1) and (18.2) as:

b2b=a1asinθ+a2acosθ

(18.3)

b1b=a1acosθ-a2asinθ

(18.4)

To isolate cosθ we multiply (18.3) by a2 and (18.4) by a1:

a2b2b=a1a2asinθ+a22acosθ

(18.5)

a1b1b=a12acosθ-a1a2asinθ

(18.6)

Adding (18.5) and (18.6) we obtain:

a1b1+a2b2b=a12+a22acosθ=acosθ

therefore:

abcosθ=a1b1+a2b2

To isolate sinθ we multiply (18.3) by a1 and (18.4) by a2:

a1b2b=a12asinθ+a1a2acosθ

(18.7)

a2b1b=a1a2acosθ-a22asinθ

(18.8)

Subtracting (18.8) from (18.7) we obtain:

a1b2-a2b1b=a12+a22asinθ=asinθ

therefore:

absinθ=a1b2-a2b1

If we form the product of b’s projection on a with a, we get abcosθ which we have shown equals a1b1+a2b2. Similarly, if we form the product absinθ we compute the area of the parallelogram formed by sweeping a along b, which equals a1b2-a2b1. What is noteworthy, is that the product abcosθ is independent of the sign of the angle θ, whereas the product absinθ is sensitive to the sign of θ. Consequently, if we construct the lines a and b such that b is rotated -θ relative to a as shown in Fig. 18.4,  abcosθ=a1b1+a2b2, but absinθ=-(a1b2-a2b1). The antisymmetric nature of the sine function reverses the sign of the area.

Fig. 18.4

Two line segments a and b separated by -θ

Having shown that area is a signed quantity just by using trigonometric identities, let’s explore how vector algebra responds to this idea.

18.5 Vectorial Foundations

When we form the algebraic product of two 2D vectors a and b:

a=a1i+a2jb=b1i+b2j

we obtain:

ab=a1b1i2+a2b2j2+a1b2ij+a2b1ji

(18.9)

and it is clear that a1b1i2+a2b2j2 has something to do with abcosθ, and a1b2ij+a2b1ji has something to do with absinθ. The product ab creates the terms i2, j2, ij and ji, which are resolved as follows.

18.6 Inner and Outer Products   

I like to believe that mathematics is a game—a game where we make the rules. Some rules might take us nowhere; others might take us so far in a particular direction and then restrict any further development; whilst other rules might open up a fantastic landscape that would have remained hidden had we not stumbled upon them. There are no ‘wrong’ or ‘right’ rules—there are just rules where some work better than others. Fortunately, the rules behind geometric algebra have been tested for over a hundred years, so we know they work. But these rules were not hiding somewhere waiting to be discovered, they arose due to the collective intellectual endeavour of many mathematicians over several decades.

Let’s begin with the products ij and ji in (18.9) and assume that they anticommute: ji=-ij. Therefore:

ab=a1b1i2+a2b2j2+(a1b2-a2b1)ij

(18.10)

and if we reverse the product to ba we obtain:

ba=a1b1i2+a2b2j2-(a1b2-a2b1)ij

(18.11)

From (18.10) and (18.11) we see that the product of two vectors contains a symmetric component:

a1b1i2+a2b2j2

and an antisymmetric component:

(a1b2-a2b1)ij

It is interesting to observe that the symmetric component has 0∘ between its vector pairs (i2 or j2), whereas the antisymmetric component has 90∘ between its vector pairs (i and j). Therefore, the sine and cosine functions play a natural role in our rules. What we are looking for are two functions that, when given our vectors a and b, one function returns the symmetric component and the other returns the antisymmetric component. We call these the inner and outer functions respectively.

It should be clear that if the inner function includes the cosine of the angle between the two vectors it will reject the antisymmetric component and return the symmetric element. Similarly, if the outer function includes the sine of the angle between the vectors, the symmetric component is rejected, and returns the antisymmetric element.

If we declare the inner function as the inner product:

a·b=‖a‖‖b‖cosθ

(18.12)

then:

a·b=(a1i+a2j)·(b1i+b2j)=a1b1i·i+a1b2i·j+a2b1j·i+a2b2j·j=a1b1+a2b2

which is perfect!

Next, we declare the outer function as the outer product using the wedge ‘∧’ symbol; which is why it is also called the wedge product:

a∧b=‖a‖‖b‖sinθi∧j

(18.13)

Note that product includes a strange i∧j term. This is included as we just can’t ignore the ij term in the antisymmetric component:

a∧b=(a1i+a2j)∧(b1i+b2j)=a1b1i∧i+a1b2i∧j+a2b1j∧i+a2b2j∧j=(a1b2-a2b1)i∧j

which enables us to write:

ab=a·b+a∧b

(18.14)

ab=‖a‖‖b‖cosθ+‖a‖‖b|sinθi∧j

(18.15)

18.7 The Geometric Product in 2D 

Clifford named the sum of the two products the geometric product, which means that (18.14) reads: The geometric product ab is the sum of the inner product ‘a dot b’ and the outer product ‘a wedge b’. Remember that all this assumes that ji=-ij which seems a reasonable assumption.

Given the definition of the geometric product, let’s evaluate i2:

ii=i·i+i∧i

Using the definition for the inner product (18.12) we have:

i·i=1×1×cos0∘=1

whereas, using the definition of the outer product (18.13) we have:

i∧i=1×1×sin0∘i∧i=0

Thus i2=1 and j2=1, and aa=‖a‖2:

aa=a·a+a∧a=‖a‖‖a‖cos0∘+‖a‖‖a‖sin0∘i∧jaa=‖a‖2

Now let’s evaluate ij:

ij=i·j+i∧j

Using the definition for the inner product (18.12) we have:

i·j=1×1×cos90∘=0

whereas using the definition of the outer product (18.13) we have:

i∧j=1×1×sin90∘i∧j=i∧j

Thus ij=i∧j. But what is i∧j? Well, it is a new object and is called a ‘bivector’ and defines the orientation of the plane containing i and j.

As the order of the vectors is from i to j, the angle is +90∘ and sin(+90)∘=1. Whereas, if the order is from j to i the angle is -90∘ and sin(-90∘)=-1. Consequently:

ji=j·i+j∧i=0+1×1×sin(-90∘)i∧jji=-i∧j

Thus the bivector i∧j defines the orientation of a surface as anticlockwise, whilst the bivector j∧i defines the orientation as clockwise. These ideas are shown in Fig. 18.5.

Fig. 18.5

An anticlockwise and clockwise bivector

So far, so good. Our rules seem to be leading somewhere. The inner product (18.12) is our old friend the dot product, and does not need explaining. However, the outer product (18.13) does require some further explanation.

The equation:

ab=9+12i∧j

simply means that the geometric product of two vectors a and b creates a scalar, inner product of 9, and an outer product of 12 on the ij-plane.

For example, given:

a=3ib=3i+4j

then:

ab=3i·(3i+4j)+3i∧(3i+4j)=9+9i∧i+12i∧jab=9+12i∧j

The 9 represents ‖a‖‖b‖cosθ, whereas the 12 represents an area ‖a‖‖b‖sinθ on the ij-plane. The angle between the two vectors θ is given by:

θ=cos-135

However, reversing the product, we obtain:

ba=(3i+4j)·3i+(3i+4j)∧3i=9+9i∧i+12j∧iab=9-12i∧j

The sign of the outer (wedge) product has flipped to reflect the new orientation of the vectors relative to the accepted orientation of the basis bivectors.

So the geometric product combines the scalar and wedge products into a single product, where the scalar product is the symmetric component and the wedge product is the antisymmetric component. Now let’s see how these products behave in 3D.

18.8 The Geometric Product in 3D 

Before we consider the geometric product in 3D we need to introduce some new notation, which will simplify future algebraic expressions. Rather than use i, j and k to represent the unit basis vectors let’s employ e1, e2 and e3 respectively. This means that (18.15) can be written:

ab=‖a‖‖b‖cosθ+‖a‖‖b‖sinθe1∧e2

We begin with two 3D vectors:

a=a1e1+a2e2+a3e3b=b1e1+b2e2+b3e3

therefore, their inner product is:

a·b=(a1e1+a2e2+a3e3)·(b1e1+b2e2+b3e3)=a1b1+a2b2+a3b3

and their outer product is:

a∧b=(a1e1+a2e2+a3e3)∧(b1e1+b2e2+b3e3)=a1b2e1∧e2+a1b3e1∧e3+a2b1e2∧e1+a2b3e2∧e3+a3b1e3∧e1+a3b2e3∧e2

a∧b=(a1b2-a2b1)e1∧e2+(a2b3-a3b2)e2∧e3+(a3b1-a1b3)e3∧e1

(18.16)

This time we have three unit-basis bivectors: e1∧e2, e2∧e3, e3∧e1, and three associated scalar multipliers: (a1b2-a2b1),  (a2b3-a3b2),   (a3b1-a1b3) respectively.

Continuing with the idea described in the previous section, the three bivectors represent the three planes containing the respective vectors as shown in Fig. 18.6, and the scalar multipliers are projections of the area of the vector parallelogram onto the three bivectors as shown in Fig. 18.7. The orientation of the vectors a and b determine whether the projected areas are positive or negative.

Fig. 18.6

The 3D bivectors

Fig. 18.7

The projections on the three bivectors

You may think that (18.16) looks familiar. In fact, it looks very similar to the cross product a×b:

a×b=(a1b2-a2b1)e3+(a2b3-a3b2)e1+(a3b1-a1b3)e2

(18.17)

This similarity is no accident. For when Hamilton invented quaternions, he did not recognise the possibility of bivectors, and invented some rules, which eventually became the cross product! Later in this chapter we discover that quaternions are really bivectors in disguise.

We can see that a simple relationship exists between (18.16) and (18.17):

e1∧e2ande3e2∧e3ande1e3∧e1ande2

the wedge product bivectors are perpendicular to the vector components of the cross product. So the wedge product is just another way of representing the cross product. However, the wedge product introduces a very important bonus: it works in space of any dimension, whereas, the cross product is only comfortable in 3D. Not only that, the wedge (outer product) is a product that creates volumes, hypervolumes, and can also be applied to vectors, bivectors, trivectors, etc.

18.9 The Outer Product of Three 3D Vectors 

Having seen that the outer product of two 3D vectors is represented by areal projections onto the three basis bivectors, let’s explore the outer product of three 3D vectors.

Given:

a=a1e1+a2e2+a3e3b=b1e1+b2e2+b3e3c=c1e1+c2e2+c3e3

then:

a∧b∧c=(a1e1+a2e2+a3e3)∧(b1e1+b2e2+b3e3)∧(c1e1+c2e2+c3e3)=[(a1b2-a2b1)e1∧e2+(a2b3-a3b2)e2∧e3+(a3b1-a1b3)e3∧e1]∧(c1e1+c2e2+c3e3)

At this stage we introduce another axiom: the outer product is associative. This means that a∧(b∧c)=(a∧b)∧c. Therefore, knowing that a∧a=0:

a∧b∧c=c3(a1b2-a2b1)e1∧e2∧e3+c1(a2b3-a3b2)e2∧e3∧e1+c2(a3b1-a1b3)e3∧e1∧e2.

But we are left with the products e1∧e2∧e3,  e2∧e3∧e1 and e3∧e1∧e2. Not to worry, because we know that a∧b=-b∧a. Therefore:

e2∧e3∧e1=-e2∧e1∧e3=e1∧e2∧e3

and

e3∧e1∧e2=-e1∧e3∧e2=e1∧e2∧e3

Therefore, we can write a∧b∧c as:

a∧b∧c=c3(a1b2-a2b1)e1∧e2∧e3+c1(a2b3-a3b2)e1∧e2∧e3+c2(a3b1-a1b3)e1∧e2∧e3

or

a∧b∧c=c3(a1b2-a2b1)+c1(a2b3-a3b2)+c2(a3b1-a1b3)e1∧e2∧e3

or using a determinant:

a∧b∧c=a1b1c1a2b2c2a3b3c3e1∧e2∧e3

which is the well-known expression for the volume of a parallelpiped formed by three vectors.

The term e1∧e2∧e3 is a trivector and reminds us that the volume is oriented. If the sign of the determinant is positive, the original three vectors possess the same orientation of the three basis vectors. If the sign of the determinant is negative, the three vectors possess an orientation opposing that of the three basis vectors.

18.10 Axioms 

One of the features of geometric algebra is that it obeys the same axioms of every-day scalars:

Axiom 1: The associative rule:

a(bc)=(ab)c

Axiom 2: The left and right distributive rules:

a(b+c)=ab+ac(b+c)a=ba+ca

The next four axioms describe how vectors interact with a scalar λ:

Axiom 3:

(λa)b=λ(ab)=λab

Axiom 4:

λ(ϕa)=(λϕ)a

Axiom 5:

λ(a+b)=λa+λb

Axiom 6:

(λ+ϕ)a=λa+ϕa

The next axiom that is adopted is:

Axiom 7:

a2=‖a‖2

which has already emerged as a consequence of the algebra. However, for non-Euclidean geometries, this can be set to a2=-‖a‖2, which does not concern us here.

18.11 Notation

Having abandoned i, j, k for e1, e2, e3, it is convenient to convert geometric products e1e2⋯en to e12⋯n. For example, e1e2e3≡e123. Furthermore, we must get used to the following substitutions:

eieiej=eje21=-e12e312=e123e112=e2e121=-e2

18.12 Grades, Pseudoscalars and Multivectors     

As geometric algebra embraces such a wide range of objects, it is convenient to grade them as follows: scalars are grade 0, vectors are grade 1, bivectors are grade 2, and trivectors are grade 3, and so on for higher dimensions. In such a graded algebra it is traditional to call the highest grade element a pseudoscalar. Thus in 2D the pseudoscalar is e12 and in 3D the pseudoscalar is e123.

One very powerful feature of geometric algebra is the idea of a multivector, which is a linear combination of a scalar, vector, bivector, trivector or any other higher dimensional object. For example the following are multivectors:

A=3+(2e1+3e2+4e3)+(5e12+6e23+7e31)+8e123B=2+(2e1+2e2+3e3)+(4e12+5e23+6e31)+7e123

and we can form their sum:

A+B=5+(4e1+5e2+7e3)+(9e12+11e23+13e31)+15e123

or their difference:

A-B=1+(e2+e3)+(e12+e23+e31)+e123

We can even form their product AB, but at the moment we have not explored the products between all these elements.

We can isolate any grade of a multivector using the following notation:

⟨multivector⟩g

where g identifies a particular grade. For example, say we have the following multivector:

2+3e1+2e2-5e12+6e123

we extract the scalar term using:

⟨2+3e1+2e2-5e12+6e123⟩0=2

the vector term using:

⟨2+3e1+2e2-5e12+6e123⟩1=3e1+2e2

the bivector term using:

⟨2+3e1+2e2-5e12+6e123⟩2=-5e12

and the trivector term using:

⟨2+3e1+2e2-5e12+6e123⟩3=6e123

It is also worth pointing out that the inner vector product converts two grade 1 elements, i.e. vectors, into a grade 0 element, i.e. a scalar, whereas the outer vector product converts two grade 1 elements into a grade 2 element, i.e. a bivector. Thus the inner product is a grade lowering operation, while the outer product is a grade raising operation. These qualities of the inner and outer products are associated with higher grade elements in the algebra. This is why the scalar product is renamed as the inner product, because the scalar product is synonymous with transforming vectors into scalars. Whereas, the inner product transforms two elements of grade n into a grade n-1 element.

18.13 Redefining the Inner and Outer Products   

As the geometric product is defined in terms of the inner and outer products, it seems only natural to expect that similar functions exist relating the inner and outer products in terms of the geometric product. Such functions do exist and emerge when we combine the following two equations:

ab=a·b+a∧b

(18.18)

ba=a·b-a∧b

(18.19)

Adding and subtracting (18.18) and (18.19) we have:

a·b=12(ab+ba)

(18.20)

a∧b=12(ab-ba)

(18.21)

Equations (18.20) and (18.21) and used frequently to define the products between different grade elements.

18.14 The Inverse of a Vector 

In traditional vector analysis we accept that it is impossible to divide by a vector, but that is not so in geometric algebra. In fact, we don’t actually divide a multivector by another vector but find a way of representing the inverse of a vector. For example, we know that a unit vector a^ is defined as:

a^=a‖a‖

and using the geometric product:

a^2=a2‖a‖2=1

therefore:

b=a2b‖a‖2

and exploiting the associative nature of the geometric product we have:

b=a(ab)‖a‖2

(18.22)

Equation (18.22) is effectively stating that, given the geometric product ab we can recover the vector b by pre-multiplying by a-1:

a‖a‖2

Similarly, we can recover the vector a by post-multiplying by b-1:

a=(ab)b‖b‖2

For example, given two vectors:

a=e1+2e2b=3e1+2e2

their geometric product is:

ab=7-4e12

Therefore, given ab and a, we can recover b as follows:

b=e1+2e25(7-4e12)=15(7e1-4e112+14e2-8e212)=15(7e1-4e2+14e2+8e1)b=3e1+2e2

Similarly, give ab and b, a is recovered as follows:

a=(7-4e12)3e1+2e213=113(21e1+14e2-12e121-8e122)=113(21e1+14e2+12e2-8e1)a=e1+2e2

Note that the inverse of a unit vector is the original vector:

a^-1=a^‖a^‖2=a^

18.15 The Imaginary Properties of the Outer Product 

So far we know that the outer product of two vectors is represented by one or more unit basis vectors, such as:

a∧b=λ1e12+λ2e23+λ3e31

where, in this case, the λi terms represent areas projected onto their respective unit basis bivectors. But what has not emerged is that the outer product is an imaginary quantity, which is revealed by expanding e122:

e122=e1212

but as:

e21=-e12

then:

e1(21)2=-e1(12)2=-e12e22e122=-1

Consequently, the geometric product effectively creates a complex number! Thus in a 2D scenario, given two vectors:

a=a1e1+a2e2b=b1e1+b2e2

their geometric product is:

ab=(a1b1+a2b2)+(a1b2-a2b1)e12

and knowing that e12=i, then we can write ab as:

ab=(a1b1+a2b2)+(a1b2-a2b1)i

(18.23)

However, this notation is not generally adopted by the geometric community. The reason being that i is normally only associated with a scalar, with which it commutes. Whereas in 2D, e12 is associated with scalars and vectors, and although scalars present no problem, under some conditions, it anticommutes with vectors. Consequently, an upper-case I is used so that there is no confusion between the two elements. Thus (18.23) is written as:

ab=(a1b1+a2b2)+(a1b2-a2b1)I

where:

I2=-1

It goes without saying that the 3D unit basis bivectors are also imaginary quantities, so is e123.

Multiplying a complex number by i rotates it 90∘ on the complex plane. Therefore, it should be no surprise that multiplying a 2D vector by e12 rotates it by 90∘. However, because vectors are sensitive to their product partners, we must remember that pre-multiplying a vector by e12 rotates a vector clockwise and post-multiplying rotates a vector anti-clockwise.

Fig. 18.8

The effect of pre-multiplying a vector by a bivector

Whilst on the subject of rotations, let’s consider what happens in 3D. We begin with a 3D vector:

a=a1e1+a2e2+a3e3

and the unit basis bivector e12 as shown in Fig. 18.8. Next we construct their geometric product by pre-multiplying a by e12:

e12a=a1e12e1+a2e12e2+a3e12e3

which becomes:

e12a=a1e121+a2e122+a3e123=-a1e2+a2e1+a3e123=a2e1-a1e2+a3e123

and contains two parts: a vector (a2e1-a1e2) and a volume a3e123.

Figure 18.8 shows how the projection of vector a is rotated clockwise on the bivector e12. A volume is also created perpendicular to the bivector. This enables us to predict that if the vector is coplanar with the bivector, the entire vector is rotated -90∘ and the volume component will be zero.

By post-multiplying a by e12 creates:

ae12=-a2e1+a1e2+a3e123

which shows that while the volumetric element has remained the same, the projected vector is rotated anticlockwise.

You may wish to show that the same happens with the other two bivectors.

18.16 Duality 

The ability to exchange pairs of geometric elements such as lines and planes involves a dual operation, which in geometric algebra is relatively easy to define. For example, given a multivector A its dual A∗ is defined as:

A∗=IA

where I is the local pseudoscalar. For 2D this is e12 and for 3D it is e123. Therefore, given a 2D vector:

a=a1e1+a2e2

its dual is:

a∗=e12(a1e1+a2e2)=a1e121+a2e122=a2e1-a1e2

which is another vector rotated 90∘ clockwise.

It is easy to show that (a∗)∗=-a, and two further dual operations return the vector back to a.

In 3D the dual of a vector e1 is:

e123e1=e1231=e23

which is the perpendicular bivector. Similarly, the dual of e2 is e31 and the dual of e3 is e12.

For a general vector a1e1+a2e2+a3e3 its dual is:

e123(a1e1+a2e2+a3e3)=a1e1231+a2e1232+a3e1233=a3e12+a1e23+a2e31

The duals of the 3D basis bivectors are:

e123e12=e12312=-e3e123e23=e12323=-e1e123e31=e12331=-e2

18.17 The Relationship Between the Vector Product and the Outer Product

We have already discovered that there is a very close relationship between the vector product and the outer product, and just to recap. Given two vectors:

a=a1e1+a2e2+a3e3b=b1e1+b2e2+b3e3

then:

a×b=(a2b3-a3b2)e1+(a3b1-a1b3)e2+(a1b2-a2b1)e3

(18.24)

and

a∧b=(a2b3-a3b2)e2∧e3+(a3b1-a1b3)e3∧e1+(a1b2-a2b1)e1∧e2

or

a∧b=(a2b3-a3b2)e23+(a3b1-a1b3)e31+(a1b2-a2b1)e12

(18.25)

If we multiply (18.25) by I123 we obtain:

I123(a∧b)=(a2b3-a3b2)e123e23+(a3b1-a1b3)e123e31+(a1b2-a2b1)e123e12=-(a2b3-a3b2)e1-(a3b1-a1b3)e2-(a1b2-a2b1)e3

which is identical to the cross product (18.24) apart from its sign. Therefore, we can state:

a×b=-I123(a∧b)

18.18 The Relationship Between Quaternions and Bivectors   

Hamilton’s rules for the imaginaries i, j and k are shown in Table 18.1, whilst Table 18.2 shows the rules for 3D bivector products.

Table 18.1

Hamilton’s quaternion product rules

i

j

k

i

-1

k

-j

j

-k

-1

i

k

j

-i

-1

Table 18.2

3D bivector product rules

e23

e31

e12

e23

-1

-e12

e31

e31

e12

-1

-e23

e12

-e31

e23

-1

Although there is some agreement between the table entries, there is a sign reversal in some of them. However, if we switch to a left-handed axial system the bivectors become e32, e13, e21 and their products are as shown in Table 18.3.

If we now create a one-to-one correspondence (isomorphism) between the two systems:

i↔e32,j↔e13,k↔e21

there is a true correspondence between quaternions and a left-handed set of bivectors.

Table 18.3

Left-handed 3D bivector product rules

e32

e13

e21

e32

-1

e21

-e13

e13

-e21

-1

e32

e21

e13

-e32

-1

18.19 Reflections and Rotations   

One of geometric algebra’s strengths is the elegance it brings to calculating reflections and rotations. Unfortunately, there is insufficient space to examine the derivations of the formulae, but if you are interested, these can be found in the author’s books [1, 2]. Let’s start with 2D reflections.

18.19.1 2D Reflections 

Given a line, whose perpendicular unit vector is m^ and a vector a its reflection a′ is given by:

a′=m^am^

which is rather elegant! For example, Fig. 18.9 shows a scenario where:

m^=12(e1+e2)a=e1

therefore:

a′=12(e1+e2)(e1)12(e1+e2)=12(1-e12)(e1+e2)=12(e1+e2+e2-e1)a′=e2

Note that in this scenario a reflection means a mirror image about the perpendicular vector.

Fig. 18.9

The reflection of a 2D vector

18.19.2 3D Reflections 

Let’s explore the 3D reflections shown in Fig. 18.10 where:

a=e1+e2-e3m^=e2

therefore:

a′=e2(e1+e2-e3)e2=e212+e222-e232=-e1+e2+e3

Fig. 18.10

The reflection of a 3D vector

As one might expect, it is also possible to reflect bivectors, trivectors and higher-dimensional objects, and for reasons of brevity, they are summarised as follows:

Reflecting about a line:

scalars:invariantvectors:v′=m^vm^bivectors:B′=m^Bm^trivectors:T′=m^Tm^

Reflecting about a mirror:

scalars:invariantvectors:v′=-m^vm^bivectors:B′=m^Bm^trivectors:T′=-m^Tm^

18.19.3 2D Rotations

 Figure 18.11 shows a plan view of two mirrors M and N separated by an angle θ. The object of the exercise is to discover the position of a point after being rotated a 2D rotation. The point P is in front of mirror M and subtends an angle α, and its reflection PR exists in the virtual space behind M and also subtends an angle α with the mirror. The angle between PR and N must be θ-α, and its reflection P′ must also lie θ-α behind N. By inspection, the angle between P and the double reflection P′ is 2θ.

Fig. 18.11

Rotating a point by a double reflection

If we apply this double reflection transform to a collection of points, they are effectively all rotated 2θ about the origin where the mirrors intersect. The only slight drawback with this technique is that the angle of rotation is twice the angle between the mirrors.

Fig. 18.12

Rotating a point by a double reflection

Instead of using points, let’s employ position vectors and substitute normal unit vectors for the mirrors’ orientation. For example, Fig. 18.12 shows the same mirrors with unit normal vectors m^ and n^. After two successive reflections, P becomes P′, and using the relationship:

v′=-m^vm^

we compute the reflections as follows:

pR=-m^pm^p′=-n^pRn^p′=n^m^pm^n^

which is also rather elegant and compact. However, we must remember that P is rotated twice the angle separating the mirrors, and the rotation is relative to the origin. Let’s demonstrate this technique with an example.

Fig. 18.13

Rotating a point by 180∘

Figure 18.13 shows two mirrors M and N with unit normal vectors m^, n^ and position vector p:

m^=e2n^=-e1P=(1,-1)p=e1-e2

As the mirrors are separated by 90∘ the point P is rotated 180∘:

p′=n^m^pm^n^=-e1e2(e1-e2)e2(-e1)=e12121-e12221=-e1+e2P′=(-1,1)

18.20 Rotors 

Quaternions are the natural choice for rotating vectors about an arbitrary axis, and although it may not be immediately obvious, we have already started to discover geometric algebra’s equivalent.

We begin with:

p′=n^m^pm^n^

and substitute R for n^m^ and R~ for m^n^, therefore:

p′=RpR~

where R and R~ are called rotors which perform the same function as a quaternion.

Because geometric algebra is non-commutative, the sequence of elements, be they vectors, bivectors, trivectors, etc., is very important. Consequently, it is very useful to include a command that reverses a sequence of elements. The notation generally employed is the tilde (~) symbol:

R=n^m^R~=m^n^

Let’s unpack a rotor in terms of its angle and bivector as follows:

The bivector defining the plane is m^∧n^ and θ is the angle between the vectors. Let:

R=n^m^R~=m^n^

where:

n^m^=n^·m^-m^∧n^m^n^=n^·m^+m^∧n^n^·m^=cosθm^∧n^=B^sinθ

Therefore:

R=cosθ-B^sinθR~=cosθ+B^sinθ

We now have an equation that rotates a vector p through an angle 2θ about an axis defined by B^:

p′=RpR^

or

p′=(cosθ-B^sinθ)p(cosθ+B^sinθ)

We can also express this such that it identifies the real angle of rotation α:

p′=(cos(α/2)-B^sin(α/2))pcos(α/2)+B^sin(α/2)

(18.26)

Equation (18.26) references a bivector, which may make you feel uncomfortable! But remember, it simply identifies the axis perpendicular to its plane. Let’s demonstrate how (18.26) works with two examples.

Figure 18.14 shows a scenario where vector p is rotated 90∘ about e2 which is perpendicular to B^, where:

α=90∘a=e2p=e1+e2B^=e31

Therefore:

p′=(cos45∘-e31sin45∘)(e1+e2)(cos45∘+e31sin45∘)=22-22e31(e1+e2)22+22e31=22e1+22e2-22e3-22e31222+22e31=12(e1-e3+e2+e231-e3-e1-e312-e31231)p′=e2-e3

Observe what happens when the bivector’s sign is reversed to -e31:

p′=(cos45∘+e31sin45∘)(e1+e2)(cos45∘-e31sin45∘)=22+22e31(e1+e2)22-22e31=22e1+22e2+22e3+22e31222-22e31=12(e1+e3+e2+e231+e3-e1+e312-e31231)p′=e2+e3

the rotation is clockwise about e2.

Fig. 18.14

Rotating a vector by 90∘

Figure 18.15 shows another scenario where vector p is rotated 120∘ about the bivector B, where:

m=e1-e3n=e2-e3α=120∘p=e2+e3B=m∧n=(e1-e3)∧(e2-e3)B=e12+e31+e23

Next, we normalise B to B^:

B^=13(e12+e23+e31)

therefore:

p′=(cos60∘-B^sin60∘)p(cos60∘+B^sin60∘)=12-13(e12+e23+e31)32(e2+e3)12+13(e12+e23+e31)32=12-e122-e232-e312(e2+e3)12+e122+e232+e312=14e2+e3-e1-e123+e3-e2-e312+e11+e12+e23+e31=12(e3-e123)(1+e12+e23+e31)=12(e3+e312-e2+e1-e123-e12312-e12323-e12331)=12(e3-e2+e1+e3+e1+e2)p′=e1+e3

These examples show that rotors behave just like quaternions. Rotors not only rotate vectors, but they can be used to rotate bivectors, and even trivectors, although, as one might expect, a rotated trivector remains unaltered in 3D.

Fig. 18.15

Rotating a vector by 120∘

18.21 Applied Geometric Algebra

This has been a very brief introduction to geometric algebra, and it has been impossible to cover all the algebra’s features. However, if you have understood the above topics, you will have understood some of the fundamental ideas behind the algebra. Let’s now consider some practical applications for geometric algebra.   The sine rule states that for any triangle ▵ABC with angles α, β and θ, and respective opposite sides a, b and c, then:

asinα=bsinβ=csinθ

This rule can be proved using the outer product of two vectors, which we know incorporates the sine of the angle between two vectors:

‖a∧b‖=‖a‖‖b‖sinα

Fig. 18.16

The sine rule

With reference to Fig. 18.16, we can state the triangle’s area as:

areaof▵ABC=12‖-c∧a‖=12‖c‖‖a‖sinβareaof▵BCA=12‖-a∧b‖=12‖a‖‖b‖sinθareaof▵CAB=12‖-b∧c‖=12‖b‖‖c‖sinα

which means that:

‖c‖‖a‖sinβ=‖a‖‖b‖sinθ=‖b‖‖c‖sinα

‖a‖sinα=‖b‖sinβ=‖c‖sinθ

The cosine rule states that for any triangle ▵ABC with sides a, b and c, then:

a2=b2+c2-2bccosα

where α is the angle between b and c.

Although this is an easy rule to prove using simple trigonometry, the geometric algebra solution is even easier.

Fig. 18.17

The cosine rule

Figure 18.17 shows a triangle ▵ABC constructed from vectors a, b and c. From Fig. 18.16:

a=b-c

(18.27)

Squaring (18.27) we obtain:

a2=b2+c2-(bc+cb)

But:

bc+cb=2b·c=2‖b‖‖c‖cosα

therefore:

‖a‖2=‖b‖2+‖c‖2-2‖b‖‖c‖cosα

Figure 18.18 shows a scenario where a line with direction vector v^ passes through a point T. The objective is to locate another point P perpendicular to v^ and a distance δ from T. The solution is found by post-multiplying v^ by the psuedoscalar e12, which rotates v^ through an angle of 90∘.

Fig. 18.18

A point P perpendicular to a point T on a line

As v^ is a unit vector:

TP→=δv^e12

therefore:

p=t+TP→

and

p=t+δv^e12

(18.28)

Fig. 18.19

A point P perpendicular to a point T on a line

For example, Fig. 18.19 shows a 2D scenario where:

v^=12(e1+e2)T=(4,1)t=4e1+e2δ=32

Using (18.28):

p=t+δv^e12=4e1+e2+3212(e1+e2)e12=4e1+e2+4e2-4e1p=5e2

and

P=(0,5)

If p is required on the other side of the line, we pre-multiply v^ by e12:

p=t+δe12v^

which is the same as reversing the sign of δ.

Reflecting a vector about another vector happens to be a rather easy problem for geometric algebra. Figure 18.20 shows the scenario where we see a vector a reflected about the normal to a line with direction vector v^.

Fig. 18.20

Reflecting a vector about a vector

We begin by calculating m^:

m^=v^e12

(18.29)

then reflecting a about m^:

a′=m^am^

substituting m^ we have:

a′=v^e12av^e12

(18.30)

Fig. 18.21

Reflecting a vector about a vector

As an illustration, consider the scenario shown in Fig. 18.21 where:

v^=12(e1+e2)a=-e1

Therefore, using (18.29):

m^=12(e1+e2)e12m^=12(e2-e1)

and using (18.30):

a′=12(e2-e1)(-e1)12(e2-e1)=12(e12+1)(e2-e1)=12(e1+e2+e2-e1)a′=e2

In computer graphics we often need to test whether a point is above, below or on a planar surface. If we already have the plane equation for the surface it is just a question of substituting the test point in the equation and investigating its signed value. But here is another way using geometric algebra. For example, if a bivector is used to represent the orientation of a plane, the outer product of the test point’s position vector with the bivector computes an oriented volume. Figure 18.22 shows a bivector a∧b and a test point P with position vector p relative to the bivector.

Fig. 18.22

Point relative to a bivector

Let:

The terms ‘above’ and ‘below’ mean in the bivector’s positive and negative half-space respectively.

As an example, consider the scenario shown in Fig. 18.23 where the plane’s orientation is represented by the bivector a∧b, and three test points P, Q and R.

Fig. 18.23

Three points relative to a bivector

If P=(0,1,0),   Q=(0,-1,0),   R=(1,0,0):

a=e1+e3b=e1

then:

p=e2q=-e2r=e1

and

a∧b∧p=(e1+e3)∧e1∧e2=e123a∧b∧q=(e1+e3)∧e1∧(-e2)=-e123a∧b∧r=(e1+e3)∧e1∧e1=0

We can see that the signs of the first two volumes show that P is in the positive half-space, Q is in the negative half-space, and R is on the plane.

18.22 Summary

Geometric algebra is a new and exciting subject and is destined to impact upon the way we solve problems in computer games and animation. Hopefully, you have found this chapter interesting, and if you are tempted to take the subject further, then look at the author’s books.

References

1.

Vince JA (2008) Geometric algebra for computer graphics. Springer

2.

Vince JA (2009) Geometric algebra: an algebraic system for computer games and animation. Springer

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_19

19. Calculus: Derivatives

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

19.1 Introduction

Calculus  is a very large subject, and calculus books have a reputation for being heavy. Therefore, to minimise this book’s weight, and provide a gentle introduction to the subject, I have selected specific topics from my book [1], and condensed them into two chapters.

One branch of calculus is concerned with a function’s derivative, which describes how fast a function changes relative to its independent variable. In this chapter, I show how limits are used in this process. We begin with some historical background, and then look at small numerical quantities, and how they can be ignored if they occur in certain products, but remain important in quotients.

19.2 Background

Over  a period of 350 years or more, calculus has evolved conceptually and in notation. Up until recently, calculus was described using infinitesimals, which are numbers so small, they can be ignored in certain products. However, it was Cauchy and the German mathematician Karl Weierstrass (1815–1897), who showed how limits can replace infinitesimals.

19.3 Small Numerical Quantities

The adjective small is a relative term, and requires clarification in the context of numbers. For example, if numbers are in the hundreds, and also contain some decimal component, then it seems reasonable to ignore digits after the 3rd decimal place for any quick calculation. For instance,

100.000003×200.000006≈20,000

and ignoring the decimal part has no significant impact on the general accuracy of the answer, which is measured in tens of thousands.

To develop an algebraic basis for this argument let’s divide a number into two parts: a primary part x, and some very small secondary part δx (pronounced delta x). In one of the above numbers, x=100 and δx=0.000003. Given two such numbers, x1 and y1, their product is given by:

x1=x+δxy1=y+δyx1y1=(x+δx)(y+δy)=xy+x·δy+y·δx+δx·δy

Using x1=100.000003 and y1=200.000006 we have:

x1y1=100×200+100×0.000006+200×0.000003+0.000003×0.000006=20,000+0.0006+0.0006+0.00000000018=20,000+0.0012+0.00000000018=20,000.00120000018

where it is clear that the products x·δy, y·δx and δx·δy contribute very little to the result. Furthermore, the smaller we make δx and δy, their contribution becomes even more insignificant. Just imagine if we reduce δx and δy to the level of quantum phenomenon, e.g. 10-34, then their products play no part in every-day numbers. But there is no need to stop there, we can make δx and δy as small as we like, e.g. 10-100,000,000,000. Later on we employ the device of reducing a number towards zero, such that any products involving them can be dropped from any calculation.

Even though the product of two numbers less than one is an even smaller number, care must be taken with their quotients. For example, in the above scenario, where δy=0.000006 and δx=0.000003:

δyδx=0.0000060.000003=2

so we must watch out for such quotients.

From now on I will employ the term derivative to describe a function’s rate of change relative to its independent variable. I will now describe two ways of computing a derivative, and provide a graphical interpretation of the process. The first way uses simple algebraic equations, and the second way uses a functional representation. Needless to say, they both give the same result.

19.4 Equations and Limits

19.4.1 Quadratic Function

Here  is a simple algebraic approach using limits to compute the derivative of a quadratic function. Starting with the function y=x2, let x change by δx, and let δy be the corresponding change in y. We then have:

y=x2y+δy=(x+δx)2=x2+2x·δx+(δx)2δy=2x·δx+(δx)2

Dividing throughout by δx we have:

δyδx=2x+δx

The ratio δy/δx provides a measure of how fast y changes relative to x, in increments of δx. For example, when x=10:

δyδx=20+δx

and if δx=1, then δy/δx=21. Equally, if δx=0.001, then δy/δx=20.001. By making δx smaller and smaller, δy becomes equally smaller, and their ratio converges towards a limiting value of 20.

In this case, as δx approaches zero, δy/δx approaches 2x, which is written:

limδx→0δyδx=2x

Thus in the limit, when δx=0, we create a condition where δy is divided by zero – which is a meaningless operation. However, if we hold onto the idea of a limit, as δx→0, it is obvious that the quotient δy/δx is converging towards 2x. The subterfuge employed to avoid dividing by zero is to substitute another quotient dy/dx to stand for the limiting condition:

dydx=limδx→0δyδx=2x

dy/dx (pronounced dee y dee x) is the derivative of y=x2, i.e. 2x. For instance, when x=0, dy/dx=0, and when x=3, dy/dx=6. The derivative dy/dx, is the instantaneous rate at which y changes relative to x.

If we had represented this equation as a function:

f(x)=x2f′(x)=2x

where f′(x) is another way of expressing dy/dx.

Now let’s introduce two constants into the original quadratic equation to see what effect, if any, they have on the derivative. We begin with:

y=ax2+b

and increment x and y:

y+δy=a(x+δx)2+b=ax2+2x·δx+(δx)2+bδy=a2x·δx+(δx)2

Dividing throughout by δx:

δyδx=a(2x+δx)

and the derivative is:

dydx=limδx→0δyδx=2ax

Thus we see the added constant b disappears (i.e. because it does not change), whilst the multiplied constant a is transmitted through to the derivative.

19.4.2 Cubic Equation

Now  let’s repeat the above analysis for a cubic equation y=x3:

y=x3y+δy=(x+δx)3=x3+3x2·δx+3x(δx)2+(δx)3δy=3x2·δx+3x(δx)2+(δx)3

Dividing throughout by δx:

δyδx=3x2+3x·δx+(δx)2

Employing the idea of infinitesimals, one would argue that any term involving δx can be ignored, because its numerical value is too small to make any contribution to the result. Similarly, using the idea of limits, one would argue that as δx is made increasingly smaller, towards zero, any term involving δx rapidly disappears.

Using limits, we have:

limδx→0δyδx=3x2

or

dydx=limδx→0δyδx=3x2

We could also show that if y=ax3+b then:

dydx=3ax2

This incremental technique can be used to compute the derivative of all sorts of functions.

If we continue computing the derivatives of higher-order polynomials, we discover the following pattern:

y=x2,dydx=2xy=x3,dydx=3x2y=x4,dydx=4x3y=x5,dydx=5x4

Clearly, the rule is:

y=xn,dydx=nxn-1

but we need to prove why this is so. The solution is found in the binomial expansion for (x+δx)n, which can be divided into three components:

1.

Decreasing terms of x.

2.

Increasing terms of δx.

3.

The terms of Pascal’s triangle.

For example, the individual terms of (x+δx)4 are:

which when combined produce:

x4+4x3(δx)+6x2(δx)2+4x(δx)3+(δx)4

 Thus when we begin an incremental analysis:

y=x4y+δy=(x+δx)4=x4+4x3(δx)+6x2(δx)2+4x(δx)3+(δx)4δy=4x3(δx)+6x2(δx)2+4x(δx)3+(δx)4

Dividing throughout by δx:

δyδx=4x3+6x2(δx)1+4x(δx)2+(δx)3

In the limit, as δx slides to zero, only the second term of the original binomial expansion remains:

4x3

The second term of the binomial expansion (x+δx)n is always of the form:

nxn-1

which is the proof we require.

19.4.3 Functions and Limits

In  order to generalise the above findings, let’s approach the above analysis using a function of the form y=f(x). We begin by noting some arbitrary value of its independent variable and note the function’s value. In general terms, this is x and f(x) respectively. We then increase x by a small amount δx, to give x+δx, and measure the function’s value again: f(x+δx). The function’s change in value is f(x+δx)-f(x), whilst the change in the independent variable is δx. The quotient of these two quantities approximates to the function’s rate of change at x:

f(x+δx)-f(x)δx

(19.1)

By making δx smaller and smaller towards zero, (19.1) converges towards a limiting value expressed as:

dydx=limδx→0f(x+δx)-f(x)δx

(19.2)

which can be used to compute all sorts of functions. For example, to compute the derivative of sinx we proceed as follows:

y=sinxy+δy=sin(x+δx)

Using the identity sin(A+B)=sinAcosB+cosAsinB, we have:

y+δy=sinxcos(δx)+cosxsin(δx)δy=sinxcos(δx)+cosxsin(δx)-sinx=sinx(cos(δx)-1)+cosxsin(δx)

Dividing throughout by δx we have:

δyδx=sinxδxcos(δx)-1+sin(δx)δxcosx

In the limit as δx→0, (cos(δx)-1)→0 and sin(δx)/δx=1, and:

dydx=d(sinx)dx=cosx

Before moving on, let’s compute the derivative of cosx:

y=cosxy+δy=cos(x+δx)

Using the identity cos(A+B)=cosAcosB-sinAsinB, we have:

y+δy=cosxcos(δx)-sinxsin(δx)δy=cosxcos(δx)-sinxsin(δx)-cosx=cosx(cos(δx)-1)-sinxsin(δx)

Dividing throughout by δx we have:

δyδx=cosxδxcos(δx)-1-sin(δx)δxsinx

In the limit as δx→0, (cos(δx)-1)→0 and sin(δx)/δx=1 (see Appendix A) and:

dydx=d(cosx)dx-sinx

We will continue to employ this strategy to compute the derivatives of other functions later on.

Fig. 19.1

Sketch of f(x)=x2

19.4.4 Graphical Interpretation of the Derivative

To illustrate this limiting process graphically, consider the scenario in Fig. 19.1 where the sample point is P. In this case the function is f(x)=x2 and P’s coordinates are (x,x2). We identify another point R, displaced δx to the right of P, with coordinates (x+δx,x2). The point Q on the curve, vertically above R, has coordinates (x+δx,(x+δx)2). When δx is relatively small, the slope of the line PQ approximates to the function’s rate of change at P, which is the graph’s slope. This is given by:

slope=QRPR=(x+δx)2-x2δx=x2+2x(δx)+(δx)2-x2δx=2x(δx)+(δx)2δx=2x+δx

We can now reason that as δx is made smaller and smaller, Q approaches P, and slope becomes the graph’s slope at P. This is the limiting condition:

dydx=limδx→0(2x+δx)=2x

Thus, for any point with coordinates (x,x2), the slope is given by 2x. For example, when x=0, the slope is 0, and when x=4, the slope is 8, etc.

19.4.5 Derivatives and Differentials

Given  a function f(x), the ratio df/dx represents the instantaneous change of f for some x, and is called the first derivative of f(x). For linear functions, this is constant, for other functions, the derivative’s value changes with x and is represented by a function.

The elements df, dy and dx are called differentials, and historically, the derivative used to be called the differential coefficient, but has now been dropped in favour of derivative. One can see how the idea of a differential coefficient arose if we write, for example:

dydx=3x

as

dy=3xdx

In this case, 3x acts like a coefficient of dx, nevertheless, we will use the word derivative. It is worth noting that if y=x, then dy/dx=1, or dy=dx. The two differentials are individual algebraic quantities, which permits us to write statements such as:

dydx=3x,dy=3xdx,dx=dy3x

Now let’s find dy/dx, for:

y=6x3-4x2+8x+6

Differentiating y:

dydx=18x2-8x+8

which is the instantaneous change of y relative to x. When x=1, dy/dx=18-8+8=18, which means that y is changing 18 times faster than x. Consequently, dx/dy=1/18.

19.4.6 Integration and Antiderivatives

If  it is possible to differentiate a function, it seems reasonable to assume the existence of an inverse process to convert a derivative back to its associated function. Fortunately, this is the case, but there are some limitations. This inverse process is called integration and reveals the antiderivative of a function. Many functions can be paired together in the form of a derivative and an antiderivative, such as 2x with x2, and cosx with sinx. However, there are many functions where it is impossible to derive its antiderivative in a precise form. For example, there is no simple, finite functional antiderivative for sinx2 or (sinx)/x. To understand integration, let’s begin with a simple derivative.

If we are given:

dydx=18x2-8x+8

it is not too difficult to reason that the original function could have been:

y=6x3-4x2+8x

However, it could have also been:

y=6x3-4x2+8x+2

or

y=6x3-4x2+8x+20

or with any other constant. Consequently, when integrating the original function, the integration process has to include a constant:

y=6x3-4x2+8x+C

The value of C is not always required, but it can be determined if we are given some extra information, such as y=10 when x=0, then C=10.

The notation for integration employs a curly ‘S’ symbol ∫, which may seem strange, but is short for sum and will be explained later. So, starting with:

dydx=18x2-8x+8

we rewrite this as:

dy=(18x2-8x+8)dx

and integrate both sides, where dy becomes y and the right-hand-side becomes:

∫(18x2-8x+8)dx

although brackets are not always used:

y=∫18x2-8x+8dx

This equation reads: “y is the integral of 18x2-8x+8 dee x.” The dx reminds us that x is the independent variable. In this case we can write the answer:

dy=18x2-8x+8dxy=∫18x2-8x+8dx=6x3-4x2+8x+C

where C is some constant.

For example, let’s find y, given:

dy=6x2+10xdx

Integrating:

y=∫6x2+10xdx=2x3+5x2+C

Now let’s find y, given:

dy=dx.

Integrating:

y=∫1dx=x+C

The antiderivatives for the sine and cosine functions are written:

∫sinxdx=-cosx+C∫cosxdx=sinx+C

which you may think obvious, as we have just computed their derivatives. However, the reason for introducing integration alongside differentiation, is to make you familiar with the notation, and memorise the two distinct processes, as well as lay the foundations for the next chapter.

19.5 Function Types

Mathematical functions come in all sorts of shapes and sizes. Sometimes they are described explicitly where y equals some function of its independent variable(s), such as:

y=xsinx

or implicitly where y, and its independent variable(s) are part of an equation, such as:

x2+y2=10

A function may reference other functions, such as:

y=sin(cos2x)

or

y=xsinx

There is no limit to the way functions can be combined, which makes it impossible to cover every eventuality. Nevertheless, we will explore some useful combinations that prepare us for any future surprises.

First, we examine how to differentiate different types of functions, that include sums, products and quotients, which are employed later on to differentiate specific functions such as trigonometric, logarithmic and hyperbolic. Where relevant, I include the appropriate antiderivative to complement its derivative.

19.6 Differentiating Groups of Functions

 So far we have only considered simple individual functions, which, unfortunately, do not represent the equations found in mathematics, science, physics or even computer graphics. In general, the functions we have to differentiate include sums of functions, functions of functions, function products and function quotients. Let’s explore these four scenarios.

19.6.1 Sums of Functions

 A function normally computes a numerical value from its independent variable(s), and if it can be differentiated, its derivative generates another function with the same independent variable. Consequently, if a function contains two functions of x, such as u and v, where:

y=u(x)+v(x)

which can be abbreviated to:

y=u+v

then:

dydx=dudx+dvdx

where we just sum their individual derivatives.

As an example, find dy/dx, given:

u=2x6v=3x5y=u+vy=2x6+3x5

Differentiating y:

dydx=12x5+15x4

Similarly, find dy/dx, given:

u=2x6v=sinxw=cosxy=u+v+wy=2x6+sinx+cosx

Differentiating y:

dydx=12x5+cosx-sinx

Fig. 19.2

Graph of y=2x6+sinx+cosx ((blue), and its derivative, dydx=12x5+cosx-sinx (green)

Figure 19.2 shows a graph of y=2x6+sinx+cosx and its derivative y=12x5+cosx-sinx. Differentiating such functions is relatively easy, so too, is integrating. Given:

dydx=dudx+dvdx

then:

y=∫dudxdx+∫dvdxdx=∫(dudx+dvdx)dx

For example, let’s find y, given:

dydx=12x5+cosx-sinx

Integrating:

dy=(12x5+cosx-sinx)dxy=∫12x5dx+∫cosxdx-∫sinxdx=2x6+sinx+cosx+C

19.6.2 Function of a Function

One  of the advantages of modern mathematical notation is that it lends itself to unlimited elaboration without introducing any new symbols. For example, the polynomial 3x2+2x is easily raised to some power by adding brackets and an appropriate index: (3x2+2x)2. Such an object is a function of a function, because the function 3x2+2x is subjected to a further squaring function. The question now is: how are such functions differentiated? Well, the answer is relatively easy, but does introduce some new ideas.

Imagine that Heidi swims twice as fast as John, who in turn, swims three times as fast as his dog, Monty. It should be obvious that Heidi swims six (2×3) times faster than Monty. This product rule, also applies to derivatives, because if y changes twice as fast as u, i.e. dy/du=2, and u changes three times as fast as x, i.e. du/dx=3, then y changes six times as fast as x:

dydx=dydu·dudx

To differentiate:

y=3x2+2x2

we substitute:

u=3x2+2x

then:

y=u2

and

dydu=2u=23x2+2x=6x2+4x

Next, we require du/dx:

u=3x2+2xdudx=6x+2

therefore, we can write:

dydx=dydu·dudx=6x2+4x(6x+2)=36x3+36x2+8x

This result is easily verified by expanding the original polynomial and differentiating:

y=3x2+2x2=3x2+2x3x2+2x=9x4+12x3+4x2dydx=36x3+36x2+8x

Figure 19.3 shows a graph of y=3x2+2x2 and its derivative y=36x3+36x2+8x.

Now  let’s differentiate y=sin(ax), which is a function of a function.

Fig. 19.3

Graph of y=(3x2+2x)2 (blue), and its derivative dydx=36x3+36x2+8x (green)

Substitute u for ax:

y=sinudydu=cosu=cos(ax)

Next, we require du/dx:

u=axdudx=a

therefore, we can write:

dydx=dydu·dudx=cos(ax)·a=acos(ax)

Consequently, given:

dydx=cos(ax)

then:

dy=cos(ax)dxy=∫cos(ax)dx=1asin(ax)+C

Similarly, given:

dydx=sin(ax)

then:

dy=sin(ax)dxy=∫sin(ax)dx=-1acos(ax)+C

To differentiate y=sin(x2), which is also a function of a function, we substitute u for x2:

y=sinudydu=cosu=cos(x2)

Next, we require du/dx:

u=x2dudx=2x

therefore, we can write:

dydx=dydu·dudx=cos(x2)·2x=2xcos(x2)

Fig. 19.4

Graph of y=sin(x2) (blue), and its derivative, dydx=2xcos(x2) (green)

Figure 19.4 shows a graph of y=sin(x2) and its derivative y=2xcos(x2). In general, there can be any depth of functions within a function, which permits us to write the chain rule for derivatives:

dydx=dydu·dudv·dvdw·dwdx

19.6.3 Function Products

 Function products occur frequently in every-day mathematics, and involve the product of two, or more functions. Here are three simple examples:

y=3x2+2x2x2+3xy=sinxcosxy=x2sinx

When it comes to differentiating function products of the form:

y=uv

it seems natural to assume that:

dydx=dudx·dvdx

(19.3)

which unfortunately, is incorrect. For example, in the case of:

y=3x2+2x2x2+3x

differentiating using the above rule (19.3) produces:

dydx=(6x+2)(4x+3)=24x2+26x+6

However, if we expand the original product and then differentiate, we obtain:

y=3x2+2x2x2+3x=6x4+13x3+6x2dydx=24x3+39x2+12x

which is correct, but differs from the first result. Obviously, (19.3) must be wrong. So let’s return to first principles and discover the correct rule.

So far we have incremented the independent variable – normally x – by δx to discover the change in y – normally δy. Next, we see how the same notation can be used to increment functions.

Given the following functions of x, u and v, where:

y=uv

if x increases by δx, then there will be corresponding changes of δu, δv and δy, in u, v and y respectively. Therefore:

y+δy=(u+δu)(v+δv)=uv+uδv+vδu+δuδvδy=uδv+vδu+δuδv

Dividing throughout by δx we have:

δyδx=uδvδx+vδuδx+δuδvδx

In the limiting condition:

dydx=limδx→0uδvδx+limδx→0vδuδx+limδx→0δuδvδx

As δx→0, then δu→0 and δuδvδx→0. Therefore:

dydx=udvdx+vdudx

(19.4)

Applying (19.4) to the original function product:

u=3x2+2xv=2x2+3xy=uvdudx=6x+2dvdx=4x+3dydx=udvdx+vdudx=3x2+2x(4x+3)+2x2+3x(6x+2)=12x3+17x2+6x+12x3+22x2+6x=24x3+39x2+12x

which agrees with our previous prediction. Figure 19.5 shows a graph of y=3x2+2x2x2+3x and its derivative y=24x3+39x2+12x.

Fig. 19.5

Graph of y=(3x2+2x)(2x2+3x) (blue), and its derivative dydx=24x3+39x2+12x (green)

Now let’s differentiate y=sinxcosx using (19.4).

y=sinxcosxu=sinxdudx=cosxv=cosxdvdx=-sinxdydx=udvdx+vdudx=sinx(-sinx)+cosxcosx=cos2x-sin2x=cos(2x)

Using the identity sin(2x)=2sinxcosx, we can rewrite the original function as

y=sinxcosx=12sin(2x)dydx=cos(2x)

which confirms the above derivative. Now let’s consider the antiderivative of cos2x.

Given:

dydx=cos(2x)

then:

dy=cos(2x)dxy=∫cos(2x)dx=12sin(2x)+C=sinxcosx+C

Figure 19.6 shows a graph of y=sinxcos and its derivative y=cos(2x).

Fig. 19.6

Graph of y=sinxcosx (blue), and its derivative dydx=cos(2x) (green)

Let’s differentiate y=x2sinx, using (19.4):

y=x2sinxu=x2dudx=2xv=sinxdvdx=cosxdydx=udvdx+vdudx=x2cosx+2xsinx

Figure 19.7 shows a graph of y=x2sinx and its derivative x2cosx+2xsinx.

Fig. 19.7

Graph of y=x2sinx (blue), and its derivative y=x2cosx+2xsinx (green)

19.6.4 Function Quotients

Next, we investigate how to differentiate function quotients. We begin with two functions of x, u and v, where:

y=uv

which makes y also a function of x.

We now increment x by δx and measure the change in u as δu, and the change in v as δv. Consequently, the change in y is δy:

y+δy=u+δuv+δvδy=u+δuv+δv-uv=v(u+δu)-u(v+δv)v(v+δv)=vδu-uδvv(v+δv)

Dividing throughout by δx we have:

δyδx=vδuδx-uδvδxv(v+δv)

As δx→0, δu, δv and δy also tend towards zero, and the limiting conditions are:

dydx=limδx→0δyδxvdudx=limδx→0vδuδxudvdx=limδx→0uδvδxv2=limδx→0v(v+δv)

therefore:

dydx=vdudx-udvdxv2

To illustrate this, let’s differentiate y, given:

y=x3+2x2+3x+6x2+3

Substitute u=x3+2x2+3x+6 and v=x2+3, then:

dudx=3x2+4x+3dvdx=2xdydx=x2+33x2+4x+3-x3+2x2+3x+62xx2+32=3x4+4x3+3x2+9x2+12x+9-2x4+4x3+6x2+12xx4+6x2+9=x4+6x2+9x4+6x2+9=1

which is not a surprising result when one sees that the original function has the factors:

y=x2+3(x+2)x2+3=x+2

whose derivative is 1. Figure 19.8 shows a graph of y=x2+3(x+2)/x2+3 and its derivative y=1.

Fig. 19.8

Graph of y=(x2+3)(x+2)/(x2+3) and its derivative, dydx=1 (dashed)

19.7 Differentiating Implicit Functions

Functions conveniently fall into two types: explicit and implicit. An explicit function, describes a function in terms of its independent variable(s), such as:

y=asinx+bcosx

where the value of y is determined by the values of a, b and x. On the other hand, an implicit function, such as:

x2+y2=25

combines the function’s name with its definition. In this case, it is easy to untangle the explicit form:

y=25-x2

So far, we have only considered differentiating explicit functions, so now let’s examine how to differentiate implicit functions. Let’s begin with a simple explicit function and differentiate it as it is converted into its implicit form.

Let:

y=2x2+3x+4

then:

dydx=4x+3

Now let’s start the conversion into the implicit form by bringing the constant 4 over to the left-hand side:

y-4=2x2+3x

differentiating both sides:

dydx=4x+3

Bringing 4 and 3x across to the left-hand side:

y-3x-4=2x2

differentiating both sides:

dydx-3=4xdydx=4x+3

Finally, we have:

y-2x2-3x-4=0

differentiating both sides:

dydx-4x-3=0dydx=4x+3

which seems straight forward. The reason for working through this example is to remind us that when y is differentiated we get dy/dx.

Let’s find dy/dx, given:

y+sinx+4x=0

Differentiating the individual terms:

y+sinx+4x=0dydx+cosx+4=0dydx=-cosx-4.y+x2-cosx=0dydx+2x+sinx=0dydx=-2x-sinx

But how do we differentiate y2+x2=r2? Well, the important difference between this implicit function and previous functions, is that it involves a function of a function. y is not only a function of x, but is squared, which means that we must employ the chain rule described earlier:

dydx=dydu·dudx

Therefore, given:

y2+x2=r22ydydx+2x=0dydx=-2x2y=-xr2-x2

This is readily confirmed by expressing the original function in its explicit form and differentiating:

y=r2-x212

which is a function of a function.

Let u=r2-x2, then:

dudx=-2x

As y=u12, then:

dydu=12u-12=12u12=12r2-x2

However:

dydx=dydu·dudx=-2x2r2-x2=-xr2-x2

which agrees with the implicit differentiated form.

As another example, let’s find dy/dx, given:

x2-y2+4x=6y

Differentiating the individual terms:

2x-2ydydx+4=6dydx

Rearranging the terms, we have:

2x+4=6dydx+2ydydx=dydx(6+2y)dydx=2x+46+2y

If, for example, we have to find the slope of x2-y2+4x=6y at the point (4,3), then we simply substitute x=4 and y=3 in dy/dx to obtain the answer 1.

Finally, let’s find dy/dx, given:

xn+yn=annxn-1+nyn-1dydx=0dydx=-nxn-1nyn-1dydx=-xn-1yn-1

19.8 Differentiating Exponential and Logarithmic Functions 

19.8.1 Exponential Functions

Exponential functions have the form y=ax, where the independent variable is the exponent. Such functions are used to describe various forms of growth or decay, from the compound interest law, to the rate at which a cup of tea cools down. One special value of a is 2.718282.., called e, where:

e=limn→∞1+1nn

Raising e to the power x:

ex=limn→∞1+1nnx

which, using the Binomial Theorem, is:

ex=1+x+x22!+x33!+x44!+⋯

If we let:

y=exdydx=1+x+x22!+x33!+x44!+⋯=ex.

which is itself. Figure 19.9 shows graphs of y=ex and y=e-x.

Fig. 19.9

Graphs of y=ex and y=e-x

Now let’s differentiate y=ax. We know from the rules of logarithms that:

logxn=nlogx

therefore, given:

y=ax

then:

lny=lnax=xlna

therefore:

y=exlna

which means that:

ax=exlna

Consequently:

ddxax=ddxexlna=lnaexlna=axlna

Similarly, it can be shown that:

y=e-x,dydx=-e-xy=eax,dydx=aeaxy=e-ax,dydx=-ae-axy=ax,dydx=lnaaxy=a-x,dydx=-lnaa-x

The exponential antiderivatives are written:

∫exdx=ex+C∫e-xdx=-e-x+C∫eaxdx=1aeax+C∫e-axdx=-1ae-ax+C∫axdx=1lnaax+C∫a-xdx=-1lnaa-x+C

19.8.2 Logarithmic Functions

Given a function of the form:

y=lnx

then:

x=ey

Therefore:

dxdy=ey=xdydx=1x

Thus:

ddxlnx=1x

Figure 19.10 shows the graph of y=lnx and its derivative y=1/x. Conversely:

∫1xdx=ln|x|+C

Fig. 19.10

Graph of y=lnx (blue), and its derivative, dydx=1x (green)

When differentiating logarithms to a base a, we employ the conversion formula:

y=logax=(lnx)(logae)

whose derivative is:

dydx=1xlogae

When a=10, then log10e=0.4343⋯ and:

ddxlog10x≈0.4343x

Figure 19.11 shows the graph of y=log10x and its derivative y≈0.4343/x.

Fig. 19.11

Graph of y=log10x (blue), and its derivative, dydx≈0.4343x (green)

19.9 Differentiating Trigonometric Functions

We have only differentiated two trigonometric functions: sinx and cosx, so let’s add tanx, cscx, secx and cotx to the list, as well as their inverse forms.

19.9.1 Differentiating tan

Rather than return to first principles and start incrementing x by δx, we can employ the rules for differentiating different function combinations and various trigonometric identities. In the case of tan(ax), this can be written as:

tan(ax)=sin(ax)cos(ax)

and employ the quotient rule:

dydx=vdudx-udvdxv2

Therefore, let u=sin(ax) and v=cos(ax), and:

dydx=acos(ax)cos(ax)+asin(ax)sin(ax)cos2(ax)=a(cos2(ax)+sin2(ax))cos2(ax)=acos2(ax)=asec2(ax)=a(1+tan2(ax))

Figure 19.12 shows the graph of y=tanx and its derivative y=1+tan2x.

It follows that:

∫sec2(ax)dx=1atan(ax)+C

Fig. 19.12

Graph of y=tanx (blue), and its derivative, dydx=1+tan2x (green)

19.9.2 Differentiating csc

Using the quotient rule:

y=csc(ax)=1sin(ax)dydx=0-acos(ax)sin2(ax)=-acos(ax)sin2(ax)=-asin(ax)·cos(ax)sin(ax)=-acsc(ax)·cot(ax)

Figure 19.13 shows the graph of y=cscx and its derivative y=-cscxcotx.

It follows that:

∫csc(ax)·cot(ax)dx=-1acsc(ax)+C

Fig. 19.13

Graph of y=cscx (blue), and its derivative, dydx=-cscxcotx (green)

19.9.3 Differentiating sec

Using the quotient rule:

y=sec(ax)=1cos(ax)dydx=-(-asin(ax))cos2(ax)=asin(ax)cos2(ax)=acos(ax)·sin(ax)cos(ax)=asec(ax)·tan(ax)

Figure 19.14 shows the graph of y=secx and its derivative y=secxtanx.

It follows that:

∫sec(ax)·tan(ax)dx=1asec(ax)+C

Fig. 19.14

Graph of y=secx (blue), and its derivative, dydx=secxtanx (green)

19.9.4 Differentiating cot

Using the quotient rule:

y=cot(ax)=1tan(ax)dydx=-asec2(ax)tan2(ax)=-acos2(ax)·cos2(ax)sin2(ax)=-asin2(ax)=-acsc2(ax)=-a1+cot2(ax)

Figure 19.15 shows the graph of y=cotx and its derivative y=-(1+cot2x).

It follows that:

∫csc2(ax)dx=-1acot(ax)+C

Fig. 19.15

Graph of y=cotx (blue), and its derivative, dydx=-(1+cot2x) (green)

19.9.5 Differentiating arcsin, arccos and arctan          

These inverse functions are solved using a clever strategy.

Let:

x=siny

then:

y=arcsinx

Differentiating the first expression, we have:

dxdy=cosydydx=1cosy

and as sin2y+cos2y=1, then:

cosy=1-sin2y=1-x2

and

ddxarcsinx=11-x2

Using a similar technique, it can be shown that:

ddxarccosx=-11-x2ddxarctanx=11+x2

It follows that:

∫dx1-x2=arcsinx+C∫dx1+x2=arctanx+C

19.9.6 Differentiating arccsc, arcsec and arccot           

Let:

y=arccscx

then:

x=cscy=1sinydxdy=-cosysin2ydydx=-sin2ycosy=-1x2xx2-1ddxarccscx=-1xx2-1

Similarly:

ddxarcsecx=1xx2-1ddxarccotx=-1x2+1

It follows:

∫dxxx2-1=arcsec|x|+C∫dxx2+1=-arccotx+C

19.10 Differentiating Hyperbolic Functions 

Trigonometric functions are useful for parametric, circular motion, whereas hyperbolic functions arise in equations for the absorption of light, mechanics and in integral calculus. Figure 19.16 shows graphs of the unit circle and a hyperbola whose respective equations are:

x2+y2=1x2-y2=1

where the only difference between them is a sign. The parametric form for the trigonometric, or circular functions and the hyperbolic functions are respectively:

sin2θ+cos2θ=1cosh2x-sinh2x=1

The three hyperbolic functions have the following definitions:

sinhx=ex-e-x2coshx=ex+e-x2tanhx=sinhxcoshx=e2x-1e2x+1

and their reciprocals are:

cosechx=1sinhx=2ex-e-xsechx=1coshx=2ex+e-xcothx=1tanhx=e2x+1e2x-1

Other useful identities include:

sech2x=1-tanh2xcosech2x=coth2x-1

The coordinates of P and Q in Fig. 19.16 are given by P(cosθ,sinθ) and Q(coshx,sinhx).

Fig. 19.16

Graphs of the unit circle x2+y2=1 and the hyperbola x2-y2=1

Table 19.1 shows the names of the three hyperbolic functions, their reciprocals and inverse forms. As these functions are based upon ex and e-x, they are relatively easy to differentiate.

Table 19.1

Hyperbolic function names

Function

Reciprocal

Inverse function

Inverse reciprocal

sinh

cosech

arsinh

arcsch

cosh

sech

arcosh

arsech

tanh

coth

artanh

arcoth

Table 19.2

Differentiating hyperbolic functions

y

dy/dx

sinhx

coshx

coshx

sinhx

tanhx

sech2x

cosechx

-cosechx·cothx

sechx

-sechx·tanhx

cothx

-cosech2x

19.10.1 Differentiating sinh, cosh and tanh     

Table 19.2 shows the rules for differentiating hyperbolic functions, and Table 19.3 the rules for differentiating inverse, hyperbolic functions.

Table 19.4 shows some of the rules for integrating hyperbolic functions, and Table 19.5 the rules for integrating inverse, hyperbolic functions.

Table 19.3

Differentiating inverse hyperbolic functions

y

dy/dx

arsinhx

11+x2

arcoshx

1x2-1

artanhx

11-x2

arcschx

-1x1+x2

arsechx

-1x1-x2

arcothx

-1x2-1

Table 19.4

Integrating hyperbolic functions

f(x)

∫f(x)dx

sinhx

coshx+C

coshx

sinhx+C

sech2x

tanhx+C

Table 19.5

Integrating inverse hyperbolic functions

f(x)

∫f(x)dx

11+x2

arsinhx+C

1x2-1

arcoshx+C

11-x2

artanhx+C.

19.11 Higher Derivatives 

There are three parts to this section: The first part shows what happens when a function is repeatedly differentiated; the second shows how these higher derivatives resolve local minimum and maximum conditions; and the third section provides a physical interpretation for these derivatives. Let’s begin by finding the higher derivatives of simple polynomials.

19.12 Higher Derivatives of a Polynomial

We have previously seen that polynomials of the form:

y=axr+bxs+cxt…

are differentiated as follows:

dydx=raxr-1+sbxs-1+tcxt-1…

For example, given:

y=3x3+2x2-5x

then:

dydx=9x2+4x-5

which describes how the slope of the original function changes with x.

Fig. 19.17

Graph of y=3x3+2x2-5x (blue), and its derivative dydx=9x2+4x-5 (green)

Figure 19.17 shows the graph of y=3x3+2x2-5x and its derivative y=9x2+4x-5, and we can see that when x=-1 there is a local maximum, where the function reaches a value of 4, then begins a downward journey to 0, where the slope is -5. Similarly, when x≃0.55, there is a point where the function reaches a local minimum with a value of approximately -1.65. The slope is zero at both points, which is reflected in the graph of the derivative.

Having differentiated the function once, there is nothing to prevent us differentiating a second time, but first we require a way to annotate the process, which is performed as follows. At a general level, let y be some function of x, then the first derivative is:

ddx(y)

The second derivative is found by differentiating the first derivative:

ddxdydx

and is written:

d2ydx2

Similarly, the third derivative is:

d3ydx3

and the nth derivative:

dnydxn

When a function is expressed as f(x), its derivative is written f′(x). The second derivative is written f′′(x), and so on for higher derivatives.

Returning to the original function, the first and second derivatives are:

dydx=9x2+4x-5d2ydx2=18x+4

and the third and fourth derivatives are:

d3ydx3=18d4ydx4=0

Fig. 19.18

Graph of y=3x3+2x2-5x (blue), its first derivative dydx=9x2+4x-5 (green), and its second derivative d2ydx2=18x+4 red

Figure 19.18 shows the original function and the first two derivatives. The graph of the first derivative shows the slope of the original function, whereas the graph of the second derivative shows the slope of the first derivative. These graphs help us identify a local maximum and minimum. By inspection of Fig. 19.18, when the first derivative equals zero, there is a local maximum or a local minimum. Algebraically, this is when:

dydx=09x2+4x-5=0

Solving this quadratic in x we have:

x=-b±b2-4ac2a

where a=9,   b=4,   c=-5:

x=-4±16+18018x1=-1,x2=0.5¯

which confirms our earlier analysis. However, what we don’t know, without referring to the graphs, whether it is a minimum, or a maximum.

19.13 Identifying a Local Maximum or Minimum   

Figure 19.19 shows a function containing a local maximum of 5 when x=-1. Note that as the independent variable x, increases from -2 towards 0, the slope of the graph changes from positive to negative, passing through zero at x=-1. This is shown in the function’s first derivative, which is the straight line passing through the points (-2,6),(-1,0) and (0,-6). A natural consequence of these conditions implies that the slope of the first derivative must be negative:

d2ydx2=-ve

Figure 19.20 shows another function containing a local minimum of -5 when x=-1. Note that as the independent variable x, increases from -2 towards 0, the slope of the graph changes from negative to positive, passing through zero at x=-1. This is shown in the function’s first derivative, which is the straight line passing through the points (-2,-6),(-1,0) and (0,6). A natural consequence of these conditions implies that the slope of the first derivative must be positive:

d2ydx2=+ve

We can now apply this observation to the original function for the two values of x, x1=-1,x2=0.5¯:

dydx=9x2+4x-5d2ydx2=18x+4

x=-1,d2ydx2=18×(-1)+4=-14x=0.5¯,d2ydx2=18×(0.5¯)+4=14

Which confirms that when x=-1 there is a local maximum, and when x=0.5¯, there is a local minimum, as shown in Fig. 19.17.

Fig. 19.19

A function containing a local maximum (blue), and its first derivative (green)

Fig. 19.20

A function containing a local minimum (blue), and its first derivative (green)

Now let’s find the local minimum and maximum for y, given:

y=-3x3+9x

The first derivative is:

dydx=-9x2+9

and second derivative:

d2ydx2=-18x

as shown in Fig. 19.21. For a local maximum or minimum, the first derivative equals zero:

-9x2+9=0

which implies that x=±1.

The sign of the second derivative determines whether there is a local minimum or maximum.

d2ydx2=-18x=-18×(-1)=+ve=-18×(+1)=-ve

therefore, when x=-1 there is a local minimum, and when x=+1 there is a local maximum, as confirmed by Fig. 19.21.

Fig. 19.21

Graph of y=-3x3+9x (blue), its first derivative y=-9x2+9 (green) and its second derivative y=-18x red

19.14 Partial Derivatives   

Up to this point we have used functions with one independent variable, such as y=f(x). However, we must be able to compute derivatives of functions with more than one independent variable, such as y=f(u,v,w). The technique employed is to assume that only one variable changes, whilst the other variables are held constant. This means that a function can possess several derivatives – one for each independent variable. Such derivatives are called partial derivatives and employ a new symbol ∂, which can be read as ‘partial dee’.

Given a function f(u, v, w), the three partial derivatives are defined as

∂f∂u=limh→0f(u+h,v,w)-f(u,v,w)h∂f∂v=limh→0f(u,v+h,w)-f(u,v,w)h∂f∂w=limh→0f(u,v,w+h)-f(u,v,w)h

For example, a function for the volume of a cylinder is:

V(r,h)=πr2h

where r is the radius, and h is the height. Say we wish to compute the function’s partial derivative with respect to r. First, the partial derivative is written:

∂V∂r

Second, we hold h constant, whilst allowing r to change. This means that the function becomes:

V(r,h)=kr2

(19.5)

where k=πh. Thus the partial derivative of (19.5) with respect to r is:

∂V∂r=2kr=2πhr

Next, by holding r constant, and allowing h to change, we have:

∂V∂h=πr2

Sometimes, for purposes of clarification, the partial derivatives identify the constant variable(s):

∂V∂rh=2πhr∂V∂hr=πr2

  Partial differentiation is subject to the same rules for ordinary differentiation – we just to have to remember which independent variable changes, and those held constant. As with ordinary derivatives, we can compute higher-order partial derivatives.

As an example, let’s find the second-order partial derivatives of f, given:

f(u,v)=u4+2u3v2-4v3

The first partial derivatives are:

∂f∂u=4u3+6u2v2∂f∂v=4u3v-12v2

and the second-order partial derivatives are:

∂2f∂u2=12u2+12uv2∂2f∂v2=4u3-24v

Now let’s find the second-order partial derivatives of f, given:

f(u,v)=sin(4u)cos(5v)

the first partial derivatives are:

∂f∂u=4cos(4u)cos(5v)∂f∂v=-5sin(4u)sin(5v)

and the second-order partial derivatives are:

∂2f∂u2=-16sin(4u)cos(5v)∂2f∂v2=-25sin(4u)cos(5v)

 In general, given f(u,v)=uv, then:

∂f∂u=v∂f∂v=u

and the second-order partial derivatives are:

∂2f∂u2=0∂2f∂v2=0

Similarly, given f(u,v)=u/v, then:

∂f∂u=1v∂f∂v=-uv2

and the second-order partial derivatives are:

∂2f∂u2=0∂2f∂v2=2uv3

Finally, given f(u,v)=uv, then:

∂f∂u=vuv-1

whereas, ∂f/∂v requires some explaining. First, given:

f(u,v)=uv

taking natural logs of both sides, we have:

lnf(u,v)=vlnu

and

f(u,v)=evlnu

Therefore:

∂f∂v=evlnulnu=uvlnu

The second-order partial derivatives are:

∂2f∂u2=v(v-1)uv-2∂2f∂v2=uvln2u

19.14.1 Visualising Partial Derivatives 

Functions of the form y=f(x) are represented by a 2D graph, and the function’s derivative f′(x) represents the graph’s slope at any point x. Functions of the form z=f(x,y) can be represented by a 3D surface, like the one shown in Fig. 19.22, which is z(x,y)=2.5x2-2.5y2. The two partial derivatives are:

∂z∂x=8x∂z∂y=-4y

where ∂z/∂x is the slope of the surface in the x-direction, as shown in Fig. 19.23, and ∂z/∂y is the slope of the surface in the y-direction, as shown in Fig. 19.24.

The second-order partial derivatives are:

∂2z∂x2=8=+ve∂2z∂y2=-4=-ve

As ∂2z/∂x2 is positive, there is a local minimum in the x-direction, and as ∂2z/∂y2 is negative, there is a local maximum in the y-direction, as confirmed by Fig. 19.23.

Fig. 19.22

Surface of z=2.5x2-2.5y2 using a right-handed axial system with a vertical z-axis

Fig. 19.23

∂z∂x describes the slopes of these contour lines

Fig. 19.24

∂z∂y describes the slopes of these contour lines

19.14.2 Mixed Partial Derivatives   

We have seen that, given a function of the form f(u, v), the partial derivatives ∂f/∂u and ∂f/∂v provide the relative instantaneous changes in f and u, and f and v, respectively, whilst the second independent variable remains fixed. However, nothing prevents us from differentiating ∂f/∂u with respect to v, whilst keeping u constant:

∂∂v∂f∂u

which is also written as:

∂2f∂v∂u

and is a mixed partial derivative.

As an example, let’s find the mixed partial derivative of f, given:

f(u,v)=u3v4

Therefore:

∂f∂u=3u2v4

and

∂2f∂v∂u=12u2v3

It should be no surprise that reversing the differentiation gives the same result. Let:

f(u,v)=u3v4

then:

∂f∂v=4u3v3

and

∂2f∂u∂v=12u2v3

Generally, for continuous functions, we can write:

∂2f∂u∂v=∂2f∂v∂u

Let’s look at two examples. The formula for the volume of a cylinder is given by V(r,h)=πr2h, where r and h are the cylinder’s radius and height, respectively. The mixed partial derivative is computed as follows.

V(r,h)=πr2h∂V∂r=2πhr∂2V∂h∂r=2πr

or

V(r,h)=πr2h∂V∂h=πr2∂2V∂r∂h=2πr

Given:

f(u,v)=sin(4u)cos(3v)

then:

∂f∂u=4cos(4u)cos(3v)∂2f∂v∂u=-12cos(4u)sin(3v)

or

∂f∂v=-3sin(4u)sin(3v)∂2f∂u∂v=-12cos(4u)sin(3v)

19.15 Chain Rule   

Earlier, we came across the chain rule for computing the derivatives of functions of functions. For example, to compute the derivative of y=sin(x2) we substitute u=x2, then

y=sinudydu=cosu=cos(x2)

Next, we compute du/dx:

u=x2dudx=2x

and dy/dx is the product of the two derivatives using the chain rule:

dydx=dydu·dudx=cos(x2)2x=2xcos(x2)

But say we have a function where w is a function of two variables x and y, which in turn, are a function of u and v. Then we have:

w=f(x,y)x=r(u,v)y=s(u,v)

With such a scenario, we have the following partial derivatives:

∂w∂x,∂w∂y∂w∂u,∂w∂v∂x∂u,∂x∂v∂y∂u,∂y∂v

These are chained together as follows:

∂w∂u=∂w∂x·∂x∂u+∂w∂y·∂y∂u

(19.6)

∂w∂v=∂w∂x·∂x∂v+∂w∂y·∂y∂v

(19.7)

Here is an example of the chain rule. Find ∂w/∂u and ∂w/∂v, given:

w=f(2x+3y)x=r(u2+v2)y=s(u2-v2)

Therefore:

∂w∂x=2,∂w∂y=3∂x∂u=2u,∂x∂v=2v∂y∂u=2u,∂y∂v=-2v

and plugging these into (19.6) and (19.7) we have:

∂w∂u=∂w∂x∂x∂u+∂w∂y∂y∂u=2×2u+3×2u=10u∂w∂v=∂w∂x∂x∂v+∂w∂y∂y∂v=2×2v+3×(-2v)=-2v

Thus, when u=2 and v=1:

∂w∂u=20,and∂w∂v=-2

19.16 Total Derivative   

Given a function with three independent variables, such as w=f(x,y,t), where x=g(t) and y=h(t), there are three primary partial derivatives:

∂w∂x,∂w∂y,∂w∂t

which show the differential change of w with x, y and t respectively. There are also three derivatives:

dxdt,dydt,dtdt

where dt/dt=1. The partial and ordinary derivatives can be combined to create the total derivative which is written:

dwdt=∂w∂xdxdt+∂w∂ydydt+∂w∂t

dw/dt measures the instantaneous change of w relative to t, when all three independent variables change.

Let’s find dw/dt, given:

w=x2+xy+y3+t2x=2ty=t-1

Therefore:

dxdt=2dydt=1∂w∂x=2x+y=4t+t-1=5t-1∂w∂y=x+3y2=2t+3(t-1)2=3t2-4t+3∂w∂t=2tdwdt=∂w∂xdxdt+∂w∂ydydt+∂w∂t=(5t-1)2+(3t2-4t+3)+2t=3t2+8t+1

and the total derivative equals:

dwdt=3t2+8t+1

and when t=1, dw/dt=12.

19.17 Summary

This chapter has shown how limits provide a useful tool for computing a function’s derivative. Basically, the function’s independent variable is disturbed by a very small quantity, typically δx, which alters the function’s value. The quotient:

f(x+δx)-f(x)δx

is a measure of the function’s rate of change relative to its independent variable. By making δx smaller and smaller towards zero, we converge towards a limiting value called the function’s derivative. Unfortunately, not all functions possess a derivative, therefore we can only work with functions that can be differentiated.

We have seen how to differentiate generic functions such as sums, products, quotients and a function of a function, and we have also seen how to address explicit and implicit forms. These techniques were then used to differentiate exponential, logarithmic, trigonometric and hyperbolic functions, which will be employed in later chapters to solve various problems. Where relevant, integrals of certain functions have been included to show the intimate relationship between derivatives and antiderivatives.

Hopefully, it is now clear that differentiation is like an operator—in that it describes how fast a function changes relative to its independent variable in the form of another function.

Reference

1.

Vince JA (2022) Calculus for computer graphics, 6th edn. Springer

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_20

20. Calculus: Integration

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

20.1 Introduction

In this chapter I develop the idea that integration is the inverse of differentiation, and examine standard algebraic strategies for integrating functions, where the derivative is unknown; these include simple algebraic manipulation, trigonometric identities, integration by parts, integration by substitution and integration using partial fractions.

20.2 Indefinite Integral

In  the previous chapter we have seen that given a simple function, such as:

y=sinx+23dydx=cosx

and the constant term 23 disappears. Inverting the process, we begin with:

dy=cosxdx

and integrating:

y=∫cosxdx=sinx+C

An integral of the form:

∫f(x)dx

is known as an indefinite integral; and as we don’t know whether the original function contains a constant term, a constant C has to be included. Its value remains undetermined unless we are told something about the original function. In this example, if we are told that when x=π/2, y=24, then:

24=sin(π/2)+C=1+CC=23

Fig. 20.1

A discontinuous square-wave function

20.3 Integration Techniques 

20.3.1 Continuous Functions   

Functions come in all sorts of shapes and sizes, which is why we have to be very careful before they are differentiated or integrated. If a function contains any form of discontinuity, then it cannot be differentiated or integrated. For example, the square-wave function shown in Fig. 20.1 cannot be differentiated as it contains discontinuities. Consequently, to be very precise, we identify an interval [a,b], over which a function is analysed, and stipulate that it must be continuous over this interval. For example, a and b define the upper and lower bounds of the interval such that:

a≤x≤b

then we can say that for f(x) to be continuous:

limh→0f(x+h)=f(x)

Even this needs further clarification as h must not take x outside of the permitted interval. So, from now on, we assume that all functions are continuous and can be integrated without fear of singularities.

20.3.2 Difficult Functions 

There are many functions that cannot be differentiated and represented by a finite collection of elementary functions. For example, the derivative f′(x)=(sinx)/x does not exist, which precludes the possibility of its integration. Figure 20.2 shows this function, and even though it is continuous, its derivative and integral can only be approximated. Similarly, the derivative f′(x)=xsinx does not exist, and also precludes the possibility of its integration. Figure 20.3 shows this continuous function. So now let’s examine how most functions have to be rearranged to secure their integration.

Fig. 20.2

Graph of y=(sinx)/x

Fig. 20.3

Graph of y=xsinx

20.3.3 Trigonometric Identities 

Sometimes it is possible to simplify the integrand by substituting a trigonometric identity. To illustrate this, let’s evaluate ∫sin2xdx, ∫cos2xdx, ∫tan2xdx and ∫sin(3x)cosxdx.

The identity sin2x=12(1-cos(2x)) converts sin2x into a double-angle form:

∫sin2xdx=12∫1-cos(2x)dx=12∫dx-12∫cos(2x)dx=12x-14sin(2x)+C

Figure 20.4 shows the graphs of y=sin2x and y=12x-14sin(2x).

Fig. 20.4

The graphs of y=sin2x (green), and y=12x-14sin(2x) (blue)

The identity cos2x=12(cos(2x)+1) converts cos2x into a double-angle form:

∫cos2xdx=12∫cos(2x)+1dx=12∫cos(2x)dx+12∫dx=14sin(2x)+12x+C

Figure 20.5 shows the graphs of y=cos2x and y=14sin(2x)+12x.

Fig. 20.5

The graphs of y=cos2x (green), and y=14sin(2x)+12x (blue)

The identity sec2x=1+tan2x, permits us to write:

∫tan2xdx=∫sec2x-1dx=∫sec2xdx-∫dx=tanx-x+C

Fig. 20.6

The graphs of y=tan2x (green), and y=tanx-x (blue)

Figure 20.6 shows the graphs of y=tan2x and y=tanx-x.

Finally, to evaluate ∫sin(3x)cosxdx we use the identity:

2sinacosb=sin(a+b)+sin(a-b)

which converts the integrand’s product into the sum and difference of two angles:

sin(3x)cosx=12(sin(4x)+sin(2x))∫sin(3x)cosxdx=12∫sin(4x)+sin(2x)dx=12∫sin(4x)dx+12∫sin(2x)dx=-18cos(4x)-14cos(2x)+C

Figure 20.7 shows the graphs of y=sin(3x)cosx and y=-18cos(4x)-14cos(2x).

Fig. 20.7

The graphs of y=sin(3x)cosx (green), and y=-18cos(4x)-14cos(2x) (blue)

20.3.4 Exponent Notation 

Radicals are best replaced by their equivalent exponent notation. For example, to evaluate:

∫2x4dx

we proceed as follows:

The constant 2 is moved outside the integral, and the integrand is converted into an exponent form:

2∫1x4dx=2∫x-14=2x3434+C=243x34+C=83x34+C

Figure 20.8 shows the graphs of y=2/x4 and y=8x34/3.

Fig. 20.8

The graphs of y=2/x4 (green), and y=8x34/3 (blue)

20.3.5 Completing the Square

Where possible, see if an integrand can be simplified by completing the square. For example, to evaluate:

∫1x2-4x+8dx

we proceed as follows:

We have already seen that:

∫11+x2dx=arctanx+C

and it’s not too difficult to prove that:

∫1a2+x2dx=1aarctanxa+C

Therefore, if we can manipulate an integrand into this form, then the integral will reduce to an arctan result. The following needs no manipulation:

∫14+x2dx=12arctanx2+C

However, the original integrand has x2-4x+8 as the denominator, which is resolved by completing the square:

x2-4x+8=4+(x-2)2

Therefore:

∫1x2-4x+8dx=∫122+(x-2)2dx=12arctan(x-22)+C

Figure 20.9 shows the graphs of y=1/(x2-4x+8) and y=12arctanx-22.

Fig. 20.9

The graphs of y=1/(x2-4x+8) (green), and y=12arctanx-22 (blue)

Fig. 20.10

The graphs of y=1/(x2+6x+10) (green), and y=arctan(x+3) (blue)

To evaluate:

∫1x2+6x+10dx

we factorize the denominator:

∫1x2+6x+10dx=∫112+(x+3)2dx=arctan(x+3)+C

Figure 20.10 shows the graphs of y=1/(x2+6x+10) and y=arctan(x+3).

20.3.6 The Integrand Contains a Derivative 

An integral of the form:

∫f(x)f′(x)dx

is relatively easy to integrate. For example, let’s evaluate:

∫arctanx1+x2dx

Knowing that:

ddxarctanx=11+x2

let u=arctanx, then:

dudx=11+x2

and

∫arctanx1+x2dx=∫udu=12u2+C=12(arctanx)2+C

Figure 20.11 shows the graphs of y=arctanx1+x2 and y=12(arctanx)2.

Fig. 20.11

The graphs of y=arctanx1+x2 (green), and y=12(arctanx)2 (blue)

An integral of the form:

∫f′(x)f(x)dx

is also relatively easy to integrate. For example, let’s evaluate:

∫cosxsinxdx

Knowing that:

ddxsinx=cosx

let u=sinx, then:

dudx=cosx

and

∫cosxsinxdx=∫1udu=ln|u|+C=ln|sinx|+C

Figure 20.12 shows the graphs of y=cosx/sinx and y=ln|sinx|.

Fig. 20.12

The graphs of y=cosx/sinx (green), and y=ln|sinx| (blue)

20.3.7 Converting the Integrand into a Series of Fractions

Integration is often made easier by converting an integrand into a series of fractions. For example, to integrate:

∫4x3+x2-8+12xcosx4xdx

we divide the numerator by 4x:

∫4x3+x2-8+12xcosx4xdx=∫x2dx+∫x4dx-∫2xdx+∫3cosxdx=13x3+18x2-2ln|x|+3sinx+C

Figure 20.13 shows the graphs of y=4x3+x2-8+12xcosx/4x and y=13x3+18x2-2ln|x|+3sinx.

Fig. 20.13

The graphs of y=(4x3+x2-8+12xcosx)/4x (green), and y=13x3+18x2-2ln|x|+3sinx (blue)

20.3.8 Integration by Parts 

Integration by parts is based upon the rule for differentiating function products where:

ddxuv=udvdx+vdudx

therefore:

uv=∫uv′dx+∫vu′dx

which rearranged, gives:

∫uv′dx=uv-∫vu′dx

Thus, if an integrand contains a product of two functions, we can attempt to integrate it by parts. For example, let’s evaluate:

∫xsinxdx

In this case, we try the following:

u=xandv′=sinx

therefore:

u′=1andv=C1-cosx

Integrating by parts:

∫uv′dx=uv-∫vu′dx∫xsinxdx=x(C1-cosx)-∫(C1-cosx)(1)dx=C1x-xcosx-C1x+sinx+C=-xcosx+sinx+C

Figure 20.14 shows the graphs of y=xsinx and y=-xcosx+sinx.

Note the problems that arise if we make the wrong substitution:

u=sinxandv′=x

therefore:

u′=cosxandv=12x2+C1

Integrating by parts:

∫uv′dx=uv-∫vu′dx∫xsinxdx=sinx12x2+C1-∫12x2+C1cosxdx

which requires to be integrated by parts, and is even more difficult, which suggests the substitution was not useful.

Fig. 20.14

The graphs of y=xsinx (green), and y=-xcosx+sinx (blue)

Now let’s evaluate:

∫x2cosxdx

In this case, we try the following:

u=x2andv′=cosx

therefore:

u′=2xandv=sinx+C1

Integrating by parts:

∫uv′dx=uv-∫vu′dx∫x2cosxdx=x2(sinx+C1)-2∫(sinx+C1)(x)dx=x2sinx+C1x2-2C1∫xdx-2∫xsinxdx=x2sinx+C1x2-2C112x2+C2-2∫xsinxdx=x2sinx-C3-2∫xsinxdx

At this point we come across ∫xsinxdx, which we have already solved:

∫x2cosxdx=x2sinx-C3-2(-xcosx+sinx+C4)=x2sinx-C3+2xcosx-2sinx-C5=x2sinx+2xcosx-2sinx+C

Figure 20.15 shows the graphs of y=x2cosx and y=x2sinx+2xcosx-2sinx.

Fig. 20.15

The graphs of y=x2cosx (green), and y=x2sinx+2xcosx-2sinx (blue)

Now let’s evaluate:

∫xlnxdx

In this case, we try the following:

u=lnxandv′=x

therefore:

u′=1xandv=12x2

Integrating by parts:

∫uv′dx=uv-∫vu′dx∫xlnxdx=12x2lnx-∫(12x2)1xdx=12x2lnx-12∫xdx=12x2lnx-14x2+C

Figure 20.16 shows the graphs of y=xlnx and y=12x2lnx-14x2.

Fig. 20.16

The graphs of y=xlnx (green), and y=12x2lnx-14x2 (blue)

Finally, let’s evaluate:

∫1+x2dx

Although this integrand does not look as though it can be integrated by parts, if we rewrite it as:

∫1+x2(1)dx

then we can use the formula.

Let:

u=1+x2andv′=1

therefore:

u′=x1+x2andv=x

Integrating by parts:

∫uv′dx=uv-∫vu′dx∫1+x2dx=x1+x2-∫x21+x2dx

Now we simplify the right-hand integrand:

∫1+x2dx=x1+x2-∫(1+x2)-11+x2dx=x1+x2-∫1+x21+x2dx+∫11+x2dx=x1+x2-∫1+x2dx+arsinhx+C1

Now we have the original integrand on the right-hand side, therefore:

2∫1+x2dx=x1+x2+arsinhx+C1∫1+x2dx=12x1+x2+12arsinhx+C

Figure 20.17 shows the graphs of y=1+x2 and y=12x1+x2+12arsinhx.

Fig. 20.17

The graphs of y=1+x2 (green), and y=12x1+x2+12arsinhx (blue)

20.3.9 Integration by Substitution 

Integration by substitution is based upon the chain rule for differentiating a function of a function, which states that if y is a function of u, which in turn is a function of x, then:

dydx=dydududx

For example, let’s evaluate:

∫x2x3dx

This is easily solved by rewriting the integrand:

∫x2x3dx=∫x72dx=29x92+C

However, introducing a constant term within the square-root requires integration by substitution. For example:

evaluate∫x2x3+1dx

First, we let u=x3+1, then:

dudx=3x2ordx=du3x2

Substituting u and dx in the integrand gives:

∫x2x3+1dx=∫x2udu3x2=13∫udu=13∫u12du=13·23u32+C=29x3+132+C

Figure 20.18 shows the graphs of y=x2x3+1 and y=29x3+132.

Fig. 20.18

The graphs of y=x2x3+1 (green), and y=29(x3+1)32 (blue)

Now let’s evaluate:

∫2sinx·cosxdx

Integrating by substitution we let u=sinx, then:

dudx=cosxordx=ducosx

Substituting u and dx in the integrand gives:

∫2sinx·cosxdx=2∫ucosxducosx=2∫udu=u2+C1=sin2x+C

Figure 20.19 shows the graphs of y=2sinx·cosx and y=sin2x.

Fig. 20.19

The graphs of y=2sinx·cosx (green), and y=sin2x (blue)

To evaluate:

∫2ecos2xsinx·cosxdx

we integrate by substitution, and let u=cos(2x), then:

dudx=-2sin(2x)ordx=-du2sin(2x)

Substituting a double-angle identity, u and du:

∫2ecos2xsinx·cosxdx=-∫eusin(2x)du2sin(2x)=-12∫eudu=-12eu+C=-12ecos(2x)+C

Figure 20.20 shows the graphs of y=2ecos(2x)sinx·cosx and y=-12ecos(2x).

Fig. 20.20

The graphs of y=2ecos(2x)sinx·cosx (green), and y=-12ecos(2x) (blue)

To evaluate:

∫cosx(1+sinx)3dx

we integrate by substitution, and let u=1+sinx, then:

dudx=cosxordx=ducosx

∫cosx(1+sinx)3dx=∫cosxu3ducosx=∫u-3du=-12u-2+C=-12(1+sinx)-2+C=-12(1+sinx)2+C

Figure 20.21 shows the graphs of y=cosx/(1+sinx)3 and y=-12(1+sinx)-2.

Fig. 20.21

The graphs of y=cosx/(1+sinx)3 (green), and y=-12(1+sinx)-2 (blue)

To evaluate:

∫sin(2x)dx

we integrate by substitution, and let u=2x, then:

dudx=2ordx=du2

∫sin(2x)dx=12∫sinudu=-12cosu+C=-12cos(2x)+C

Figure 20.22 shows the graphs of y=sin(2x) and y=-12cos(2x).

Fig. 20.22

The graphs of y=sin(2x) (green), and y=-12cos(2x) (blue)

20.3.10 Partial Fractions 

Integration by partial fractions is used when an integrand’s denominator contains a product that can be split into two fractions. For example, it should be possible to convert:

∫3x+4(x+1)(x+2)dx

into:

∫Ax+1dx+∫Bx+2dx

which individually, are easy to integrate. Let’s compute A and B:

3x+4(x+1)(x+2)=Ax+1+Bx+23x+4=A(x+2)+B(x+1)=Ax+2A+Bx+B

Equating constants and terms in x:

4=2A+B

(20.1)

3=A+B

(20.2)

Subtracting (20.2) from (20.1), gives A=1 and B=2. Therefore:

∫3x+4(x+1)(x+2)dx=∫1x+1dx+∫2x+2dx=ln(x+1)+2ln(x+2)+C

Figure 20.23 shows the graphs of y=3x+4(x+1)(x+2) and y=ln(x+1)+2ln(x+2).

Fig. 20.23

The graphs of y=3x+4(x+1)(x+2) (green), and y=ln(x+1)+2ln(x+2) (blue)

Now let’s evaluate:

∫5x-7(x-1)(x-2)dx

Integrating by partial fractions:

5x-7(x-1)(x-2)=Ax-1+Bx-25x-7=A(x-2)+B(x-1)=Ax+Bx-2A-B

Equating constants and terms in x:

-7=-2A-B

(20.3)

5=A+B

(20.4)

Subtracting (20.3) from (20.4), gives A=2 and B=3. Therefore:

∫5x-7(x-1)(x-2)dx=∫2x-1dx+∫3x-2dx=2ln(x-1)+3ln(x-2)+C

Figure 20.24 shows the graphs of y=5x-7(x-1)(x-2) and y=2ln(x-1)+3ln(x-2).

Fig. 20.24

The graphs of y=5x-7(x-1)(x-2) (green), and y=2ln(x-1)+3ln(x-2) (blue)

Finally, let’s evaluate:

∫6x2+5x-2x3+x2-2xdx

using partial fractions:

6x2+5x-2x3+x2-2x=Ax+Bx+2+Cx-16x2+5x-2=A(x+2)(x-1)+Bx(x-1)+Cx(x+2)=Ax2+Ax-2A+Bx2-Bx+Cx2+2Cx

Equating constants, terms in x and x2:

-2=-2A

(20.5)

5=A-B+2C

(20.6)

6=A+B+C

(20.7)

Manipulating (20.5), (20.6) and (20.7): A=1, B=2 and C=3, therefore:

∫6x2+5x-2x3+x2-2xdx=∫1xdx+∫2x+2dx+∫3x-1dx=lnx+2ln(x+2)+3ln(x-1)+C

Figure 20.25 shows the graphs of y=6x2+5x-2x3+x2-2x and y=lnx+2ln(x+2)+3ln(x-1).

Fig. 20.25

The graphs of y=6x2+5x-2x3+x2-2x (green), and y=lnx+2ln(x+2)+3ln(x-1) (blue)

20.4 Area Under a Graph 

The ability to calculate the area under a graph is one of the most important discoveries of integral calculus. Prior to calculus, area was computed by dividing a zone into very small strips and summing the individual areas. The accuracy of the result is improved simply by making the strips smaller and smaller, taking the result towards some limiting value. In this section, I show how integral calculus provides a way to compute the area between a function’s graph and the x- and y-axis.

20.5 Calculating Areas

Before considering the relationship between area and integration, let’s see how area is calculated using functions and simple geometry.

Fig. 20.26

Area of the shaded zone is A=x

Fig. 20.27

Area of the shaded zone is A=x2

Figure 20.26 shows the graph of y=1, where the area A of the shaded zone is:

A=x,x>0

For example, when x=4, A=4, and when x=10, A=10. An interesting observation is that the original function is the derivative of A:

dAdx=1=y

Figure 20.27 shows the graph of y=2x. The area A of the shaded triangle is:

A=12base×height=12x×2x=x2

Thus, when x=4, A=16. Once again, the original function is the derivative of A:

dAdx=2x=y

which is no coincidence.

Fig. 20.28

Graph of y=r2-x2

Finally, Fig. 20.28 shows a circle where x2+y2=r2, and the curve of the first quadrant is described by the function: 

y=r2-x2,1≤x≤r

The total area of the shaded zones is the sum of the two parts A1 and A2. To simplify the calculations the function is defined in terms of the angle θ, such that:

x=rsinθ

and

y=rcosθ

Therefore:

A1=12r2θA2=12(rcosθ)(rsinθ)=14r2sin(2θ)A=A1+A2=12r2θ+12sin(2θ)

To show that the total area is related to the function’s derivative, let’s differentiate A with respect to θ:

dAdθ=12r21+cos(2θ)=r2cos2θ

But we want the derivative dAdx, which requires the chain rule:

dAdx=dAdθdθdx

where:

dxdθ=rcosθ

or

dθdx=1rcosθ

therefore:

dAdx=r2cos2θrcosθ=rcosθ=y

which is the equation for the quadrant.

Fig. 20.29

Relationship between y=f(x) and A(x)

Hopefully, these three examples provide strong evidence that the derivative of the function for the area under a graph, equals the graph’s function:

dAdx=f(x)

which implies that:

A=∫f(x)dx

Now let’s prove this observation using Fig. 20.29, which shows a continuous function y=f(x). Next, we define a function A(x) to represent the area under the graph over the interval [a,x]. δA is the area increment between x and x+δx, and:

δA≈f(x)·δx

We can also reason that:

δA=A(x+δx)-A(x)≈f(x)·δx

and the derivative dAdx is the limiting condition:

dAdx=limδx→0A(x+δx)-A(x)δx=limδx→0f(x)·δxδx=f(x)

thus:

dAdx=f(x)

whose antiderivative is:

A(x)=∫f(x)dx

The function A(x) computes the area over the interval [a,b] and is represented by:

A(x)=∫abf(x)dx

which is called the integral or definite integral.   

Fig. 20.30

A(b) is the area under the graph y=f(x),    0≤x≤b

Let’s assume that A(b) is the area under the graph of f(x) over the interval [0,b], as shown in Fig. 20.30, and is written:

A(b)=∫0bf(x)dx

Similarly, let A(a) be the area under the graph of f(x) over the interval [0,a], as shown in Fig. 20.31, and is written:

A(a)=∫0af(x)dx

Fig. 20.31

A(a) is the area under the graph y=f(x),    0≤x≤a

Fig. 20.32

A(b)-A(a) is the area under the graph y=f(x),   a≤x≤b

Figure 20.32 shows that the area of the shaded zone over the interval [a,b] is calculated by:

A=A(b)-A(a)

which is written:

A=∫0bf(x)dx-∫0af(x)dx

and is contracted to:

A=∫abf(x)dx

(20.8)

 The fundamental theorem of calculus states that the definite integral:

∫abf(x)dx=F(b)-F(a)

where:

F(a)=∫f(x)dx,x=aF(b)=∫f(x)dx,x=b

In order to compute the area beneath a graph of f(x) over the interval [a,b], we first integrate the graph’s function:

F(x)=∫f(x)dx

and then calculate the area, which is the difference:

A=F(b)-F(a)

To illustrate how (20.8) is used in the context of the earlier three examples, let’s calculate the area over the interval [1,4] for y=1, as shown in Fig. 20.33. We begin with:

A=∫141dx

Next, we integrate the function, and transfer the interval bounds employing the substitution symbol |14, or square brackets []14. Using |14, we have:

A=|14x=4-1=3

or using []14, we have:

A=[x]14=4-1=3

I will continue with square brackets.

Fig. 20.33

Area under the graph is ∫141dx

Fig. 20.34

Area under the graph is ∫142xdx

Fig. 20.35

Area under the graph is ∫0rr2-x2dx

Now let’s calculate the area over the interval [1,4] for y=2x, as shown in Fig. 20.34. We begin with:

A=∫142xdx

Next, we integrate the function and evaluate the area:

A=[x2]14=16-1=15

Finally, let’s calculate the area over the interval [0,r] for y=r2-x2, which is the equation for a circle, as shown in Fig. 20.35. We begin with:

A=∫0rr2-x2dx

(20.9)

Unfortunately, (20.9) contains a function of a function, which is resolved by substituting another independent variable. In this case, the geometry of the circle suggests:

x=rsinθ

therefore:

r2-x2=rcosθ

and

dxdθ=rcosθ

(20.10)

However, changing the independent variable requires changing the interval for the integral. In this case, changing 0≤x≤r into θ1≤θ≤θ2:

When x=0,   rsinθ1=0,   therefore θ1=0.

When x=r,   rsinθ2=r,   therefore θ2=π/2.

Thus, the new interval is [0,π/2].

Finally, the dx in (20.9) has to be changed into dθ, which using (20.10) makes:

dx=rcosθdθ

Now we are in a position to rewrite the original integral using θ as the independent variable:

A=∫0π2(rcosθ)(rcosθ)dθ=r2∫0π2cos2θdθ=r22∫0π21+cos(2θ)dθ=r22[θ+12sin(2θ)]0π2=r22π2=πr24

which makes the area of a full circle πr2.

20.6 Positive and Negative Areas   

Area in the real world is always regarded as a positive quantity—no matter how it is measured. In mathematics, however, area is often a signed quantity, and is determined by the clockwise or anticlockwise direction of vertices. As we generally use a left-handed Cartesian axial system in calculus, areas above the x-axis are positive, whilst areas below the x-axis are negative. This can be illustrated by computing the area of the positive and negative parts of a sine wave.

Fig. 20.36

The two areas associated with a sine wave

Figure 20.36 shows a sketch of a sine wave over one cycle, where the area above the x-axis is labelled A1, and the area below the x-axis is labelled A2. These areas are computed as follows:

A1=∫0πsinxdx=[-cosx]0π=1+1=2

However, A2 gives a negative result:

A2=∫π2πsinxdx=[-cosx]π2π=-1-1=-2

This means that the area is zero over the bounds 0 to 2π:

A2=∫02πsinxdx=[-cosx]02π=-1+1=0

Consequently, one must be very careful using this technique for functions that are negative in the interval under investigation. Figure 20.37 shows a sine wave over the interval [0,π] and its accumulated area.

Fig. 20.37

The accumulated area of a sine wave

Fig. 20.38

Two areas between y=x2 and y=x3

20.7 Area Between Two Functions 

Figure 20.38 shows the graphs of y=x2 and y=x3, with two areas labelled A1 and A2. A1 is the area trapped between the two graphs over the interval [-1,0] and A2 is the area trapped between the two graphs over the interval [0,1]. These areas are calculated very easily: in the case of A1 we sum the individual areas under the two graphs, remembering to reverse the sign for the area associated with y=x3. For A2 we subtract the individual areas under the two graphs.

A1=∫-10x2dx-∫-10x3dx=x33-10-x44-10=13+14=712A2=∫01x2dx-∫01x3dx=x3301-x4401=13-14=112

Note, that in both cases the calculation is the same, which implies that when we employ:

A=∫abf(x)-g(x)dx

A is always the area trapped between f(x) and g(x) over the interval [a,b].

Let’s take another example, by computing the area A between y=sinx and the line y=0.5, as shown in Fig. 20.39. The horizontal line intersects the sine curve at x=30∘ and x=150∘, marked in radians as 0.5236 and 2.618 respectively.

A=∫30∘150∘sinxdx-∫π/65π/60.5dx=[-cosx]30∘150∘-12[x]π/65π/6=32+32-125π6-π6=3-π3≈0.685

Fig. 20.39

The area between y=sinx and y=0.5

Fig. 20.40

The areas between the x-axis and the y-axis

20.8 Areas with the y-Axis

So far we have only calculated areas between a function and the x-axis. So let’s compute the area between a function and the y-axis. Figure 20.40 shows the function y=x2 over the interval [0,4], where A1 is the area between the curve and the x-axis, and A2 is the area between the curve and y-axis. The sum A1+A2 must equal 4×16=64, which is a useful control. Let’s compute A1.

A1=∫04x2dx=[x33]04=643=21.3¯

which means that A2=42.6¯. To compute A2 we construct an integral relative to dy with a corresponding interval. If y=x2 then x=y12, and the interval is [0,16]:

A2=∫016y12dy=[23y32]016=2364=42.6¯

20.9 Area with Parametric Functions 

When working with functions of the form y=f(x), the area under its curve and the x-axis over the interval [a,b] is:

A=∫abf(x)dx

However, if the curve has a parametric form where:

x=fx(t)andy=fy(t)

then we can derive an equivalent integral as follows.

First: We need to establish equivalent limits [α,β] for t, such that:

a=fx(α)andb=fx(β)

Second: Any point on the curve has corresponding Cartesian and parametric coordinates:

xandfx(t)

y=f(x)andfy(t)

Third:

x=fx(t)dx=fx′(t)dtA=∫abf(x)dx=∫αβfy(t)fx′(t)dt

therefore:

A=∫αβfy(t)fx′(t)dt

(20.11)

Let’s apply (20.11) using the parametric equations for a circle:

x=-rcosty=rsint

as shown in Fig. 20.41. Remember that the Cartesian interval is [a, b] left to right, and the polar interval [α,β], must also be left to right, which is why x=-rcost. Therefore:

fx′t=rsintfy(t)=rsintA=∫αβfy(t)fx′(t)dt=∫0πrsint·rsintdt=r2∫0πsin2tdt=r22∫0π1-cos(2t)dt=r22[t+12sin(2t)]0π=πr22

which makes the area of a full circle πr2.

Fig. 20.41

The parametric functions for a circle

20.10 The Riemann Sum

  The German mathematician Bernhard Riemann (1826–1866) (pronounced ‘Reeman’) made major contributions to various areas of mathematics, including integral calculus, where his name is associated with a formal method for summing areas and volumes. Through the Riemann Sum, Riemann provides an elegant and consistent notation for describing single, double and triple integrals when calculating area and volume. Let’s see how the Riemann sum explains why the area under a curve is the function’s integral.

Fig. 20.42

The graph of function f(x) over the interval [a,b]

Figure 20.42 shows a function f(x) divided into eight equal sub-intervals where:

Δx=b-a8

and

a=x0<x1<x2<⋯<x7<x8=b

In order to compute the area under the curve over the interval [a,b], the interval is divided into some large number of sub-intervals. In this case, eight, which is not very large, but convenient to illustrate. Each sub-interval becomes a rectangle with a common width Δx and a different height. The area of the first rectangular sub-interval shown shaded, can be calculated in various ways. We can take the left-most height f(x0) and form the product f(x0)Δx, or we can take the right-most height f(x1) and form the product f(x1)Δx. On the other hand, we could take the mean of the two heights (f(x0)+f(x1))/2 and form the product (f(x0)+f(x1))Δx/2. A solution that shows no bias towards either left, right or centre, is to let f(xi∗) be anywhere in a specific sub-interval Δxi, then the area of the rectangle associated with the sub-interval is f(xi∗)Δxi, and the sum of the rectangular areas is given by:

A=∑i=18f(xi∗)Δxi

Dividing the interval into eight equal sub-intervals will not generate a very accurate result for the area under the graph. But increasing it to eight-thousand or eight-million, will take us towards some limiting value. Rather than specify some specific large number, it is common practice to employ n, and let n tend towards infinity, which is written:

A=∑i=1nf(xi∗)Δxi

(20.12)

The right-hand side of (20.12) is called a Riemann sum, of which there are many. For the above description, I have assumed that the sub-intervals are equal, which is not a necessary requirement.

If the number of sub-intervals is n, then:

Δx=b-an

and the definite integral is defined as:

∫abf(x)dx=limn→∞∑i=1nf(xi∗)Δxi

20.11 Summary

In this chapter we have discovered the double role of integration. Integrating a function reveals another function, whose derivative is the function under investigation. Simultaneously, integrating a function computes the area between the function’s graph and the x- or y-axis. Although the concept of area in every-day life is an unsigned quantity, within mathematics, and in particular calculus, area is a signed quality, and one must be careful when making such calculations.

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_21

21. Fourier Series

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

21.1 Introduction

This chapter shows how certain waveforms are approximated by a series of cosine and sine functions, called a Fourier Series. The idea was proposed by the French mathematician Joseph Fourier (1768–1830), who claimed that any function of a variable, whether continuous or discontinuous, can be expanded into a series of sines of multiples of the variable [1]. Today, this claim has been  slightly tempered by mathematicians.

This chapter is based upon my favourite book on mathematics Mathematics: From the Birth of Numbers [2].

21.2 Mathematical Foundations

Fourier suggested that certain waveforms are represented by an infinite series of cosine and sine waves defined by:

f(x)=a02+∑n=1∞ancos(nx)+∑n=1∞bnsin(nx)

(21.1)

Equation (21.1) is often written as:

f(x)=a02+∑n=1∞ancos(nx)+bnsin(nx)

(21.2)

where:

f(x)isafunctionforfrequencyfandiscontinuousovertheinterval[-π≤x≤π].a0isaconstant.nidentifiestheFourierseriesterm.anistheamplitudeofthecosineterm.bnistheamplitudeofthesineterm.

To find an expression for a0 we integrate f(x) in (21.2) over the interval [-π≤x≤π]:

∫-ππf(x)dx=a02∫-ππ1dx+∑n=1∞∫-ππancos(nx)dx+∫-ππbnsin(nx)dx=a0x2-ππ+∑n=1∞annsin(nx)-bnncos(nx)-ππ=a0π+∑n=1∞ann[sin(nπ)-sin(-nπ)]-bnn[cos(nπ)-cos(-nπ)]=a0π+∑n=1∞ann[0]-bnn[0]=a0πa0=1π∫-ππf(x)dx

We can find an expression for an where n≥1, by first multiplying f(x) in (21.2) by cos(nx) and then integrating with respect to x over the interval [-π≤x≤π]. This results in:

an=1π∫-ππf(x)·cos(nx)dx

Similarly, we can find an expression for bn where n≥1, by first multiplying f(x) in (21.2) by sin(nx) and then integrating with respect to x over the interval [-π≤x≤π]. This results in:

bn=1π∫-ππf(x)·sin(nx)dx

21.3 Discontinuous Functions

A square wave is an excellent  example of a discontinuous function, as shown in Fig. 21.1, where the function is 0 over the interval [-π≤x≤0], and is 1 over the interval [0≤x≤π]. The function is discontinuous at x=-π, x=0 and x=π, and has a period of 2π.

Fig. 21.1

Sketch of a square wave

Over the interval [0≤x≤π], the value of a0, an and bn are:

a0=1π∫0π1dx=1an=1π∫0π1·cos(nx)dx=0bn=1π∫0π1·sin(nx)dx=1π-1n[cos(nx)]0π=1nπ[cos(nx)]π0=0(forevenn)=2nπ(foroddn)

These values confirm that the series contains only a constant term, and sine terms:

f(x)=12+2πsin(x)1+sin(3x)3+sin(5x)5+sin(7x)7+⋯x=kπwherek∈Z

Fig. 21.2

Superimposed graphs with each colour showing an extra term in the series

Fig. 21.3

The Fourier series up to sin(23x)23

Figure 21.2 shows this function by adding the extra terms. Figure 21.3 shows the function up to sin(23x)23.

21.4 Even and Odd Functions

As function products are involved in the definitions of a0, an and bn, it helps develop a Fourier series if a function is described as even or odd over the interval [-π≤x≤π]. Figure 21.4 shows an even function y=a(x), and an odd function y=b(x), with the areas marked +ve and −ve. Areas are often used for predicting the nature of a Fourier series.

Fig. 21.4

Even and odd functions

We know that an even function is defined by f(-x)=f(x), which makes the cosine function an even function. Conversely, an odd function is defined by f(-x)=-f(x), which makes the sine function an odd function. Table 21.1 shows the product of two such functions, where we note that the product of two even functions, or two odd functions, is an even function. The product of an even and odd function is an odd function. These results are quickly confirmed by noting that cos2x and sin2x are even functions, whilst cos(x)·sin(x) is odd.

Table 21.1

The product of even and odd functions

Product

Even

Odd

Even

Even

Odd

Odd

Odd

Even

21.4.1 Even Functions

We begin by assuming that f(x) is an even function over the interval [-π≤x≤π], and we  will show that the Fourier series for f(x) only contains cosine terms. What follows is the values of a0, an and bn.

Starting with:

f(x)=a02+∑n=1∞ancos(nx)+bnsin(nx)

then:

a0=1π∫-ππf(x)dx

As f(x) is an even function, the area of f(x) over the interval [-π≤x≤0] equals the area of f(x) over the interval [0≤x≤π], therefore:

a0=2π∫0πf(x)dx

Similarly, an is given by:

an=1π∫-ππf(x)·cos(nx)dx=2π∫0πf(x)·cos(nx)dx

The last constant is bn, where:

bn=1π∫-ππf(x)·sin(nx)dx

which contains the product of an even and odd function, and produces an odd function. The integral of an odd function, with a period of 2π, over the interval [-π≤x≤π] is zero, therefore:

bn=0

Thus, if f(x) is an even function, the Fourier terms are given by:

f(x)=a02+∑n=1∞ancos(nx)

21.4.2 Odd Functions

Next, if f(x) is an odd function over the interval [-π≤x≤π], then we will  show that the Fourier series for f(x) only contains sine terms. What follows is how we calculate a0, an and bn.

Starting with:

f(x)=a02+∑n=1∞ancos(nx)+bnsin(nx)

then:

a0=1π∫-ππf(x)dx

As f(x) is an odd function, the area of f(x) over the interval [-π≤x≤π] equals zero, then:

a0=0

The value of an is given by:

an=1π∫-ππf(x)·cos(nx)dx

and as f(x) is odd, and the cosine is even, the resulting function is odd. The integral of an odd function over the interval [-π≤x≤π] is zero, therefore:

an=0

The last constant is bn, where:

bn=1π∫-ππf(x)·sin(nx)dx

which contains the product of two odd functions, and produces an even function, therefore:

bn=1π∫-ππf(x)·sin(nx)dx=2π∫0πf(x)·sin(nx)dx

Thus, if f(x) is an odd function, the Fourier terms are given by:

f(x)=∑n=1∞bnsin(nx)

We have shown that if f(x) is an odd function, the Fourier  series only contains the sine terms.

21.4.3 The Fourier Series for a Triangular Function

A triangular function shown in Fig. 21.5 is described by:

f(x)=a02+∑n=1∞ancos(nx)a0=2π∫0πf(x)dxan=2π∫0πf(x)·cos(nx)dxbn=0

The waveform has a period of 2π and an amplitude of π. As we are integrating over the interval [0≤x≤π], we only have to describe f(x) over this interval, which is the straight line f(x)=x, or more accurately f(x)=|x|.

Fig. 21.5

A triangular function

The values of a0 and an are given by:

a0=2π∫0π|x|dx=2π[x22]0π=πan=2π∫0π|x|·cos(nx)dx

This integral is evaluated by parts where we use:

∫0πuv′dx=uv-∫0πvu′dx

We begin by letting u=|x| and v′=cos(nx), where u′=1 and v=sin(nx)n.

Integrating by parts:

2π∫0πuv′dx=2πuv-∫0πvu′dx=2πx·sin(nx)n-∫0πsin(nx)ndx=2π[x·sin(nx)n+cos(nx)n2]0π=0+2πn2·[cos(nx)]0π=0(forevenn)=-4πn2(foroddn)

Therefore:

f(x)=π2-4πcos(x)1+cos(3x)32+cos(5x)32+cos(7x)72+⋯x=kπwherek∈Z

where we see that f(x) is composed entirely of odd cosine terms. Figure 21.6 shows this function containing 4 Fourier terms.

Fig. 21.6

A triangular function represented by 4 Fourier terms

21.4.4 Fourier Series for a Sawtooth Function

A sawtooth function is shown in Fig. 21.7, where f(x) has a period of 2π and [-π<x≤π].

Fig. 21.7

A sawtooth function

The sawtooth function f(x) is discontinuous and an odd function, therefore, a0=0, and an=0.

f(x)=|x|

bn=2π∫0π|x|·sin(nx)dx

This integral is evaluated by parts where we use:

∫0πuv′dx=uv-∫0πvu′dx

We begin by letting u=|x| and v′=sin(nx), where u′=1 and v=-cos(nx)n.

Integrating by parts:

2π∫0πuv′dx=2πuv-∫0πvu′dx=2π-x·cos(nx)n+∫0πcos(nx)ndx=2π[-x·cos(nx)n+sin(nx)n2]0π=-2nπ[x·cos(nx)]0πbn=2n(-1)n-1=2n(foroddn)=-2n(forevenn)f(x)=∑n=1∞2n(-1)n-1·sin(nx)

Therefore:

f(x)=2sin(x)1-sin(2x)2+sin(3x)3-sin(4x)4+⋯

where we see that f(x) is composed entirely of sine terms. Figure 21.8 shows this function containing 8 Fourier terms.

Fig. 21.8

A sawtooth function represented by 8 Fourier terms

21.5 Summary

Hopefully, this short chapter is sufficient to show that certain functions can be represented by a series of sine and/or cosine terms, and will inspire readers to learn more about this interesting topic.

References

1.

https://​en.​wikipedia.​org/​wiki/​Joseph_​Fourier

2.

Gullberg J (1997) Mathematics: from the birth of numbers. WW Norton

© The Author(s), under exclusive license to Springer-Verlag London Ltd., part of Springer Nature 2025

J. VinceMathematics for Computer GraphicsUndergraduate Topics in Computer Sciencehttps://doi.org/10.1007/978-1-4471-7550-6_22

22. Worked Examples

John Vince1  

(1)

Breinton, UK

John Vince

Email: heidi@heidivince.co.uk

22.1 Introduction

This chapter examines a variety of problems encountered in computer graphics and develops mathematical strategies for their solution. Such strategies may not be the most efficient, however, they will provide the reader with a starting point, which may be improved upon.

22.2 Area of Regular Polygon

Given a regular polygon with n sides, side length s, and radius r of the circumscribed circle, its area can be computed by dividing it into n isosceles triangles and summing their total area.

Figure 22.1 shows one of the isosceles triangles OAB formed by an edge s and the centre O of the polygon. From Fig. 22.1 we observe that:

s2h=tanπn

therefore:

h=s2cotπnarea(ΔOAB)=sh2=s24cotπn

but there are n such triangles, therefore:

area=ns24cotπn

Table 22.1 shows the area for the first six regular polygons with s=1.

Fig. 22.1

One of the isosceles triangles forming a regular polygon

Table 22.1

Area of first 6 regular polygons

n

area

3

0.433

4

1

5

1.72

6

2.598

7

3.634

8

4.828

22.3 Area of any Polygon

Figure 22.2 shows a polygon with the following vertices in anticlockwise sequence, and from Table 22.2, the area is 9.5.

Table 22.2

Polygon coordinates

x

0

2

5

4

2

y

2

0

1

3

3

Fig. 22.2

A five-sided irregular polygon

The area of a polygon is given by:

area=12∑i=0n-1(xiyi+1(modn)-yixi+1(modn))=12(0×0+2×1+5×3+4×3+2×2-2×2-0×5-1×4-3×2-3×0)area=12(33-14)=9.5

22.4 Dihedral Angle of a Dodecahedron

The  dodecahedron is a member of the five Platonic solids, which are constructed from regular polygons. The dihedral angle is the internal angle between two touching faces. Figure 22.3 shows a dodecahedron with one of its pentagonal sides.

Fig. 22.3

A dodecahedron with one of its pentagonal sides

Figure 22.4 illustrates the geometry required to fold two pentagonal sides through the dihedral angle γ.

Fig. 22.4

The dihedral angle γ between two pentagonal sides

The point P has coordinates:

P(x,y,z)=(sin72∘,0,-cos72∘)

and for simplicity, we will use a unit vector to represent an edge, therefore:

‖v1‖=‖v2‖=1

The coordinates of the rotated point P′ are given by the following transform:

x′y′z′=cosγ-sinγ0sinγcosγ0001sin72∘0-cos72∘

where:

x′=cosγsin72∘y′=sinγsin72∘z′=-cos72∘

But:

v1·v2=‖v1‖‖v2‖cosθ=xx′+yy′+zz′

therefore:

cosθ=cosγsin272∘+cos272∘

but θ=108∘ (internal angle of a regular pentagon), therefore:

cosγ=cos108∘-cos272∘sin272∘=cos72∘cos72∘-1

The dihedral angle γ≈116.56505∘.

A similar technique can be used to calculate the dihedral angles of the other Platonic objects.

22.5 Vector Normal to a Triangle

Very often in computer graphics we have to calculate a vector normal to a plane containing three points. The most effective tool to achieve this is the vector product. For example, given three points P1(5,0,0), P2(0,0,5) and P3(10,0,5), we can create two vectors a and b as follows:

a=x2-x1y2-y1z2-z1,b=x3-x1y3-y1z3-z1

therefore:

a=-5i+5k,b=5i+5k

The normal vector n is given by:

n=a×b=ijk-505505=50j

22.6 Area of a Triangle Using Vectors

The vector product is also useful in calculating the area of a triangle using two of its sides as vectors. For example, using the same points and vectors in the previous example:

area=12‖a×b‖=12ijk-505505=12‖50j‖=25

22.7 General Form of the Line Equation from Two Points

The general form of the line equation is given by:

ax+by+c=0

and it may be required to compute this equation from two known points. For example, Fig. 22.5 shows two points P1(x1,y1) and P2(x2,y2), from which it is possible to determine P(x,y).

Fig. 22.5

A line formed from two points P1 and P2

From Fig. 22.5:

y2-y1x2-x1=y-y1x-x1(y2-y1)(x-x1)=(x2-x1)(y-y1)(y2-y1)x-(y2-y1)x1=(x2-x1)y-(x2-x1)y1(y2-y1)x+(x1-x2)y=x1y2-x2y1

therefore:

a=y2-y1b=x1-x2c=-(x1y2-x2y1)

If the two points are P1(1,0) and P2(3,4), then:

(4-0)x+(1-3)y-(1×4-3×0)=0

and

4x-2y-4=0

22.8 Angle Between Two Straight Lines

Given two line equations it is possible to compute the angle between the lines using the scalar product. For example, if the line equations are:

a1x+b1y+c1=0a2x+b2y+c2=0

their normal vectors are n=a1i+b1j and m=a2i+b2j respectively, therefore:

n·m=‖n‖‖m‖cosα

and the angle between the lines α is given by:

α=cos-1n·m‖n‖‖m‖

Figure 22.6 shows two lines with equations:

2x+2y-4=02x+4y-4=0

therefore:

α=cos-12×2+2×422+2222+42≈18.435∘

Fig. 22.6

Two lines intersecting at an angle α

22.9 Test if Three Points Lie on a Straight Line

Figure 22.7 shows three points P1, P2 and P3 which lie on a straight line. There are all sorts of ways to detect such a condition. For example, we could assume that the points are the vertices of a triangle, and if the triangle’s area is zero, then the points lie on a line. Here is another approach.

Given P1(x1,y1), P2(x2,y2), P3(x3,y3) and r=P1P2→ and s=P1P3→, the three points lie on a straight line when s=λr where λ is a scalar.

Let the points be:

P1(0,-2),P2(1,-1),P3(4,2)

then:

r=i+j,ands=4i+4j

and

s=4r

therefore, the points lie on a straight line as confirmed by the diagram.

Fig. 22.7

Three points on a common line

Another way is to compute:

x1y11x2y21x3y31=0-211-11421=0

which is twice the area of ΔP1P2P3, and as this equals zero, the points must be co-linear.

22.10 Position and Distance of the Nearest Point on a Line to a Point

Suppose we have a line and some arbitrary point P, and we require to find the nearest point on the line to P. Vector analysis provides a very elegant way to solve such problems. Figure 22.8 shows a line and a point P and the nearest point Q on the line. The nature of the geometry is such that the line connecting P to Q is perpendicular to the reference line, which is exploited in the analysis. The objective is to determine the position vector q.

Fig. 22.8

Q is the nearest point on the line to P

We start with the line equation:

ax+by+c=0

and declare Q(x,y) as the nearest point on the line to P.

The normal to the line must be:

n=ai+bj

and the position vector for Q is:

q=xi+yj

Therefore:

n·q=-c

(22.1)

r is parallel to n, therefore:

r=λn

(22.2)

where λ is some scalar.

Taking the scalar product of (22.2):

n·r=λn·n

(22.3)

but as:

r=q-p

(22.4)

n·r=n·q-n·p

(22.5)

Substituting (22.1) and (22.3) in (22.5) we obtain:

λn·n=-c-n·p

therefore:

λ=-(n·p+c)n·n

From (22.4) we get:

q=p+r

(22.6)

Substituting (22.2) in (22.6) we obtain the position vector for Q:

q=p+λn

The distance PQ must be the magnitude of r:

PQ=‖r‖=λ‖n‖

Let’s test this result with an example where the answer can be predicted.

Figure 22.9 shows a line whose equation is x+y-1=0, and the associated point is P(1,1). By inspection, the nearest point is Q12,12 and the distance PQ≈0.7071.

From the line equation:

a=1,b=1,c=-1

therefore:

λ=-2-12=-12

and

xQ=xP+λxn=1-12×1=12yQ=yP+λyn=1-12×1=12

The nearest point is Q12,12 and the distance is:

PQ=‖λn‖=12‖i+j‖≈0.7071

Fig. 22.9

Q is the nearest point on the line to P

22.11 Position of a Point Reflected in a Line

Suppose that instead of finding the nearest point on a line we require the reflection Q of P in the line. Once more, we set out to discover the position vector for Q. Figure 22.10 shows the vectors used in the analysis. We start with the line equation:

ax+by+c=0

and declare T(x,y) as the nearest point on the line to O with t=xi+yj as its position vector.

Fig. 22.10

The vectors required to find the reflection of P in the line

From the line equation:

n=ai+bj

therefore:

n·t=-c

(22.7)

We note that r+r′ is orthogonal to n, therefore:

n·(r+r′)=0

and

n·r+n·r′=0

(22.8)

We also note that p-q is parallel to n, therefore:

p-q=r-r′=λn

where λ is some scalar, therefore:

λ=r-r′n

(22.9)

From the figure we note that:

r=p-t

(22.10)

Substituting (22.7) in (22.10):

n·r=n·p-n·t=n·p+c

(22.11)

Substituting (22.8) and (22.11) in (22.9):

λ=n·r-n·r′n·n=2n·rn·nλ=2(n·p+c)n·n

and the position vector is:

q=p-λn

Let’s again test this formula with a scenario that can be predicted in advance. Given the line equation:

x+y-1=0

and the point P(1,1), the reflection must be the origin, as shown in Fig. 22.11.

Now let’s confirm this prediction. From the line equation:

a=1,b=1,c=-1

and

xP=1yP=1λ=2×(2-1)2=1

therefore:

xQ=xP-λxn=1-1×1=0yQ=yP-λyn=1-1×1=0

and the reflection point is Q(0,0).

Fig. 22.11

Q is the reflection of P in the line

22.12 Intersection of a Line and a Sphere

In ray tracing and ray casting it is necessary to detect whether a ray (line) intersects objects within a scene. Such objects may be polygonal, constructed from patches, or defined by equations. In this example, we explore the intersection between a line and a sphere.

There are three possible scenarios: the line intersects, touches or misses the sphere. It just so happens, that the cosine rule proves very useful in setting up a geometric condition that identifies the above scenarios, which are readily solved using vector analysis.

Figure 22.12 shows a sphere with radius r located at C. The line is represented parametrically, which lends itself to this analysis. The objective is to discover whether there are points in space that satisfy both the line equation and the sphere equation. If there is a point, a position vector will locate it.

Fig. 22.12

The vectors required to locate a possible intersection

The position vector for C is:

c=xci+ycj+zck

and the equation of the line is:

p=t+λv

where λ is a scalar, and:

‖v‖=1

(22.12)

For an intersection at P:

‖q‖=r‖q‖2=r2‖q‖2-r2=0

Using the cosine rule:

‖q‖2=‖λv‖2+‖s‖2-2‖λv‖‖s‖cosθ

(22.13)

‖q‖2=λ2‖v‖2+‖s‖2-2‖v‖‖s‖λcosθ

(22.14)

Substituting (22.12) in (22.14):

‖q‖2=λ2+‖s‖2-2‖s‖λcosθ

(22.15)

Now let’s identify cosθ:

s·v=‖s‖‖v‖cosθ

therefore:

cosθ=s·v‖s‖

(22.16)

Substituting (22.16) in (22.15):

‖q‖2=λ2-2s·vλ+‖s‖2

therefore:

‖q‖2-r2=λ2-2s·vλ+‖s‖2-r2=0

(22.17)

Equation (22.17) is a quadratic in λ where:

λ=s·v±(s·v)2-‖s‖2+r2

(22.18)

and

s=c-t

The discriminant of (22.18) determines whether the line intersects, touches or misses the sphere.

The position vector for P is given by:

p=t+λv

where:

λ=s·v±(s·v)2-‖s‖2+r2

and

s=c-t

For a miss condition:

(s·v)2-‖s‖2+r2<0

For a touch condition:

(s·v)2-‖s‖2+r2=0

For an intersect condition:

(s·v)2-‖s‖2+r2>0

To test these formulae we will create all three scenarios and show that the equations are well behaved.

Figure 22.13 shows a sphere with three lines represented by their direction vectors λv1, λv2 and λv3. The sphere has radius r=1 and is located at C with position vector:

c=i+j

whilst the three lines L1, L2 and L3 miss, touch and intersect the sphere respectively.

The lines are of the form:

p=t+λv

therefore:

p1=t1+λv1p2=t2+λv2p3=t3+λv3

where:

t1=2i,v1=12i+12jt2=2i,v2=jt3=2i,v3=-12i+12j

and

c=i+j

Fig. 22.13

Three lines that miss, touch and intersect the sphere

Let’s substitute the lines in the original equations:

L1:

s=-i+j(s·v)2-‖s‖2+r2=0-2+1=-1

the negative discriminant confirms a miss condition.

L2:

s=-i+j(s·v)2-‖s‖2+r2=1-2+1=0

the zero discriminant confirms a touch condition, therefore λ=1 and the touch point is: P2(2,1,0) which is correct.

L3:

s=-i+j(s·v)2-‖s‖2+r2=2-2+1=1

the positive discriminant confirms an intersect condition, therefore:

λ=22±1=1+2or2-1

The intersection points are given by the two values of λ:

when λ=1+2

xP=2+1+2-12=1-12yP=0+1+212=1+12zP=0

when λ=2-1

xP=1+2-1-12=1+12yP=0+2-112=1-12zP=0

The intersection points are:

P3′1-12,1+12,0P31+12,1-12,0

which are correct.

22.13 Sphere Touching a Plane

A sphere will touch a plane if the perpendicular distance from its centre to the plane equals its radius. The geometry describing this condition is identical to finding the position and distance of the nearest point on a plane to a point.

Figure 22.14 shows a sphere located at P with position vector p. A potential touch condition occurs at Q, and the objective of the analysis is to discover its position vector q. Given the following plane equation:

ax+by+cz+d=0

its surface normal is:

n=ai+bj+ck

The nearest point Q on the plane to a point P is given by the position vector:

q=p+λn

(22.19)

where:

λ=-n·p+dn·n

the distance:

PQ=‖λn‖

Fig. 22.14

The vectors used to detect when a sphere touches a plane

If P is the centre of the sphere with radius r, and position vector p, the touch point is also given by (22.19) when:

PQ=‖λn‖=r

Let’s test the above equations with a simple example, as shown in Fig. 22.15, which shows a sphere with radius r=1 and centred at P(1,1,1).

The plane equation is:

y-2=0

therefore:

n=j

and

p=i+j+k

therefore:

λ=-(1-2)=1

which equals the sphere’s radius and therefore the sphere and plane touch.

Fig. 22.15

A sphere touching a plane

The touch point is:

xQ=1+1×0=1yQ=1+1×1=2zQ=1+1×0=1Q=(1,2,1)

22.14 Summary

Unfortunately, problem solving is not always obvious, and it is possible to waste hours of analysis simply because the objective of the solution has not been well formulated. Hopefully, though, the reader has discovered some of the strategies used in solving the above geometric problems, and will be able to implement them in other scenarios. At the end of the day, practice makes perfect!

Appendix A

Limit of (sinθ)/θ

This appendix proves that:

limθ→0sinθθ=1,whereθisinradians

From high-school mathematics we know that sinθ≈θ, for small values of θ. For example:

sin0.1≈0.099833sin0.05≈0.04998sin0.01≈0.0099998

and

sin0.10.1≈0.99833sin0.050.05≈0.99958sin0.010.01≈0.99998

Fig. A.1

Graph of (sinθ)/θ

Therefore, we can reason that in the limit, as θ→0:

limθ→0sinθθ=1

Figure A.1 shows a graph of (sinθ)/θ, which confirms this result. However, this is an observation, rather than a proof. So, let’s pursue a geometric line of reasoning.

Fig. A.2

Unit radius circle with trigonometric ratios

From Fig. A.2 we see as the circle’s radius is unity, OA=OB=1, and AC=tanθ. As part of the strategy, we need to calculate the area of the triangle ▵OAB, the sector OAB and the ▵OAC:

area(▵OAB)=area(▵ODB)+area(▵DAB)=12cosθsinθ+12(1-cosθ)sinθ=12cosθsinθ+12sinθ-12cosθsinθ=12sinθareaofsectorOAB=θ2ππ(1)2=12θarea(▵OAC)=12(1)tanθ=12tanθ

From the geometry of a circle, we know that:

12sinθ<12θ<12tanθsinθ<θ<sinθcosθ1<θsinθ<1cosθ1>sinθθ>cosθ

and as θ→0, cosθ→1 and sinθθ→1. This holds, even for negative values of θ, because:

sin(-θ)-θ=-sinθ-θ=sinθθ

Therefore:

limθ→0sinθθ=1

Appendix B

Integrating cosnθ

We start with:

∫cosnxdx=∫cosxcosn-1xdx

Let u=cosn-1x and v′=cosx, then:

u′=-(n-1)cosn-2xsinx

and

v=sinx.

Integrating by parts:

∫uv′dx=uv-∫vu′dx+C∫cosn-1xcosxdx=cosn-1xsinx+∫sinx(n-1)cosn-2xsinxdx+C=sinxcosn-1x+(n-1)∫sin2xcosn-2xdx+C=sinxcosn-1x+(n-1)∫(1-cos2x)cosn-2xdx+C=sinxcosn-1x+(n-1)∫cosn-2dx-(n-1)∫cosnxdx+Cn∫cosnxdx=sinxcosn-1x+(n-1)∫cosn-2dx+C∫cosnxdx=sinxcosn-1xn+n-1n∫cosn-2dx+C

where n is an integer, ≠0.

Similarly:

∫sinnxdx=-cosxsinn-1xn+n-1n∫sinn-2dx+C

For example

∫cos3xdx=sinxcos2x3+23sinx+C

Index

A

Adding

complex numbers166

matrices179

ordered pairs172

quaternions251, 266

Additive form of a quaternion254

Aitken, Alexander324

Aleph-zero30

Algebra33

Algebraic notation34

Algebraic number20

Altmann, Simon248, 253, 279

Analytic geometry335

Angle

compound63

Angle between

a line and plane374

two planes373

two straight lines574

Annulus343

Anticlockwise73

Antiderivative477

Antisymmetric

functions436

matrix136

Archimedean spiral77

Area123

between two functions552

circle544

negative550

of any polygon570

of a polygonal shape74

of a regular polygon569

of a shape80

of a triangle351, 423, 573

parametric function555

positive550

under a graph542

with the y-axis553

Areal coordinates196

Argand, Jean-Robert103

Associative law10

Atan261

Augmented matrix150

Axial systems

left-handed76

right-handed76

Axial vector253

Axioms9, 446

B

Back-face detection116

Barycentric coordinates196, 407, 411

Base11

Basis vectors105

Bernstein polynomials313

Bézier

curves311, 432

matrix321

Bézier, Pierre311

Bijection6

Binary

addition16

negative number17

number12

operation9

subtraction17

Binary form of a quaternion255

Binomial49

expansion315, 474

theorem49

Bivector441

Blending

curve318

function322

Brahmagupta7, 9

B-splines324

Bürgi, Joost41

C

Calculus469

Camera space216

Cantor, Georg2, 19, 30

Cardano, Girolamo86

Cardinality30

Cartesian

coordinates71, 72

plane72

vector113

Casteljau, Paul de311

Cauchy, Augustin-Louis86, 87, 469

Cayley, Arthur24, 86, 127, 271, 279

Cayley numbers24, 264, 271

Centre of gravity338

Centroid410

Ceva, Giovanni408

Ceva's Theorem408

Chain rule517

Change of axes213

2D213

3D216

Circle343

equation312

Clifford, William Kingdon104, 435

Clockwise73

Closed interval44

Cofactor94

expansion147

Column vector106, 128, 131, 138, 196

Commutative law10

Complex

conjugate23

determinant100

number22, 165

roots37

Complex conjugate

complex number168

quaternion255

Complex number

absolute value168

adding matrix179

addition166

complex conjugate168

conjugate matrix180

definition165

division168

inverse169

inverse matrix181

matrix178

modulus168

norm168, 180

ordered pair171

product167

product matrix179

quotient matrix182

square167

subtracting matrix179

subtraction166

Composite number25

Compound-angles63

Continuity327, 469

Continuous

functions522

random variable384

Control

point317, 326

vertex317

Convex hull317, 422

Coordinates

barycentric407

Cartesian71

cylindrical79, 82

polar77, 81

spherical polar78, 82

Correlation393

coefficient393

Cosecant58

Cosine58

rule62, 463

Cotangent58

Counting6

Covariance392

Cross product117

Cubic

Bernstein polynomials317

Bézier surface patch332

equation472

function72

interpolant318

interpolation299

Curves and patches311

Cylindrical coordinates79, 82

D

Data set380

Decimal

number11

system7

Definite integral546

Degree55

Dependent

variable44

Derivative469, 476

graphical interpretation475

partial510

total518

Descartes, René34, 71

Determinant85, 133, 230

complex100

first-order98

fourth-order98

properties99

second-order87, 98

third-order89, 96, 98

value97

Diagonal matrix150

Difference of two squares40

Differential476

Differentiating480

arccos function501

arccot function502

arccsc function502

arcsec function502

arcsin function501

arctan function501

cosh function504

cot function500

csc function498

exponential functions494

function of a function481

function products484

function quotients488

hyperbolic functions503

implicit functions491

logarithmic functions496

partial511

sec function499

sine function483

sinh function504

sums of functions480

tan function497

tanh function504

trigonometric functions497

Dihedral angle of a dodecahedron571

Dirac, Paul3

Direction cosines

2D215

3D217

Discontinuous function560

Discrete, random variable384, 387

Dispersion388

Distance between two points75, 76

Distributive law10

Divisibility tests18

Division

algebra264

complex number168

Dodecahedron571

Domain45, 59

Dot product114

Double-angle278, 279

identities64

Duality452

E

Elements5, 6

Ellipse equation312

Equation

explicit43

implicit43

linear86

Equilateral triangle339

Euclid25, 28, 29

Euler

angles219

rotations207

Euler, Leonhard43

Even function47, 563

Expectation385

Expected value385

Explicit equation43

Exterior angle337

F

Fermat

last theorem76

Fermat, Pierre de71, 76

Feynman, Richard253

Finite set6

First minor94

Fourier, Joseph559

Fourier series559

Fourth-order determinant98

Frequency

histogram381

table380

Frobenius, Ferdinand Georg264

Function43, 474

continuous522

cubic72, 472

discontinuous560

domain45

even47, 563

graph72

linear72

notation44

odd47, 564

odd even561

power48

quadratic72, 471

range45

second derivative510

triangular565

trigonometric72

Function of a function

differentiating481

Fundamental theorem of arithmetic25

Fundamental theorem of calculus547

G

Gauss, Carl27, 87, 127

Gaussian

distribution390

elimination151

General form of a line equation573

Geometric

algebra435

continuity327

product in 2D441

product in 3D443

transform193

Gibbs, Josiah24, 104

Gibbs, Josiah Willard246

Gimbal lock210

Gödel, Kurt34

Goldbach, Christian27

Goldbach conjecture27

Golden section337

Grades447

Grassmann, Hermann Günther104, 246

Graves, John24, 271

H

Half-angle

identities65

Half-open interval44

Hamilton's rules243, 454

Hamilton, William Rowan23, 104, 118, 279

Hermite, Charles303

Hermite interpolation303

Hessian normal form345, 353

Hestenes, David435

Hexadecimal number13

Higher derivatives505

Highest common factor30

Homogeneous coordinates80, 196

I

Identity matrix202

Image space216

Imaginary number21

Implicit equation43

Incompleteness theorems34

Indefinite integral521

Independent

variable44

Indeterminate form7

Indices40

laws of40

Infinitesimals469

Infinity30

of primes28

Inner product439, 448

Integer19

number6

Integral

definite546

indefinite521

Integrating477

arccos function501

arccot function502

arccsc function502

arcsec function502

arcsin function501

arctan function501

by parts531

by substitution535

completing the square526

cot function500

csc function498

difficult functions523

exponential function496

integrand contains a derivative528

logarithmic function496

partial fractions539

radicals526

sec function499

tan function497

techniques522

trigonometric identities524

Intercept theorems336

Interior angle337

Interpolating

quaternions307

vectors304

Interpolation295

cubic299

linear296, 416

non-linear298

trigonometric298

Intersecting

circle and line354

line and sphere580

line segments349

planes368

straight lines348, 357

Interval44

closed44

half-open44

open44

Inverse

complex number169

matrix142

of a vector449

quaternion261, 268

trigonometric function59

Irrational number20

Isosceles triangle338

K

Kronecker, Leopold2, 19

L

Lambert's law115

Laplace

expansion97, 147

Laplace, Pierre-Simon86, 97, 147

Least squares396

Legendre, Adrien-Marie27

Leibniz, Gottfried43, 86

Lerp416

L'Hôpital, Guillaume de86

Lighting calculations115

Limits469, 474

Linear

equations86, 90

function72

interpolation296, 316, 322, 416

Linearly independent86

Lobachevsky, Nikolai246, 335

Local coordinates407

Logarithms41

Lowest common multiple30

M

Mass points410, 426

Matrices97, 127, 196, 263

addition137

antisymmetric136

augmented150

determinant133

diagonal150

dimension130

inverse142

multiplication129

notation130, 196

null131

order130

orthogonal149

products138

rectangular141

scalar multiplication138

singular142

skew-symmetric136

square95, 130, 140

subtraction137

symmetric134

trace132

transpose133

unit131

Maxima508

Mean382

population382

sample382

Median338, 383

Members5, 6

Mersenne, Marin28

Mersenne prime28

Minima508

Mixed partial derivative514

Möbius, August196, 407

Mode384

Multiple-angle

identities65

Multivectors447

N

Napier, John41

Natural number18

Nearest point to a line576

Negative number8

Non-associative algebra24

Non-commutative algebra23, 24

Non-linear interpolation298

Non-rational B-splines324

Non-uniform

B-splines328

rational B-splines328

Non-Uniform Rational B-Splines (NURBS)329

Norm

complex number168, 180

ordered pair174

quaternion257, 267

quaternion product261

Normal distribution390

table391

Normalised quaternion257

Notation3

Null matrix131

Number

algebraic20

arithmetic9

binary12

Cayley24

complex22

composite25

hexadecimal13

imaginary21

integer6, 19

irrational20

line8

Mersenne28

natural18

negative8, 9

octal12

perfect29

positive8, 9

prime25

rational6, 20

real6, 20

transcendental21

triangular29

O

Object space216

Octal number12

Octave24, 271

Octonion23

Odd function47, 564

One-to-one correspondence30

Open interval44

Ordered pair171, 248, 251

absolute value174

addition172

complex conjugate175

inverse176

modulus174

multiplying by a scalar172

norm174

product171, 172

quotient175

square173

subtraction172

Oriented axes72

Origin72

Orthogonal

matrices149, 219, 263

Outer product439, 448

3D445

imaginary properties450

P

Parallelogram341

Partial derivative510

chain rule517

first512

mixed514

second512

visualising513

Pascal, Blaise50, 71

Pascal's triangle50, 313, 474

Pearson, Karl393

Pearson's product-moment coefficient393

Peirce, Benjamin127

Peirce, Charles127

Perimeter relationships66

Perspective projection231

Pitch208, 219

Placeholder7

Planar surface patch329

Plane equation360

Cartesian form360

from three points366

general form362

parametric form363

Plücker, Julius196

Poincaré, Henri2

Point inside a triangle350, 420

Point reflected in a line578

Polar

coordinates77, 81

vector253

Polynomial equation20

Population mean382

Position vector112

Power

functions48

Prime

number distribution27

numbers25

Probability

variance387

Product

complex number167

pure quaternion258

quaternion258, 267

unit-norm quaternion259

Pseudoscalars447

Pseudovector253

Pure quaternion253

product258

Pythagorean triples75

Q

Quadratic

Bézier curve316

Bézier surface patch330

equation36

function72, 471

Quadrilateral340

Quaternion23, 243, 271, 454

addition251, 266

additive form254

algebra264

binary form255

conjugate255

interpolating307

inverse261, 268

matrix263, 281

norm257, 267

normalised257

product249, 250, 258, 259, 267, 272

pure253

square260, 268

subtraction251

unit248, 249, 254

unit-norm258, 267

Quotient

quaternion262

R

Radian55, 336

Radius of the inscribed circle425

Random variable384

Range45, 59, 384

Rational

B-splines324

coefficients20

number6, 20

Ratios409

Real

quaternion252

Real number6, 20

Rectangular matrix141

Recursive Bézier curve320

Reduced Row Echelon Form (RREF)152

Reflecting a vector465

Reflections454

Regression395

line395

Regular polygon341

Rhombus341

Riemann, Bernhard335, 556

Riemann sum556

Right-hand rule122

Right triangle339

Rodrigues, Olinde246, 279

Roll208, 219

Rotating about an axis211, 222

Rotation454

matrix178

Rotors458

Row vector106, 131, 138, 196

Russell, Bertrand34

S

Sample mean382

Sarrus, Pierre96

Sarrus's rule96, 133

Scalar product113, 114

Secant58

Second derivative510

Second-order determinant87

Seki, Takakazu86

Series48

Servois, François-Joseph246

Set5, 6

well-ordered6

Sine58

differentiating483

rule62, 461

Singular matrix142

Skew-symmetric matrix136

Space partitioning346

Sphere touching a plane584

Spherical polar coordinates78, 82

Square

complex number167

quaternion260, 268

Square determinant

order97

Square matrix95, 130, 140

Square-root of i

complex number170

matrix182

ordered pair176

Squarewave function560

Standard deviation388

Standard normal distribution390

Statistics379

Stem and leaf diagram381

Straight line equation356

Subset6

Subtracting

complex numbers166

matrices179

ordered pairs172

quaternions251

Surface patch329

Symmetric

functions436

matrix134

T

Tait, Peter Guthrie244

Tangent58

Thales336

Theorem of

Pythagoras58, 75, 76, 340

Thales339

Third-order determinant89, 96

3D

complex numbers118

coordinates76

reflections455

rotation transform207

transforms206

vector108

Three intersecting planes370

Total derivative518

Trace132

Transcendental number21

Transform

affine203

2D194

2D reflection195, 199, 204

2D rotation about a point205

2D scaling194, 198

2D shearing200

2D translation194, 198

3D reflection213

3D scaling206

3D translation206

Transforming vectors228

Transpose matrix133

Trapezoid340

Triangle

centre of gravity338

equilateral339

isosceles338

right339

Triangular

function565

numbers29

Trigonometric

function56, 72

identities61

interpolation298

inverse function59

ratios56

Trigonometry55

Trivector446, 447

2D

analytic geometry344

polygons73

reflections455

rotations456

scaling transform203

Two's complement17

U

Uniform B-splines325

Unique factorisation theorem25

Unit

matrix131

normal distribution390

normal vector122

quaternion254

vector112

Unit-norm

quaternion258, 259, 267

V

Variance385

probability387

Vector104

addition111

basis105

Cartesian113

column106, 128, 131, 138, 196

dimension106

interpolating304

magnitude108

normalising112

normal to a triangle572

position112

product113, 117

row106, 131, 138, 196

scaling110

space105

subtraction111

3D108

transforming228

unit112

Vertices73

Virtual camera216

Volume of a tetrahedron430

W

Warren, John104

Weierstrass, Karl469

Well-ordered set6

Wessel, Caspar103

Whitehead, Alfred North34

Wiles, Sir Andrew John76

Wilson, Edwin Bidwell104, 246

Wittgenstein, Ludwig2

Witt, Jan de86

World space216

X

XY-plane71

Y

Yaw208, 219

Z

Zero7