Ray-Triangle and Ray-Quadrilateral Intersections in Homogeneous Coordinates

Similar documents
CS-9645 Introduction to Computer Vision Techniques Winter 2019

Geometric transformations assign a point to a point, so it is a point valued function of points. Geometric transformation may destroy the equation

Robot Vision: Projective Geometry

MAT 3271: Selected Solutions to the Assignment 6

Multiple View Geometry in Computer Vision

521493S Computer Graphics Exercise 2 Solution (Chapters 4-5)

1 Appendix to notes 2, on Hyperbolic geometry:

Homogeneous Coordinates and Transformations of the Plane

Trig Functions, Equations & Identities May a. [2 marks] Let. For what values of x does Markscheme (M1)

1 Affine and Projective Coordinate Notation

Part II. Working and Playing with Geometry

Overview. By end of the week:

Downloaded from Class XI Chapter 12 Introduction to Three Dimensional Geometry Maths

Videos, Constructions, Definitions, Postulates, Theorems, and Properties

Mathematics Background

Lesson 2: Basic Concepts of Geometry

Ray Tracing. CPSC 453 Fall 2018 Sonny Chan

Therefore, after becoming familiar with the Matrix Method, you will be able to solve a system of two linear equations in four different ways.

Math 7 Glossary Terms

2 Solution of Homework

Tantasqua/Union 61 Math Alignment GRADE 5

Geometric Constructions

DEFINITIONS. Perpendicular Two lines are called perpendicular if they form a right angle.

Year 6 Mathematics Overview

Unit 6: Connecting Algebra and Geometry Through Coordinates

Geometric Algebra. 8. Conformal Geometric Algebra. Dr Chris Doran ARM Research

Computer Vision Projective Geometry and Calibration. Pinhole cameras

Chapter 1. Essentials of Geometry

Suggested problems - solutions

6 Mathematics Curriculum

Math 308, Section 101 Solutions to Study Questions for Final Exam (Thursday, December 16, 2004)

SUMMARY. CS380: Introduction to Computer Graphics Varying Variables Chapter 13. Min H. Kim KAIST School of Computing 18/04/26.

New Swannington Primary School 2014 Year 6

Geometry Definitions, Postulates, and Theorems. Chapter 3: Parallel and Perpendicular Lines. Section 3.1: Identify Pairs of Lines and Angles.

Number- Algebra. Problem solving Statistics Investigations

2 Second Derivatives. As we have seen, a function f (x, y) of two variables has four different partial derivatives: f xx. f yx. f x y.

Technische Universität München Zentrum Mathematik

Glossary Common Core Curriculum Maps Math/Grade 6 Grade 8

1.1 IDENTIFY POINTS, LINES AND PLANES

A.1 Numbers, Sets and Arithmetic

Geometry - Chapter 1 - Corrective #1

Geometry Reasons for Proofs Chapter 1

3 Solution of Homework

An Approach to Geometry (stolen in part from Moise and Downs: Geometry)

A point is pictured by a dot. While a dot must have some size, the point it represents has no size. Points are named by capital letters..

Barycentric Coordinates and Parameterization

Technische Universität München Zentrum Mathematik

MATH 890 HOMEWORK 2 DAVID MEREDITH

(1) Page #1 24 all. (2) Page #7-21 odd, all. (3) Page #8 20 Even, Page 35 # (4) Page #1 8 all #13 23 odd

Basics of Computational Geometry

Camera Calibration Using Line Correspondences

Vector Calculus: Understanding the Cross Product

euclidean geometry given a line and a point P which is not on, how many lines pass through P and are parallel to?

Park Forest Math Team. Meet #3. Self-study Packet


Homogeneous coordinates, lines, screws and twists

30. Constrained Optimization

Matrices. Chapter Matrix A Mathematical Definition Matrix Dimensions and Notation

Bridges Grade 5 Supplement Sets Correlations to Common Core State Standards

Angles, Polygons, Circles

Synthetic Geometry. 1.1 Foundations 1.2 The axioms of projective geometry

Module Four: Connecting Algebra and Geometry Through Coordinates

Graphs and Linear Functions

Math 6, Unit 8 Notes: Geometric Relationships

Common Core State Standards. August 2010

Rational Numbers: Graphing: The Coordinate Plane

Does Not Meet State Standard Meets State Standard

Identify parallel lines, skew lines and perpendicular lines.

Generalized barycentric coordinates

Number Mulitplication and Number and Place Value Addition and Subtraction Division

5 The Theory of the Simplex Method

Today. Rendering pipeline. Rendering pipeline. Object vs. Image order. Rendering engine Rendering engine (jtrt) Computergrafik. Rendering pipeline

Grade 5. Massachusetts Curriculum Framework for Mathematics 48

Year 6 Maths Long Term Plan

COMP 558 lecture 19 Nov. 17, 2010

Naming Angles. One complete rotation measures 360º. Half a rotation would then measure 180º. A quarter rotation would measure 90º.

Year 6.1- Number and Place Value 2 weeks- Autumn 1 Read, write, order and compare numbers up to and determine the value of each digit.

EUCLID S GEOMETRY. Raymond Hoobler. January 27, 2008

DRAFT: Mathematical Background for Three-Dimensional Computer Graphics. Jonathan R. Senning Gordon College

Shadows in Computer Graphics

Geometry (H) Worksheet: 1st Semester Review:True/False, Always/Sometimes/Never

Alaska Mathematics Standards Vocabulary Word List Grade 7

Graphics and Interaction Transformation geometry and homogeneous coordinates

B. Section 1.1. Chapter 1 Review Booklet A. Vocabulary Match the vocabulary term with its definition. 3. A pair of opposite rays on line p.

PROPERTIES OF TRIANGLES AND QUADRILATERALS (plus polygons in general)

COMP30019 Graphics and Interaction Transformation geometry and homogeneous coordinates

Unit Circle. Project Response Sheet

Chapter 18 out of 37 from Discrete Mathematics for Neophytes: Number Theory, Probability, Algorithms, and Other Stuff by J. M. Cargal.

Geometry Curriculum Guide Lunenburg County Public Schools June 2014

Oklahoma C 3 Mathematics Standards

Answer each of the following problems. Make sure to show your work. Points D, E, and F are collinear because they lie on the same line in the plane.

Mathematics; Gateshead Assessment Profile (MGAP) Year 6 Understanding and investigating within number

Grade K 8 Standards Grade 4

Pre AP Geometry. Mathematics Standards of Learning Curriculum Framework 2009: Pre AP Geometry

Presents. The Common Core State Standards Checklist Grades 3-5

Explorations of Rigid Motions and Congruence

The statement implies that any three intersection points of two distinct planes lie on a line.

arxiv: v1 [math.mg] 3 Mar 2014

Chapter 7 Coordinate Geometry

TOURNAMENT OF THE TOWNS, Glossary

Transcription:

Ray-Triangle and Ray-Quadrilateral Intersections in Homogeneous Coordinates Pat Hanrahan Geometry Computing Group Minnesota Supercomputer Center Minneapolis, MN 55415 hanrahan@princeton.edu Experience shows that operation with homogeneous coordinates produces, at least with beginners, something like physical discomfirt. Felix Klein Recent articles in Ray Tracing News have discussed solutions to the problem of intersecting a ray with a triangle using the triangle s barycentric coordinates. This article shows yet another way to think about the ray-triangle intersection problem. The idea is to think of the barycentric coordinates of the intersection point, not as the ratio of areas, but rather as the as ratios of the volume of tetrahedra. This technique can also be used to derive formulae for ray-quadrilateral intersection by using the fact that associated with every planar quadrilateral is a unique triangle. Finally, I would like to show the connection between these results and Plucker line coordinates. This insight leads to quite an efficient algorithm. Most people studying computer graphics learn about homogeneous coordinates and projective geometry because they allow perspective transformations to be expressed as linear transformations involving 4x4 matrices. When writing a ray tracer, however, most authors have duplicated Turner Whitted s original approach where eye rays are directly formed in world space, obviating the need for a explicit viewing transformation. As a result the geometric calculations are usually expressed using familiar vector algebra in a Euclidean coordinate system. However, homogeneous coordinates were not invented to just express projective transformations; they have the advantage that many geometric calculations have elegant solutions when expressed in term of these coordinates. In fact, FelixKleingoesontosayinthesamebookfromwhichtheopeningquoteistaken. For our general standpoint, the questions of ordinary vector analysis constitute only a chapter out of a profusion of more general problems [in geometry]. For those interested in more about homogeneous coordinates and their uses in geometry, I suggest the references at the end of the article and I particular a recent thesis by J. Stolfi. I also might recommend my paper entitled, The Homogeneous Geometry Calculator, which describes how these ideas can be used in geometric modeling and computer graphics. 1

Points, Planes, Lines and Determinants In three-dimensional projective geometry the homogeneous coordinates of points are 4- vectors x y P = z w The 3D location of a point is interpreted to be (x/w, y/w, z/w). Because of the division by w, the homogeneous coordinates of a point can be multiplied by a constant (other than 0) without effecting its location. If w is equal to 0, the point is interpreted to at infinity in the direction given by the first three coordinates. In projective geometry, points at infinity in opposite directions are considered the same. A line is uniquely determined by two points. All points on the line can be generated by forming linear combinations of two points (Figure 1). P = s 1 P1 + s 2 P2 One can interpret this equation by stating that P1 and P2 define a coordinate system on the line, and that the coordinates of an individual point are are (s 1,s 2 ). In particular, the coordinates of P1 are (1, 0) and the coordinates of P2 are (0, 1). Notice as s 1 increases positively that P moves towards P1 and as s 2 increases positively P moves towards P2. Furthermore, these coordinates have a nice geometric interpretation: s 1 is the ratio of the length of PP1 to the length of P1P2, ands 2 is the ratio of the length of PP2to the length of P1P2, These observations allow us to enumerate the set of points on the line segment P1P2. { (s 1,s 2 ):(s 1 > 0)and(s 2 > 0) } Often it is convenient to normalize the coordinates so that their sum is one. s 1 = s 1 s 1 + s 2 s 2 = s 2 s 1 + s 2 Coordinates normalized in this way are referred to as barycentric coordinates and were originally developed by Moebius. With this representation, if the two points P1 and P2 both have w = 1, then all linear combinations involving barycentric coordinates will also have w = 1. The advantage of this from a computational point of view is that this allows us to effectively ignore the extra coordinate. However, if we allow other values for w, it is not necessary to normalize the coordinates in this way, in the process saving the cost of performing the division and avoiding a nasty singularity if the denominator happens to be 0. A basic rule of thumb when using homogeneous coordinates is: Be suspicious of any formula requiring a division. Said another way: Delay all divisions until it is absolutely necessary to interpret a point as a 3D location. Unfortunately, there is a subtlety having to do with signs. As shown above, we defined the interval between P1 and P2 as being the region where s 1 and s 2 are both positive. 2

Now suppose s 1 and s 2 are both multiplied by 1. Then they are both negative, and the point formed as their linear combination 1 times the point they originally generated. But, by our convention that multiplying a point by a constant does not change its position, these two points represent the same location on the line. Note, however, in this case the point generated will w<0. It is tempting then to divide homogeneous points into two classes based on the sign of w, and to say that a point with negative w coordinate is inside other points with negative w coordinates (since it can then be formed by positive linear combinations of them). A thorough discussion of this approach is contained in J. Stolfi s thesis. For the purposes of this paper, we will always assume w>0. Without this assumption all the formulas involving signs, orientations and determinants are not valid. Inthesamewaythatanaxiomofprojectivegeometrystatesthatauniquelineis determined by two points, so another axiom states that a unique plane is determined by three points. All points on this plane can be generated by forming linear combinations of three points (Figure 2). P = u 1 P1 + u 2 P2 + u 3 P3 The coordinates of point in the plane coordinate system defined by the triangle P1P2P3 are (u 1,u 2,u 3 ). These coordinates have the geometric interpretation that u 1 is the ratio of the area of triangle PP2P3 to P1P2P3, andu 2 is the ratio of P1PP3 to P1P2P3, and u 3 is the ratio of P1P2P to P1P2P3. The set of points inside the triangle is { (u 1,u 2,u 3 ):(u 1 > 0)and(u 2 > 0)and(u 3 > 0) } Now suppose there is a fourth point P4 contained in the plane. Then P4 can be written as a linear combination of P1, P2, andp3. So there must be some set of values (u 1,u 2,u 3,u 4 ) which satisfy the following equation u 1 P1 + u 2 P2 + u 3 P3 + u 4 P4 =0 Let s write this out as a set of linear equations x 1 u 1 + x 2 u 2 + x 3 u 3 + x 4 u 4 =0 y 1 u 1 + y 2 u 2 + y 3 u 3 + y 4 u 4 =0 z 1 u 1 + z 2 u 2 + z 3 u 3 + z 4 u 4 =0 w 1 u 1 + w 2 u 2 + w 3 u 3 + w 4 u 4 =0 Recall from linear algebra that this set of homogeneous equations will have a solution iff the following determinant equals 0. x 1 x 2 x 3 x 4 y P1P2P3P4 = 1 y 2 y 3 y 4 =0 z 1 z 2 z 3 z 4 w 1 w 2 w 3 w 4 If we interpret P4 as an arbitrary point P =(x, y, z, w) in the plane, this equation is the plane equation. y 1 y 2 y 3 z 1 z 2 z 3 w 1 w 2 w 3 x x 1 x 2 x 3 z 1 z 2 z 3 w 1 w 2 w 3 y + x 1 x 2 x 3 y 1 y 2 y 3 w 1 w 2 w 3 z x 1 x 2 x 3 y 1 y 2 y 3 z 1 z 2 z 3 w =0 3

which can be derived by expanding the 4x4 determinant into subdeterminants. The four 3x3 subdeterminants form the homogeneous coordinates of the plane through the three points. We will symbolically express this equation as P1P2P3 P =0 Although we will not go into it in this article, all the results and theorems in projective geometry are symmetric with respect to points and planes. This means that any result involving points may be interpreted as a result involving planes just by replacing the word point with planes. This is called duality. This implies that all the calculations performed with homogeneous point coordinates have dual analogues using homogeneous plane coordinates. Suppose that P4 is not in the plane. Then the four points determine a coordinate system in space. All points in space can be written as linear combinations of these 4 points (Figure 3). P = u 1 P1 + u 2 P2 + u 3 P3 + u 4 P4 The barycentric coordinates in a tetrahedron can be interpreted as the ratio of volumes of tetrahedra. That is, u 1 is the ratio of the volume of the tetrahedra PP2P3P4 to P1P2P3P4, u 2 is the ratio of PP3P4P1 to P1P2P3P4, etc. The final geometric fact that we need is that the determinant of four points is proportional to the volume of the tetrahedron defined by the four points. x 1 x 2 x 3 x 4 y volume(p1p2p3p4) =1over6 1 y 2 y 3 y 4 z 1 z 2 z 3 z 4 w 1 w 2 w 3 w 4 (If the w coordinates of the four points are not 1 s, the volume is multiplied by the product of the four w coordinates.) The verification of this formula is left as an exercise. It s also useful to recall two other properties of determinants. First, the sign of a determinant changes if adjacent rows or columns are interchanged. P1P2P3P4 = P2P1P3P4 = P2P3P1P4 =...etc. Thus the volume of the tetrahedra is also signed. This can be interpreted geometrically by saying that the volume P1P2P3P4 is positive if it is right-handed. It is right-handed if when the fingers of your right hand are made to follow P2P3P4, yourthumbpoints towards P1. Second, if any point is duplicated in a determinant, the determinant is equal to 0; this is intuitively obvious given the interpretation of the determinant as a volume. 4

Ray-Triangle Intersection With the above preliminaries, we are now prepared to write down the ray-triangle intersection formulas. Define a ray by two points R1 and R2 R = s 1 R1 + s 2 R2, and the triangle by three points P1, P2, andp3 P = u 1 P1 + u 2 P2 + u 3 P3. This situation is illustrated in Figure 4. To solve for (s 1,s 2 ) observe that the point of intersection must lie on the line containing the ray R1R2 and on plane containing the triangle P1P2P3. These constraints are expressed by P1P2P3 R = s 1 P1P2P3R1 + s 2 P1P2P3R2 =0 By inspection, this equation has a solution at which can be verified as follows: s 1 = P1P2P3R2 s 2 = P3P2P1R1, P1P2P3R2 P1P2P3R1 + P3P2P1R1 P1P2P3R2 = P1P2P3R2 P1P2P3R1 P1P2P3R1 P1P2P3R2 =0. The geometric interpretation of this solution is that s 1 is equal to the volume of the tetrahedron P1P2P3R2, ands 2 is equal to the volume of the tetrahedron P3P2P1R1. This is illustrated in Figure 4A. Alternatively, to solve for (u 1,u 2,u 3 ) observe that the point of intersection must also lie in any plane containing the ray. In particular it must lie in the planes of the triangles R1R2P1, R1R2P2, andr1r2p3. R1R2P1 P = u 2 R1R2P1P2 + u 3 R1R2P1P3 =0 R1R2P2 P = u 1 R1R2P2P1 + u 3 R1R2P2P3 =0 R1R2P3 P = u 1 R1R2P3P1 + u 2 R1R2P3P2 =0 By inspection, these equations have solutions u 1 = R1R2P2P3 u 2 = R1R2P3P1 u 3 = R1R2P1P2 5

Verifyingthisforthefirstcaseyields: u 2 R1R2P1P2 + u 3 R1R2P1P3 = R1R2P3P1 R1R2P1P2 + R1R2P1P2 R1R2P1P3 = R1R2P3P1 R1R2P1P2 R1R2P1P2 R1R2P3P1 = 0 The other cases are just as easily verified. These solutions also have a very simple geometric interpretation. The coordinate u 1 is equal to the volume of the tetrahedron R1R2P2P3. In fact, all the coordinates are volume of tetrahedra formed by the two end points of the ray and the two points opposite the point associated with the coordinate. This is shown in Figure 4B. To actually test for an intersection with the triangle we need to determine whether the intersection is inside the triangle. This is easily done by testing whether all three coordinates are positive. In fact, it is best to test each coordinate as it is computed, since if it is negative, it is not necessary to compute the other coordinates. To test whether the intersection point is contained between the two endpoints of the rays, check that both s 1 and s 2 are positive. Ray-Quadrilateral Intersection To test whether a planar quadrilateral is intersected by a ray can be done using the above triangle intersection algorithm. This is possible because every planar quadrilateral defines a unique reference triangle. The coordinates of the vertices of the quadrilateral in this reference triangle are: (1,1,1), (-1,1,1), (1,-1,1) and (-1,-1,1). And, the equations of lines connecting the four sides are: u 1 + u 3 >=0 u 1 + u 3 >=0 u 2 + u 3 >=0 u 2 + u 3 >=0 So, a ray-quadrilateral intersection can be computed by first computing the coordinates of the ray intersection with the reference triangle as described in the last section. Then, these coordinates are tested to see whether they lie inside the unit square. Figure 5 shows the reference triangle associated with quadrilateral whose corners are A, B, C and D. These points naturally define six lines: two pairs of opposites, (AB, CD) and(ad, BC); and a diagonal pair, (AC, BD). These pairs intersect in three points which define a triangle: P1 = AB CD, P2 = AD BC, andp3 = AC BD. Note that if two lines in a line pair are parallel, they intersect at a point at infinity. The proof that in this coordinate system the quadrilateral is a unit square can be found in the references. [Texture mapping.] 6

Line Coordinates Finally let me mention a connection between these determinants and another representation of lines in homogeneous coordinates. To motivate this new representation, note that the ray-triangle calculation involves calculating determinants of the type P1P2R1R2. Normally when generating an image in a ray tracer, each triangle is tested against many rays and each ray against many triangles. Thus, it is worthwhile to preprocess triangles and rays since the preprocessing cost will be amortized over all the intersection tests. So this leads to the question: Is there some way to rearrange the above determinant into a set of terms involving only P1 and P2 and another set only involving R1 and R2? Ifthis is done, then these terms can be precalculated. An example of a similar rearrangement of determinants was the plane P1P2P3. This is an interpreted as four 3 subdeterminants which can be precomputed. To compute the 4x4 determinant P1P2P3R2, all that is required is a four element dot product of the plane P1P2P3 with the point R2. In the line representation by two points used above, the coordinates of points on the line depend on the choice of R1 and R2. Is there a line representation that does not change if R1 and R2 change? One such choice are the 2x2 determinants p x y = x 1 x 2 y 1 y 2 = x 1y 2 x 2 y 1 p x z = x 1 x 2 z 1 z 2 = x 1z 2 x 2 z 1 p x w = x 1 x 2 w 1 w 2 = x 1w 2 x 2 w 1 p y z = y 1 y 2 z 1 y 2 = y 1z 2 y 2 z 1 p y w = y 1 y 2 w 1 w 2 = y 1w 2 y 2 w 1 p z w = z 1 z 2 w 1 w 2 = z 1w 2 z 2 w 1 Since p i i = 0 and p i j = p j i, only these six of the sixteen possible 2x2 determinants are non-zero and unique. These six numbers are called the Plucker coordinates of a line. It can be shown that the determinant P1P2R1R2 can be written as P1P2R1R2 = p x yr z w + p x zr w y + p x wr y z + p z wr x y + p w yr x z + p y zr x w. where the p s are the coordinates of the line P1P2 and the r s are the coordinates of the line R1R2. (Note the change in sign by setting p w y = p y w and r w y = r y w.) Using these line coordinates, each determinant can be calculated using only 6 multiplies and 5 adds! 7