TEAMFLY3D Math Primer forGraphics and GameDevelopmentFletcher Dunnand Ian ParberryWordware Publishing, Inc.Library of Congress Cataloging-in-Publication DataDunn, Fletcher.3D math primer for graphics and game development / by Fletcher Dunn and Ian Parberry.p.cm.ISBN 1-55622-911-91. Computer graphics.2. Computer games--Programming.3. Computer science--Mathematics.I. Parberry, Ian.II. Title.T385 .D8752002006.6--dc212002004615CIP© 2002, Wordware Publishing, Inc.All Rights Reserved2320 Los Rios BoulevardPlano, Texas 75074No part of this book may be reproduced in any form or byany means without permission in writing fromWordware Publishing, Inc.Printed in the United States of AmericaISBN 1-55622-911-910 9 8 7 6 5 4 3 2 10205Product names mentioned are used for identification purposes only and may be trademarks of their respective companies.All inquiries for volume purchases of this book should be addressed to Wordware Publishing, Inc., at the aboveaddress. Telephone inquiries may be made by calling:(972) 423-0090ContentsAcknowledgments . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . xiChapter 1Introduction . . . . . . . . . . . . . . . . . . . . . . . 11.1 What is 3D Math? . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 11.2 Why You Should Read This Book . . . . . . . . . . . . . . . . . . . . . . . . 11.3 What You Should Know Before Reading This Book . . . . . . . . . . . . . . 31.4 Overview . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 3Chapter 2The Cartesian Coordinate System . . . . . . . . . . . . 52.1 1D Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 62.2 2D Cartesian Mathematics . . . . . . . . . . . . . . . . . . . . . . . . . . . . 92.2.1 An Example: The Hypothetical City of Cartesia . . . . . . . . . . . . . . 92.2.2 Arbitrary 2D Coordinate Spaces. . . . . . . . . . . . . . . . . . . . . . 102.2.3 Specifying Locations in 2D Using Cartesian Coordinates . . . . . . . . 132.3 From 2D to 3D . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 142.3.1 Extra Dimension, Extra Axis . . . . . . . . . . . . . . . . . . . . . . . 152.3.2 Specifying Locations in 3D . . . . . . . . . . . . . . . . . . . . . . . . 152.3.3 Left-handed vs. Right-handed Coordinate Spaces . . . . . . . . . . . . 162.3.4 Some Important Conventions Used in This Book. . . . . . . . . . . . . 192.4 Exercises. . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . . 20Chapter 3Multiple Coordinate Spaces . . . . . . . . . . . . . . 233.1 Why Multiple Coordinate Spaces? . . . . . . . . . . . . . . . . . . . . . ....