Vector Geometry for Computer Graphics



Similar documents
Resistive Network Analysis. The Node Voltage Method - 1

EQUATIONS OF LINES AND PLANES

EN3: Introduction to Engineering. Teach Yourself Vectors. 1. Definition. Problems

WHAT HAPPENS WHEN YOU MIX COMPLEX NUMBERS WITH PRIME NUMBERS?

9.3. The Scalar Product. Introduction. Prerequisites. Learning Outcomes

Mathematics. Vectors. hsn.uk.net. Higher. Contents. Vectors 128 HSN23100

Vectors Recap of vectors

Math 314, Homework Assignment Prove that two nonvertical lines are perpendicular if and only if the product of their slopes is 1.

. At first sight a! b seems an unwieldy formula but use of the following mnemonic will possibly help. a 1 a 2 a 3 a 1 a 2

Vector differentiation. Chapters 6, 7

A.7.1 Trigonometric interpretation of dot product A.7.2 Geometric interpretation of dot product

This circuit than can be reduced to a planar circuit

Appendix D: Completing the Square and the Quadratic Formula. In Appendix A, two special cases of expanding brackets were considered:

Vectors and dyadics. Chapter 2. Summary. 2.1 Examples of scalars, vectors, and dyadics

Polynomial Functions. Polynomial functions in one variable can be written in expanded form as ( )

Vectors and dyadics. Chapter 2. Summary. 2.1 Examples of scalars, vectors, and dyadics

LINEAR TRANSFORMATIONS AND THEIR REPRESENTING MATRICES

where the coordinates are related to those in the old frame as follows.

Use Geometry Expressions to create a more complex locus of points. Find evidence for equivalence using Geometry Expressions.

Reasoning to Solve Equations and Inequalities

Answer, Key Homework 10 David McIntyre 1

Section 5-4 Trigonometric Functions

21 Vectors: The Cross Product & Torque

Lecture 3 Gaussian Probability Distribution

Vectors. The magnitude of a vector is its length, which can be determined by Pythagoras Theorem. The magnitude of a is written as a.

Face Verification Problem. Face Recognition Problem. Application: Access Control. Biometric Authentication. Face Verification (1:1 matching)

Experiment 6: Friction

Support Vector Machines

Or more simply put, when adding or subtracting quantities, their uncertainties add.

Recurrence. 1 Definitions and main statements

The Velocity Factor of an Insulated Two-Wire Transmission Line

5.2. LINE INTEGRALS 265. Let us quickly review the kind of integrals we have studied so far before we introduce a new one.

Linear Circuits Analysis. Superposition, Thevenin /Norton Equivalent circuits

Angles 2.1. Exercise Find the size of the lettered angles. Give reasons for your answers. a) b) c) Example

8.5 UNITARY AND HERMITIAN MATRICES. The conjugate transpose of a complex matrix A, denoted by A*, is given by

Factoring Polynomials

Example A rectangular box without lid is to be made from a square cardboard of sides 18 cm by cutting equal squares from each corner and then folding

Pure C4. Revision Notes

Bayesian Updating with Continuous Priors Class 13, 18.05, Spring 2014 Jeremy Orloff and Jonathan Bloom

MATH 150 HOMEWORK 4 SOLUTIONS

PROF. BOYAN KOSTADINOV NEW YORK CITY COLLEGE OF TECHNOLOGY, CUNY

Luby s Alg. for Maximal Independent Sets using Pairwise Independence

PHY 140A: Solid State Physics. Solution to Homework #2

Scalar and Vector Quantities. A scalar is a quantity having only magnitude (and possibly phase). LECTURE 2a: VECTOR ANALYSIS Vector Algebra

Math 135 Circles and Completing the Square Examples

CURVES ANDRÉ NEVES. that is, the curve α has finite length. v = p q p q. a i.e., the curve of smallest length connecting p to q is a straight line.

Goals Rotational quantities as vectors. Math: Cross Product. Angular momentum

Geometry 7-1 Geometric Mean and the Pythagorean Theorem

1 Example 1: Axis-aligned rectangles

Section 5.3 Annuities, Future Value, and Sinking Funds

4.11 Inner Product Spaces

Lecture 5. Inner Product

6.2 Volumes of Revolution: The Disk Method

SPECIAL PRODUCTS AND FACTORIZATION

Fuzzy Clustering for TV Program Classification

Brillouin Zones. Physics 3P41 Chris Wiebe

1.2 The Integers and Rational Numbers

Using Series to Analyze Financial Situations: Present Value

Simple Interest Loans (Section 5.1) :

Irregular Repeat Accumulate Codes 1

Integration. 148 Chapter 7 Integration

Algebra Review. How well do you remember your algebra?

Vision Mouse. Saurabh Sarkar a* University of Cincinnati, Cincinnati, USA ABSTRACT 1. INTRODUCTION

and thus, they are similar. If k = 3 then the Jordan form of both matrices is

Boolean Algebra. ECE 152A Winter 2012

Rotation Kinematics, Moment of Inertia, and Torque

Graphs on Logarithmic and Semilogarithmic Paper

Lectures 8 and 9 1 Rectangular waveguides

8.4. Annuities: Future Value. INVESTIGATE the Math Annuities: Future Value

Inter-Ing INTERDISCIPLINARITY IN ENGINEERING SCIENTIFIC INTERNATIONAL CONFERENCE, TG. MUREŞ ROMÂNIA, November 2007.

n + d + q = 24 and.05n +.1d +.25q = 2 { n + d + q = 24 (3) n + 2d + 5q = 40 (2)

Extending Probabilistic Dynamic Epistemic Logic

Lecture 2: Single Layer Perceptrons Kevin Swingler

Newton-Raphson Method of Solving a Nonlinear Equation Autar Kaw

Section 5.4 Annuities, Present Value, and Amortization

1. Math 210 Finite Mathematics

Multiplication and Division - Left to Right. Addition and Subtraction - Left to Right.

Question 2: What is the variance and standard deviation of a dataset?

Faraday's Law of Induction

2 DIODE CLIPPING and CLAMPING CIRCUITS

Optimal Pricing Scheme for Information Services

v a 1 b 1 i, a 2 b 2 i,..., a n b n i.

Small Business Networking

FAULT TREES AND RELIABILITY BLOCK DIAGRAMS. Harry G. Kwatny. Department of Mechanical Engineering & Mechanics Drexel University

Small Business Networking

Physics 43 Homework Set 9 Chapter 40 Key

7.5. Present Value of an Annuity. Investigate

The OC Curve of Attribute Acceptance Plans

BERNSTEIN POLYNOMIALS

MODULE 3. 0, y = 0 for all y

Answer: A). There is a flatter IS curve in the high MPC economy. Original LM LM after increase in M. IS curve for low MPC economy

Harvard College. Math 21a: Multivariable Calculus Formula and Theorem Review

Homework 3 Solutions

GRAVITY DATA VALIDATION AND OUTLIER DETECTION USING L 1 -NORM

Small Business Networking

Causal, Explanatory Forecasting. Analysis. Regression Analysis. Simple Linear Regression. Which is Independent? Forecasting

Transcription:

Vector Geometry for Computer Grphcs Bo Getz Jnury, 7 Contents Prt I: Bsc Defntons Coordnte Systems... Ponts nd Vectors Mtrces nd Determnnts.. 4 Prt II: Opertons Vector ddton nd sclr multplcton... 5 The Dot-Product of two ectors. 6 Projectons.. 7 The Cross-Product of Two D Vectors 8 Mtrx Multplcton 9 Prt III: Applctons The equton of lne or ry The equton of plne... Outwrd-pontng normls. Fndng the ewer coordnte xes The dstnce from pont to lne. The dstnce from pont to plne.. 4 Determnng f pont s nsde conex polygon. 4 Determnng f pont s nsde conex polyhedron... 5 Algorthm for fndng reflecton rys. 5 Prt IV: Ry Intersecton Algorthms Ry-Sphere Intersecton, Algerc Verson. 7 Ry-Sphere Intersecton, Geometrc Verson 7 Ry-Ellpsod Intersecton. 8 Ry-Plne Intersecton... 9 Ry-Polygon Intersecton...9 Fndng the ntersecton of two lnes n plne. 9 Ry-Polyhedron ntersecton.

Prt I: Bsc Defntons Coordnte Systems Most D geometry s pctured wth the frst coordnte on the horzontl xs nd the second coordnte on the ertcl xs, s n The D stuton s somewht more complex. ote tht the followng two coordnte systems re essentlly the sme; we cn rotte one nto the other: On the other hnd, the followng pr re dfferent; no set of rottons wll conert one xs nto the other: The usul wy to thnk of ths s tht coordnte xes he hndedness. Coordnte xes re ether rght-hnded or left-hnded. If you lel your ndex fngers wth n x, your mddle fngers wth y nd your thums wth z, then you wll e le to lgn one

of your hnds wth gen xs. For the two systems llustrted mmedtely oe, you should e le to lgn the fngers of your left hnd wth the system on the left. Ths mens t s left-hnded system. Smlrly, the system on the rght mtches the fngers of your rght hnd nd so s rght-hnded system. Ponts nd Vectors A pont n n-dmensonl spce s just collecton of n lues tht cn e consdered the pont s coordntes. A ector n n-dmensonl spce s lso collecton of n lues. The dfference etween pont nd ector les not n the coordntes, ut rther n the wy we nterpret these coordntes. The coordntes of pont ge t poston n spce. For exmple, the pont (, ) mght e drwn: A ector, on the other hnd, prodes drecton nd mgntude rther thn poston. You cn thnk of ector <, > s extendng from ny pont (x, y) to the pont (x+, y+). All of the ectors n the followng pcture re <, >, just gen dfferent strtng ponts. Alterntely, the ector extendng from pont (x, y ) to the pont (x, y ) s <x -x, y -y >. Ths s n mportnt fct tht we wll use n mny stutons. The length or mgntude of ector s the squre root of the sums of the squres of ts coordntes. The length of ector s often wrtten. For exmple, the length of the ector <, > s + =. An esy wy to mke ector of length n gen drecton s to frst fnd ny ector n ths drecton, then to dde oth coordntes of

ector y ts length. Thus, ector n the sme drecton of <, > ut hng length s,. Vectors wth length re commonly clled unt ectors. + + For -dmensonl geometry there re stndrd nmes for the unt ectors tht pont long the three xes: s the ector <,, >, j s <,, > nd k s <,, >. Mtrces nd Determnnts 8 A -dmensonl mtrx s rectngulr rry of numers, s n. The sze 9 5 of such mtrx s n m where n s the numer of rows nd m s the numer of columns. Thus, the mtrx oe hs sze. We use mtrces n computer grphcs to represent trnsformtons, splne cures nd surfces, textures, nd mny other thngs. A determnnt s n operton tht cn e ppled to n n mtrx to produce sngle lue. The determnnt of mtrx A s often wrtten A. The defnton of the determnnt s recurse. Frst, the determnnt of mtrx s = d c. c d 4 Thus, = =. Then, the determnnt of mtrx s defned n terms of 5 determnnts: c e f d f d e d e f = + c = ( e fh) ( d gf ) + c( dh ge) h g g h g h ote tht ths multples ech element of the top row tmes the determnnt tht results from remong tht element s row nd column from the grd. The results of these products re put nto n lterntng sum. For exmple, we compute 4 4 = + 6 6 6 = ( 4 ) ( ) + ( 4 4) = 56 = 7 4 4

There re mny wys to nterpret the menng of determnnt. One smple nterpretton concerns D prllelogrms nd D prllelppeds. In the D cse, consder the ectors u = <u, u > nd = <, >. Then the re of the prllelogrm formed y u nd, s Are = u u = u u Smlrly, wth three D ectors <u, u, u > <,, > nd <w, w, w > we cn defne prllelpped, whose olume s Volume = u w u w u w Determnnts he mny uses, ut we wll prmrly use them to defne nd elute the cross product of two D ectors. Prt II: Opertons Vector ddton nd sclr multplcton We cn dd or sutrct two ectors of the sme sze y summng correspondng coordntes: <, 4, -> + <5,, 6> = <7, 5, 5> We cn multply ector y sclr y multplyng ech coordnte of the ector y the sclr; the result s ector: <, 5, >* = <6, 5, > Both of these opertons he smple geometrcl nterpretton. Recll tht we cn thnk of ector s prodng drecton nd dstnce. The sum of two ectors 5

represents mong n the drecton of the frst ector for ts dstnce, then n the drecton of the second for ts dstnce. For exmple, the pcture elow on the left shows two ectors A nd B. The pcture on the rght shows the sum A+B: Fnlly, the pcture elow shows the sum A+B+B+B = A+B: Any sclr multple of ector results n prllel ector. In fct, two ectors re prllel f nd only f ech s sclr multple of the other. The Dot Product of Two Vectors There re seerl wys to multply two ectors together. Whle they re ll mportnt for grphcs, the one most frequently used s the dot-product, whose nme comes from the fct tht t s wrtten wth dot etween the two ectors. The dot-product cn e ppled to ny two ectors of the sme sze; t s computed y multlplyng the correspondng coordntes of the ectors nd summng ll of these products. Thus <, > <c, d> = c+d. nd <,, > <4, 5, 6> = 4 + + 8 =. There s ery useful geometrcl nterpretton of the dot product: If u nd re two ectors then u = u cos( θ ) where θ s the ngle etween u nd. For exmple, snce cos() =, f two ectors re pontng n the sme drecton then ther dot product s the product of ther lengths. In prtculr, for ny ector u, u u = u. Moreoer, snce o o ( 9 ) = cos( 7 ) cos =, two ectors re perpendculr f nd only f ther dot product s. Ths s one of the most mportnt fcts from ector geometry nd s used throughout computer grphcs. It should e oous tht dot products re commutte ( = ). 6

Projectons It s sometmes useful to fnd the projecton of one ector n the drecton of nother. The followng pcture shows the setup for ths. We wnt to project ector B onto ector A. The followng pcture llustrtes the derton. We wnt to fnd ector p, whch s the projecton of B onto A. Angle Θ s the ngle etween A nd B, The de s to frst fnd the length of p, then to multply ths length tmes unt ector n A the drecton of A: p = p A Here s the derton: p A B A B = cos ( θ ) = so p = B A B A A A B p = p = A A A Altogether, the projecton of B onto A s A B A A We cn lso fnd the projecton of ector onto plne. Here s the setup: we strt wth the plne nd ector B; we wnt to fnd the projecton of B onto the plne, whch s ector p; 7

8 To sole ths we ntroduce ector, the norml to the plne, nd ector r, the projecton of B onto : We know how to clculte r; ths s just the projecton of one ector onto nother: B r = ow note tht p+r = B, so p = B-r. Altogether, the projecton of B onto the plne wth norml s B B The Cross-Product of two D ectors The cross-product s nother wy to multply two ectors. Ths tme the result s ector. Cross products re only defned for D ectors. There re mny equlent defntons for the cross-product. Perhps the most common defnton s,,,, k j = where, j, nd k re the unt ectors prllel to the coordnte xes. An equlent formulton usng mtrx multplcton (see elow f you don t recll how to multply mtrces) s =,,,, Fnlly, there s geometrcl nterpretton: ) sn(θ n u u =, where θ s the ngle etween u nd nd n s the unt ector norml to oth u nd gen y the rght-hnd

rule: f you put the ndex fnger of your rght hnd n the drecton of u nd your mddle fnger n the drecton of, then your thum wll pont n the drecton of n. Ths nterpretton mkes cler the most essentl fcts out the cross-product: t ges ector norml to the two nput ectors, nd the cross-product of two prllel ectors s. Some people restte the geometrcl nterpretton s: the cross-product u s ector norml to oth u nd n the drecton gen y the rght-hnd rule whose mgntude s the re of the prllelogrm determned y u nd. The mn use of cross-products s n fndng norml ectors. For exmple, f you know three ponts n plne nd you wnt to fnd the n m norml ector to the plne, fnd two non-prllel ectors etween the three ponts nd tke the cross-product of these ectors. Mtrx multplcton Suppose A nd B re mtrces. It s possle to multply A B f mtrx A hs sze n m nd mtrx B hs sze m p (.e., f the numer of columns of A s the sme s the numer of rows of B.) The resultng mtrx hs sze n p. The entry n the th row nd j th column of the result s the dot-product of the th row of A wth the jth column of B. For exmple, consder the product. Ths multplcton cn 4 e performed ecuse the left mtrx hs columns nd the rght mtrx rows. The entry n the frst row nd frst column of the result s the dot product of the frst row of the left mtrx, [ ] wth the frst column of the rght mtrx,. Ths dot product s 4. The entry n the frst row, second column of the result s the dot product of [ ] wth, whch s 7. Contnung on, we see tht 4 7 4 = 4 7 4 It s esy to see tht mtrx multplcton s not commutte. Indeed, BA mght not een e defned when AB s. Mtrx multplcton s, howeer, ssocte. 9

Mtrces re used for mny thngs n grphcs. Perhps the most typcl pplcton of mtrces s to represent trnsformtons. Mtrx T mght represent prtculr trnsformton; to pply ths trnsformton to pont x, we multply xt. To frst pply trnsformton T to x, then pply T to the result, we multply xt T. Becuse mtrx multplcton s ssocte, t mkes no dfference f we group ths s (xt )T or s x(t T ). The ltter formulton s conenent f there re numer of ponts to whch ths sequence of trnsformtons must e ppled ecuse t llows us to multply T T once,, nd then pply the result to ech pont n turn wth one mtrx multplcton. Becuse of ths, some old texts refer to mtrx multplcton s conctentng mtrces to represent the composton of trnsformtons. Prt III: Applctons The equton of lne or ry The y=mx+ equton for lne tht you lerned n hgh school s not ery useful for grphcs ecuse t s lmted to dmensons. We more commonly use the ector form of lne, whch cn e ppled to ny numer of dmensons. The equton of the lne through pont prllel to ector s p = + t Here t s sclr prmeter nd p s n rtrry pont on the lne. For exmple, suppose we need the equton of the lne through ponts <,, > nd <4,, 5>. A ector prllel to ths lne s the ector from <,, > to <4,, 5>, whch s <4-, -, 5-> = <, -, >. The lne s then p = <,, > + t<, -, > We get ponts on the lne y ssgnng lues to t. For nstnce, f t= we get <,, > + <4, -, 4> = <4, -, 7>. Alterntely, we cn use ths equton for the lne to get three prmetrc equtons for x, y, nd z n terms of t: <x, y, z> = <,, > + t<, -, > so x = + t y = t z = + t In ry trcng we need the equton of ry, or hlf-lne. A ry hs exctly the sme equton s lne: p = + t, only for rys the prmeter t cnnot he negte lues.

The equton of plne Suppose we need to fnd the equton of the plne tht hs norml ector =<A,B,C> nd tht psses through the pont (,, c): Let (x,y,z) e ny pont n the plne. Snce s norml to the plne t s norml to ech ector lyng n the plne. In prtculr, t s norml to the ector from (,,c) to (x,y,z); ths ector s <x-, y-, z-c>. In other words x y z c =. Ths equton cn e rewrtten s A B C x y z c =, or s Ax + By + Cz = A + B + Cc. In other words, the equton of plne wth norml ector <A, B, C> s Ax+By+Cz=constnt. You cn fnd the constnt y pluggng ny pont tht s known to e n the plne nto Ax+By+Cz. If you need to fnd the equton of the plne contnng known ponts, tke the crossproduct of two non-prllel ectors connectng these ponts to get the norml; then proceed s oe. For exmple, to fnd the plne contnng (,, ), (,, ) nd (,, ), we frst need two ectors. The ector from (,, ) to (,, ) s <,, >. The ector from (,, ) to (,, ) s <,, >. The cross-product of <,, > wth <,, > s <,, ->. Thus, the equton of the plne s x-z = constnt. We cn put ny of the gen ponts nto ths to see tht the constnt s. The plne s x-z =. Outwrd-pontng ormls A polygon s ody tht les n plne nd s ounded y edges tht re lne segments, lke trngle or n octgon. A polyhedron s D ody ounded y fces tht re polygons, such s cue or pyrmd. Sometmes t s helpful to fnd n outwrd-pontng norml to polygon or polyhedron. In oth cses ths s ector tht s norml to gen fce or edge nd ponts towrds the outsde of the ody.

Consder frst the cse of polyhedron: If the ertces of the fce re numered p, p, n counter-clockwse order then we cn compute the outwrd-pontng norml from the cross-product of two of the edges. For p p p, or strtng from ny pont p, exmple, t s gen y ( ) ( p ) ( p p ) ( p p ) + + + +. The rght-hnd rule for cross-products gurntees tht ths s the outwrd-pontng norml nd not the nwrd-pontng norml. The cse of polygon s smlr: Ths tme we wnt to fnd the norml n tht les n the sme plne s the polygon nd s norml to gen edge. If s the norml to ths entre plne nd f the edge n consderton s the edge from p to p + (where gn the ertces he een numered counterclockwse strtng from p ), then the outwrd pontng norml s n = ( p+ p ). Of course, f s not gen t cn e computed from the cross-product of ny two edges of the polygon.

Fndng the ewer coordnte xes Vewer coordntes re frequently specfed n terms of left-hnded coordnte system wth orgn t the ewer s poston nd z-xs pontng n the drecton the ewer s lookng. Rther thn drectly gng the three coordnte xes, mny system prefer to determne ths system from the ewer s poston, lookt pont n the drecton the ewer s lookng, nd n up ector tht specfes the ertcl drecton. Unless there s ddtonl nformton, we ssume tht the ewer s x-xs s orthogonl to the up ector. If the ewer s stndng ertclly her y-xs wll pont n the drecton of the up ector, ut the ewer cn len oer nd stll he her x-xs orthogonl to ths up ector. We wll fnd ectors V x, V y nd V z prllel to the three xes. Frst, V z ponts from the wer to the lookt pont: V z = lookt-ewer. ext, V x s norml to oth V z nd the up ector. From the rght-hnd rule for cross-products we see tht V = V up. Fnlly, V = V V y x z x z The dstnce from pont to lne Suppose we he the lne x = t + p ( lne through pont p prllel to ector ) nd seprte pont p. We wnt to fnd the dstnce from p to the lne. Let w e the ector from p to p. The followng pcture shows the setup: We know tht the cross-product of nd w s ector whose length s the re of the prllelogrm determned y nd w. Ths re s lso gen y the length of multpled tmes the dstnce from p to the lne tht forms the se of the prllelogrm. Thus w = dst, or w dst =. An een smpler formton s dst = u w, where u s unt ector prllel to the lne nd w s n ector from the lne to p.

The dstnce from pont to plne. A smlr prolem s fndng the dstnce from pont p=(p, p, p ) to the plne Ax+By+Cz=D. Let =(,, ) e ny pont n the plne. Let ector e the ector from to p. As you cn see from the pcture, the dstnce from p to the plne s the length of the projecton of onto the norml ector = <A, B, C>. The projecton s ( ). Ths ector hs length. We know tht =<A, B, C>, =<p -, p -, p - >, nd snce s pont n the plne, A +B +C =D. we cn smplfy the dstnce from p to the plne to Ap + Bp + Cp D A + B + C Determnng f pont s nsde conex polygon Gen polygon (whch y defnton les n plne) nd sngle pont n the sme plne, we would lke n lgorthm for determnng whether the pont les nsde the polygon. The followng lgorthm only pples to conex polygons those wth the property tht gen ny two ponts nsde the polygon, the entre lne segment connectng those two ponts must le nsde the polygon. Such polygons re the ntersecton of hlf-plnes, whch mens tht f you extend the oundry edges nto nfnte lnes the polygon wll lwys le completely on one sde of ech edge lne. If pont s on the sme sde of ech edge s the polygon, then t must le nsde the polygon. For ths lgorthm we ssume tht the ertces of the polygon re numered p, p, p,. n counterclockwse order. Edge e extends from p to p +. Vector s norml to the plne contnng the polygon; ths s esy to construct s e e, or s e e + for ny. Vector n s n outwrd-pontng norml for edge e ; we cn construct ths s e. Here s n llustrton of ll of these tems: 4

n p+ p = p+ = n p. It s esy to extend ths to show tht n p = n p ote tht e =p + -p, nd n s norml to e, so ( ). Ths mens tht n for ny pont p on the lne defned y edge e. Ths lets us splt the plne nto two regons: ponts p for whch n p n p nd ponts p for whch n p n p. Whch sde s the polygon on? Consder pont p +n, whch s outsde the polygon ecuse n s n outwrd-pontng norml. n ( p + n ) = n p + n n = n p + n > n p. Thus the hlf-plne contnng ponts p where n p n p s on the sde of the edge ponted to y the outwrd-pontng norml; t does not contn the polygon. The hlf-plne defned y n p n p does contn the polygon. Our lgorthm for determnng f pont p s nsde the polygon s thus: p s nsde the polygon f n p n p for ech edge e, where n s the outwrdpontng norml to edge e. Determnng f pont s nsde conex polyhedron The rgument oe for conex polygons lso pples to conex polyhedron: p s nsde the polyhedron f n p n p for ech fce f, where n s the outwrdpontng norml to fce f. Algorthm for fndng reflecton rys The Phong model for speculr reflectons hs lght reflectng from surfce n such s wy tht ngle of ncdence equls ngle of reflecton. To use ths model we need to fnd the reflecton drecton, gen the surfce norml nd the drecton of the lght source: 5

In ths pcture L s the drecton of the lght source nd R s the drecton we wnt to clculte. s the surfce norml. The ngle etween nd L should e the sme s the ngle etween nd R. We cn sole ths prolem usng projectons. The followng dgrm shows the ddtonl prts we need: L Vector p s the projecton of L onto, so p =. Vector q connects L wth ts projecton: L+q=p, so q=p-l. Fnlly, R=p+q=p-L. Puttng ll of ths together, we see tht L R = L If we choose to e unt norml to the surfce we cn mke ths een eser: R = ( L) L In ny cse ths formul produces ector R wth the sme length s L. Prt IV: Ry Intersecton Algorthms Ths s collecton of lgorthms used n ry trcng for fndng where ry ntersects rous shpes. The ry hs n equton of the form P = P + t, where P s the strtng pont of the ry nd s ector prllel to the ry. These lgorthms generlly ge lue of the prmeter t. If t < there s no ntersecton; f t >= you cn use the expresson P + t to get the ctul pont of ntersecton. All of these lgorthms mke no ssumpton out the length of. You need to e creful out usng lgorthms off the nternet for ths; mny other lgorthms he n unstted ssumpton tht =. 6

Ry-Sphere Intersecton, Algerc Verson Ths uses the qudrtc formul to fnd t. Our ry s P = P + t; the sphere s centered t pont C nd hs rdus r. A ector formulton of the sphere s P C = P C P C = r r, or ( ) ( ) the ry defnton of P ges ( ) ( ). Insertng P + t C P + t C = r. To smplfy ths crete t A t A = r. We cn multply ths new ector A=C-P. Our equton s now ( ) ( ) out nd collect terms, rememerng tht = : ( A) + A r =. t t It s now smple mtter to use the qudrtc formul to fnd t: ( A) ± 4( A) 4 ( A r ) t = Of course, f the quntty nsde the squre root s negte there s no ntersecton. Ry-Sphere Intersecton, Geometrc Verson Ths s n lternte wy to fnd the ntersecton. It does more geometry nd ges smpler clculton, though t s t hrder to follow. In mny stutons t ges qucker ext when the ry msses the sphere. Agn we let A=C-P ; ths s ector from the strtng pont of the ry to the center of the A sphere. Let R e the projecton of A onto ; R =. ow let q e the dstnce from the center of the sphere to the ry. Becuse R s the projecton of A, the pcture oe shows tht q + R = A. Of course, f q > r then the ry does not ntersect the sphere nd we cn stop. If there s n ntersecton we let h e hlf of the length of the chord formed y the ry nsde the crcle. The pcture oe shows tht h + q = r, so 7

h nd = r q. Fnlly, the dstnces of the two ntersecton ponts from P re R h R + h. We get the ctul t-lues y sclng these y the length of. Altogether, here s the sequence of clcultons needed to fnd the ntersecton: A=C-P A R = q = A R If q > r hlt; there s no ntersecton. h = r q = r + R A R h R + h The two ponts re P + nd P + Ry-Ellpsod Intersecton An ellpsod s the D nlog of n ellpse. One wy to wrte n equton for t s ( x c ) ( y c ) ( z c ) + + =. Such n ellpsod hs,, nd c s hlf the lengths c of ts three mjor xes. To ge ector form of ths equton, let M = ; ths c represents sclng trnsformton. Then for ny pont P=(x, y, z) we he x y z PM =. An ellpsod centered t C wth hlf-xes of lengths,, nd c c conssts of ponts P where ( C) M =. P ote tht ths sys tht n ellpsod s ody tht cn e scled nto the unt sphere. The rest of the derton follows closely the lgerc form of the ry-sphere ntersecton lgorthm. We cn wrte the ellpsod equton s ( PM CM ) ( PM CM ) =. We wnt to fnd such ponts where P=P +t. Insertng ths nto the equton ges P M + tm CM P M + tm CM. Let = M nd let P =P M-CM. Our ( ) ( ) = equton s ( + t ) ( P + t ) = P + tp + t. P = Ths s esy to sole for t wth the qudrtc formul. 8

Ry-Plne Intersecton Ths ntersects ry wth n nfnte plne. Once gn, we he ry P = P + t. A plne hs equton Ax+By+Cz=D. We cn lso wrte ths P = D, where =<A,B,C> s P + t =, or the norml to the plne. Insertng P = P + t nto ths, we he ( ) D D P t = D P. Ths s esy to sole for t: t =. Of course, ths mkes no sense f =, ut n tht cse s orthogonl to the plne s norml nd so the ry ether s completely contned n the plne or else msses the plne ltogether. Of course, once we he the pproprte lue of t we cn otn the ctul pont of ntersecton from P = P + t. Ry-Polygon Intersecton To ntersect ry wth polygon, frst fnd the plne tht contns the polygon (ts norml cn e found from the cross-product of ny two non-prllel edges of the polygon) nd fnd the pont where the ry ntersects tht polygon. You must then decde f ths pont s nsde the polygon. If the polygon s conex you cn use the lgorthm gen oe. Ths lgorthm fls n the cse where the ry s orthogonl to the norml to the plne contnng the polygon. In mny stutons t s suffcent to report no ntersecton n ths cse. If, howeer, the ry les n the sme plne s the polygon nd your need to fnd the ntersecton, t cn e found y ntersectng the ry wth the lne determned y ech edge of the polygon nd testng whether the resultng pont s nsde the polygon. An lgorthm for fndng the ntersecton of two lnes n plne, or ry wth lne n the sme plne, s gen elow. The smllest poste t-lue tht stsfes ths wll yeld the desred ntersecton. Fndng the ntersecton of two lnes n plne Ths lgorthm cn e used ether to ntersect two lnes n plne, or to ntersect ry wth lne n the sme plne. Suppose we he two lnes: P = P + t nd P = P + s. ote tht t s mportnt tht the two lnes he dfferent prmeter: they could ntersect, for exmple, t pont gen y t= on one lne nd s= on the other lne. We wnt to fnd the lues of t nd s tht result n the sme pont P on ech lne. Let e the norml to the plne contnng these lnes; ths cn e found, for exmple, s =. Let n e the norml n the plne to ector. As we he seen efore, eery pont on the lne P = P + s hs n P = n P. We wnt to fnd pont on the frst lne tht hs ths sme property. n P + t = n nd sole for t. Ths ges Thus, we set ( ) P n t = P n n P 9

Wth ths lue of t the pont of ntersecton s P + t Ry-Polyhedron ntersecton To ntersect ry wth polyhedron, we fnd the ntersecton of the ry wth the plne contnng ech of the fces of the polyhedron, nd then test whether the resultng ponts re nsde the polyhedron. An lgorthm s gen oe for determnng whether pont s nsde conex polyhedron, so f the polyhedron s conex ths soles the prolem. Agn, f the polyhedron s conex nd we know the ry strts outsde the polyhedron, t s suffcent to ntersect the ry wth the front-fcng fces. These re the fces whose outwrd pontng normls re n the opposte drecton from the ry. Tht s, f s the outwrd-pontng norml nd the ry s P = P + t, then we need to check the ntersecton of the ry wth the fce only f <.