Table Of ContentIntroduction to Geometric Computing
Sherif Ghali
Introduction to
Geometric Computing
123
SherifGhali,PhD
UniversityofAlberta
Edmonton
Canada
ISBN:978-1-84800-114-5 e-ISBN:978-1-84800-115-2
DOI:10.1007/978-1-84800-115-2
BritishLibraryCataloguinginPublicationData
AcataloguerecordforthisbookisavailablefromtheBritishLibrary
LibraryofCongressControlNumber:2008926727
(cid:1)c Springer-VerlagLondonLimited2008
Apartfromanyfairdealingforthepurposesofresearchorprivatestudy,orcriticismorreview,aspermit-
tedundertheCopyright,DesignsandPatentsAct1988,thispublicationmayonlybereproduced,stored
ortransmitted,inanyformorbyanymeans,withthepriorpermissioninwritingofthepublishers,orin
thecaseofreprographicreproductioninaccordancewiththetermsoflicencesissuedbytheCopyright
LicensingAgency.Enquiriesconcerningreproductionoutsidethosetermsshouldbesenttothepublishers.
Theuseofregisterednames,trademarks,etc.inthispublicationdoesnotimply,evenintheabsenceofa
specificstatement,thatsuchnamesareexemptfromtherelevantlawsandregulationsandthereforefree
forgeneraluse.
Thepublishermakesnorepresentation,expressorimplied,withregardtotheaccuracyoftheinformation
containedinthisbookandcannotacceptanylegalresponsibilityorliabilityforanyerrorsoromissions
thatmaybemade.
Printedonacid-freepaper
9 8 7 6 5 4 3 2 1
SpringerScience+BusinessMedia
springer.com
(cid:10)(cid:9)
Preface
If geometric computing is neither computer graphics nor computational geo-
metry, thenwhatisit? Briefly, itisthemathematicsandtheengineeringthat
underlieboth.
Thistext
• discusses how to design libraries for Euclidean, spherical, projective,
andorientedprojectivegeometries.
• derivesthenecessaryresultsineachgeometrybyappealingtoelemen-
tarylinearalgebra.
• givesaconcreteimplementationinC++forclassesineachlibrary.
• suggests that the time may have come for practitioners in computer
graphicsandincomputationalgeometrytodesignandimplementase-
queltoLEDA[67]andtoCGAL[23]basedonthefourgeometries.The
mainaimwouldbestandardization.
• shows examples for the failure of geometric systems when the types
floatordoublearetakenasasubstituteforthesetR.
• presents the graphics pipeline passing through oriented projective geo-
metry,whichmakesitpossibletotalksensiblyaboutclipping.
• discussesthenotionofcoordinate-freegeometry,averysimpleideathat
appearsnottohaveyetenteredthemainstream.
• presentstheclassicalrastergraphicsalgorithmsthataretraditionallyin-
troduced in an undergraduate computer graphics course. Doing so can
be done at a rapid pace after a base of geometric computing has been
introduced.
• briefly connects with the established and vibrant discipline of graph
drawing[32].
• discusseselementsofthenow-classicalmethodsofgeometricandsolid
modeling[24,65,51]. Thisalsoisdonewithconsiderablebrevityafter
theappropriategeometricsoftwarelayershavebeenintroduced.
• showshowgeometricalgorithmscanbedesignedandimplementedsuch
that combinatorial and geometric parts are separated. The geometry
wouldactasaplug-inforacombinatorialalgorithmtoyieldaconcrete
implementation.
• presentsalgorithmsforBooleanoperationsonregularsetsusingbinary
space partitioning. An arbitrary geometry satisfying separability can
bepluggedintothiscombinatorialstructuretoperformcomputationin
(cid:11)(cid:8)
(cid:10)(cid:9)
vi PREFACE
thecorrespondingspace. ExamplesareshownforusingEuclideanand
spherical geometries as a plug-in with separability as the only require-
mentfortheplug-in.
• introducesmethodsforcomputingvisibilitybyprojectingfromEuclid-
eann-spacetosphericaln−1-space,forn=2,3.
• seeks to define a common ground from which systems for computer
graphics,visualization,computationalgeometry,computer-aideddesign,
robotics, geographic information system, and computer vision can be
designedandimplemented.
The text also fills what appears to be a serious gap in the training of un-
dergraduate students in computer science, in mathematics, in physics, and in
mechanicalengineering. Manysoftwaresystemsbuiltinthesedisciplinesare
geometric, yet no body of knowledge has been collected that discusses the
issues involved in designing and implementing a geometric system. The ap-
propriate design of an undergraduate curriculum in computer science should
includeacourseongeometriccomputinginthesecondorthirdyear. Sucha
coursewouldbearequiredprerequisiteto(traditionallythird-orfourth-year)
computer graphics courses and an optional prerequisite to (traditionally late
undergraduateorearlygraduate)computationalgeometrycourses.
Computer Computer- Geographic
Graphics Computational Robotics Computer Aided Information
and Geometry Vision
Visualization Design Systems
GeometricComputing
ClassicalGeometry Computing
The notion that metric and topological information are isolated concep-
tuallyandshouldremainisolatedinageometricsystemhaslongbeenunder-
stood[85].ThegenericityofC++makesthisisolationfeasiblewhileimposing
neitherefficiencynortypesafetypenalties. Newquestionsemerge. Canone,
forinstance,buildCSGtreesoutofsphericalgeometryororientedprojective
geometry primitives? Knowing the answer as simply an intellectual exercise
wouldbeinteresting,butitwouldbeatleastasinterestingtofindthatdoingso
Elementary ispossibleandthatonecandosomethingwiththeresult.
Linear
Algebra
Prerequisites
Object Introductionto
Orientation Geometric
Thebackgroundexpectedisminimalandincludeselementarylinearalgebra,
(C++) Computing
acourseonobjectorientationandC++,aswellasfamiliaritywithbasicdata
structuresandalgorithms.Thatsaid,Chapters1to4takeaslowrampintended
DataStructures
as a recapitulation of many of the C++ constructs and of the linear algebra
andAlgorithms
needed.
(cid:11)(cid:8)
(cid:10)(cid:9)
PREFACE vii
GeometricClassNamingConvention
ThetextincludessampleC++codeformosttopicsdiscussed.Thecodecanbe
downloadedfromhttp://www.springer.com/978-1-84800-114-5. Inthediscus-
sionofthebasiclayersforthevariousgeometries, aconcretesketchisgiven
in C++ of what may arguably be some form of a canonical implementation.
Oncethebeginninglayersareestablished,C++isusedinlieuofpseudo-code.
One can indeed argue that an objective of good software design is to abolish
theneedforpseudo-code. Thefullimplementationcontainsallthedetailsand
shouldbeconsultedifneeded,butthetextcontainssufficientexcerptsforitto
beunderstandablewithoutreferringtoadditionalcode. Inasense, theelided
C++ code included still acts as a far more precise form of pseudo-code than
oneusingprose.
The exercises frequently refer to start-up code that will make it easier to
experimentwithanimplementationwithoutspendinganexcessiveamountof
time on issues unrelated to the topic considered. All start-up code samples
compile and run before adding any extra functionality. By releasing start-up
code,instructorscanexpectthatastudentwillbecapableofwritinganontriv-
ialgeometricprogramintwotothreehours. Thechaptergranularityischosen
suchthateachchaptercanbediscussedinonehourofinstruction.
The geometric classes use C++’s genericity and are parameterized by a
number type, although the first chapters discuss direct implementations for
Euclideangeometrytoisolatetheissuesandtointroducethemgradually.Each
genericgeometricclasshasatwo-lettersuffixthatidentifiesthegeometryand
thedimension. Thefollowingexamplesillustratethenomenclature.
• Point E3isaclassforapointinthe3DEuclideangeometryE3.
• Segment S2isaclassforasegmentinthe2DsphericalgeometryS2.
• Line P2isaclassforalineinthe2DprojectivegeometryP2.
• Plane T3 is a class for a plane in the 3D oriented projective geometry
T3.
Wheninstantiatingconcreteclasses, anadditionalsuffixsignalsthenum-
bertypeused. If,forexample,thegenericclassPoint E2isinstantiatedusing
the double built-in type, then the concrete class is called Point E2d. This is
donebythefollowingstatement.
typedefPoint E2<double>Point E2d;
This convention avoids naming clashes and makes it easy to develop a
systeminvolvingmultipletypes,dimensions,andprecisions.
Eachgeometryhasitsowninterpolationoperations,intersectionfunctions,
predicates,andmethodsforcomputingtransformations. Thefilenamesinthe
accompanying code also follow the naming convention just mentioned. The
filesfortheEuclideanline,forinstance,areshowninthefollowingtable.
It will occasionally be clear that an obvious optimization is omitted, but
“premature optimization is the root of all evil” and one should first get a de-
signrightandanimplementationcorrect,thenworryaboutnonasymptoticop-
timizations later. It is not necessary to convince those who have tales to tell
(cid:11)(cid:8)
(cid:10)(cid:9)
viii PREFACE
FilenamesforthegeometryoftheEuclideanline
interpolation e1.h
intersection e1.h
predicates e1.h
transformation e1.h
about a “clever optimization” that actually introduces a performance penalty
oftheimportanceoffirstaimingforanelegantandcleansystemdesign. Code
optimizationshouldbeperformedonlyaftercodeprofilinghassuggestedthat
itisnecessarytodoso. Inthebestofworlds,significantfurtherimprovements
should be done on the code before it has been optimized since a serious side
effectofcodeoptimizationisthatdatalosetheirtype;optimizationfrequently
resultsincodeobfuscation.
Many will consider that the frequent lack of mention of asymptotic com-
plexity is a serious omission. Such discussions are not included to focus on
whatliesattheintersectionofgeometryandcomputinginadditiontotimeand
space complexity, which are in any case treated extensively elsewhere. Of-
ten complexity is also a contentious issue that separates, and nearly defines,
fields. Avoiding complexity also dodges (perhaps too conveniently) debates
about whether worst-case complexity is overly pessimistic or whether it is
reasonable to assume that information about average time complexity can be
measuredbyafewempiricalcharts. Itisbesttoargue,alsoconveniently,that
geometriccomputingisdefinedsuchthatitremainsneutralinthisdiscussion.
OneviolationofC++programmingstyle,andoneforwhichIaskthefor-
givenessofthereader,istheformattingoffunctionargumentsandparameters.
Ihopethattheincreasedreadabilityaffordedbytheuseofproportionalfonts
totypesetthecodemorethanoffsetstheuseofformattingthatwillseemun-
orthodoxtomany.
I am grateful to Sylvain Pion, Stefan Schirra, and Michiel Smid for hav-
ing kindly commented on sections of this text. Needless to say, errors or
inaccuracies are my responsibility alone. This text has been designed us-
ing Peter Wilson’s memoir, which may well represent the next generation of
LATEXpackages—the package of compatible packages. Positioning figures in
themarginsisinspiredbyComputationalGeometry: AlgorithmsandApplica-
tions and I am grateful to the authors for sharing their book design. I would
alsoliketoacknowledgethefundingoftheNaturalSciencesandEngineering
ResearchCouncilofCanada.
IowemuchgratitudetoOtfriedCheongforhavingdevelopedtheipedraw-
ing package, which is used for all hand-drawn illustrations in this text. That
lineconcurrencyandpointcolinearityinthefiguresareindeedaccurateisen-
tirelyduetothissuperbdrawingpackage. Readerswillnodoubtwishtowrite
C++ code to try some of the ideas discussed in the pages that follow, but as
muchasthistexttriestoshowjusthowenjoyableitcanbetowriteageometric
program,simplyredrawingsomeoftheillustrationsusingipewillbeenlight-
ening. The graphical user interface scene surrounding C++ remains sorely
lacking in standardization. This text relies on Daniel Azuma’s well-crafted
GLOWuserinterfacelibrary. AnicecourseprojectwouldbetouseGLOWto
(cid:11)(cid:8)
(cid:10)(cid:9)
PREFACE ix
writeaninitialipe3d—forextracredit,theoutputwouldremainpurelyvecto-
rial(byrelyingonChapter32,itselfdependingonnearlyallprecedingchap-
ters).
A risk in technical writing is “telling your readers what you’re going to
tell them, telling them, and then telling them what you’ve told them” [119].
This brief introduction is necessary, but since I’ll spare the reader a conclu-
sion,itisworthwhiletoconcludebyaskingseveralquestionsthatwillputthe
“introduction”partofthetitleinperspective.
• Asdiscussedin§14.4and§18.6,thepossibilityofalibrarythatismore
concise than the one described here, yet one that, crucially, sacrifices
neithertypesafetynorefficiencyisintriguing.
• How can an extension that captures software design for what can be
tentatively called kinetic geometric computing [44] and for computer
animation[77]bedesigned?
• Howcanalibraryforhyperbolicgeometrybedesignedandimplemented
such that, for instance, tree and graph drawing algorithms can move
gracefullybetweenEuclidean,elliptic,andhyperbolicspaces?
• How can geometric algebra [33] be brought under the umbrella of the
frameworkpresentedhere(ortheotherwayaround)?
My hope is to have succeeded in not committing one of the cardinal sins of
technical writing, boring you, dear reader. I await your comments and hope
youwillgetasmuchenjoymentreadingthistextasIhadwritingit.
SherifGhali
February2008
(cid:11)(cid:8)
(cid:10)(cid:9)
Contents
Preface v
Part I Euclidean Geometry 1
1 2DComputationalEuclideanGeometry 3
1.1 PointsandSegments 3
1.2 ASeparateTypeforVectors 6
1.3 VectorNormalizationandDirections 9
1.4 AffineCombinations 10
1.5 Lines 11
1.6 VectorOrthogonalityandLinearDependence 13
2 GeometricPredicates 17
2.1 PredicateReturnType 17
2.2 TheTurnPredicate 18
2.3 SideofCirclePredicate 21
2.4 OrderPredicate 22
2.5 TheGeometryoftheEuclideanLineE1 23
2.6 ImmutabilityofGeometricObjects 24
2.7 Exercises 25
3 3DComputationalEuclideanGeometry 27
3.1 PointsinEuclideanSpace 27
3.2 VectorsandDirections 28
3.3 VectorOrthogonalityandLinearDependence 28
3.4 PlanesinSpace 29
3.5 LinesinSpace 30
3.6 SidednessPredicatesin3D 31
3.7 DominantAxis 32
3.8 Exercises 33
4 AffineTransformations 35
4.1 AffineTransformationsin2D 35
4.2 PropertiesofAffineTransformations 38
4.3 CompositionofAffineTransformations 39
4.4 AffineTransformationObjects 40
4.5 ViewportMapping 41
4.6 OrthogonalMatrices 42
(cid:11)(cid:8)