Homogeneous Coordinates and Computer Graphics

  • Upload
    gogy

  • View
    289

  • Download
    0

Embed Size (px)

Citation preview

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    1/14

    Homogeneous Coordinates andComputer Graphics

    Tom [email protected]

    http://www.geometer.org/mathcirclesNovember 20, 2001

    The relationship between Cartesian coordinates and Euclidean geometry is well known. The theoremsfrom Euclidean geometry dont mention anything about coordinates, but when you need to apply thosetheorems to a physical problem, you need to calculate lengths, angles, et cetera, or to do geometric proofsusing analytic geometry.

    Homogeneous coordinates and projective geometry bear exactly the same relationship. Homogeneous co-ordinates provide a method for doing calculations and proving theorems in projectivegeometry, especiallywhen it is used in practical applications.

    Although projective geometry is a perfectly good area of pure mathematics, it is also quite useful incertain real-world applications. The one with which the author is most familiar is in the area of computergraphics. Since it is almost always easier to understand mathematics when there are concrete examplesavailable, well use computer graphics in this document as a source for almost all the examples.

    The prerequisites for the material contained herein include matrix algebra (how to multiply, add, andinvert matrices, and how to multiply vectors by matrices to obtain other vectors), a bit of vector algebra,some trigonometry, and an understanding of Euclidean geometry.

    1 Computer Graphics ProblemsWell begin the study of homogeneous coordinates by describing a set of problems from three-dimensionalcomputer graphics that at rst seem to have unrelated solutions. We will then show that with certaintricks, all of them can be solved in the same way. Finally, we will show that this same way is in fact just a recasting of the original problems in terms of projective geometry.

    1.1 Overview

    Much of computer graphics concerns itself with the problem of displaying three-dimensional objectsrealistically on a two-dimensional screen. We would like to be able to rotate, translate, and scale ourobjects, to view them from arbitrary points of view, and nally, to be able to view them in perspective.

    We would like to be able to display our objects in coordinate systems that are convenient for us, and to beable to reuse object descriptions when necessary.

    As a canonical problem, lets imagine that we want to draw a scene of a highway with a bunch of carson it. To simplify the situation, well have all the cars look the same, but they are in different locations,moving at different speeds, et cetera.

    We have the coordinates to describe a tire, for example, in a convenient form where the axis of the tire isaligned with the -axis of our coordinate system, and the center of the tire is at

    . We would liketo use the same description to draw all the tires on a car simply by translating them to the four locationson the body. Our car body, of course, is also dened in a nice coordinate system centered at

    andaligned with the , , and -axes.

    Once we get the tires attached to the body, wed like to make multiple copies of the car in different

    orientations on the road. The cars may be pointing in different directions, may be moving uphill anddownhill, and the one that was involved in a crash may be lying upside-down.

    1

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    2/14

    Perhaps we want to viewthe entire scene from the point of view of a trafc helicopter that can be anywhereabove the highway in three-dimensional space and tilted at any angle.

    Well deal with the viewing in perspective later, but the rst three problems to solve are how to translate,rotate, and scale the coordinates used to describe the objects in the scene. Of course we want to be ableto perform combinations of those operations 1.

    We assume that every object is described in terms of three-dimensional cartesian coordinates like ,and we will not worry how the actual drawing takes place. (In other words, whether the coordinates arevertices of triangles, ends of lines, or control points for spline surfacesits all the same to uswe justtransform the coordinates and assume that the drawing will be dragged around with them.)

    Finally, except in the cases of rotation and perspective transformation, it is easier to visualize and ex-periment with two-dimensional drawings and the extension to three dimensions is obvious and straight-forward.

    1.2 Translation

    Translation is the simplest of the operations. If you have a set of points described in cartesian coordinates,and if you add the same amount to the -coordinate of every one, all will move by the same amount inthe -direction, effectively moving the drawing by that amount. Adding a positive amount moves to theright; a negative amount to the left.

    Similarly, additions of a constant value to the or -coordinate cause uniform translations in those direc-tions as well. The translations are independent and can be performed in any order, including all at once.If an object is moved one unit to the right and one unit up, thats the same as moving it one unit up andthen one to the right. The net result is a motion of length units to the upper-right.

    We can dene a general translation operator as follows:

    ! " ! # $ & %' (0 ) 1 2 (3 ) 4 5 (0 ) 6

    where ) 1 , ) 4 , and ) 6 are the translation distances in the directions of the three coordinate axes. They maybe positive, negative, or zero. ! " ! # is a function mapping points of three-dimensional space into itself.This ! " ! # has an inverse, 8 7$ 9

    ! " ! #

    %'

    7

    !

    7

    " !

    7

    # which simply translates in the opposite directionsalong each coordinate axis. Clearly:

    ! " ! #

    7

    !

    7

    " !

    7

    # $ & %

    A @3 ) 15 (0 ) 1 8 @B ) 45 (3 ) 4 C @B ) 6D (3 ) 6 E %' $ F

    1.3 Rotation about an Axis

    Well begin by considering a rotation in the - plane about the origin by an angle G in the counter-clockwise direction. Clearly, all of the -coordinates will remain the same after the rotation. We willdenote this rotation by HA 6 ! I . The subscript is because the rotation is, in fact, a rotation about the -axis.

    Figure 1 shows how to obtain the equation for the rotation. We begin with a point PQ %Q $ and wewish to nd the coordinates of PC RS %' R R which result from rotating P by an angle G counter-clockwiseabout the -axis. The equations are most easily obtained by using polar coordinates, where T8 %' U VE (3 Vis the distance from the origin to P (and to PC R ) , and W is the angle the line connecting the origin to Pmakes with the -axis.

    As we can see in the gure, X %Y T& ` a b W and %Y T& b c d5 W , while S R %Y T& ` a b W (0 G and RS %Y T& b c d$ W (0 G .1There is one other operation that can easily be performed called shearing, but it is not particularly useful. The general

    homogeneous transformations that well discover also handle all the shearing operations seamlessly.

    2

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    3/14

    P = (x, y) = (r cos , r sin )P = (x, y) = (r cos , r sin )

    P = (x, y) = (r cos ( + ), r sin ( + ))P = (x, y) = (r cos ( + ), r sin ( + ))

    Figure 1: Rotation about the e -axis

    Using the addition formulas for sine and cosine, we obtain:f g h i p h qs rt f u& v w x f y 3 q i u& x $ f y 0 q q

    rt f u& v w x y5 v w x 2 B u& x 5 y5 x D S i u& v w x y5 x D C 0 u x 5 yC v w x q

    rt f gC v w x 2 3 pD x E S i gC x D C 3 pD v w x q

    Thus we obtain: Af g$ i p i

    e

    q& r' f gC v w x 2 3 pE x D S i gC x D C 3 pD v w x i

    e

    q

    (1)

    As was the case with translation, rotation in the clockwise direction is the inverse of rotation in thecounter-clockwise direction and vice versa:

    X $

    r

    A

    . Its a good exercise to check this by applyingequation 1 and its inverse to a point

    f g i p q

    .

    The equations for rotation about theg

    andp

    axes can be obtained similarly, and for reference, here are all

    three equations together:A

    f g i p i

    e

    q rt f g$ i pD v w x 2

    e

    x E S i pD x D C

    e

    v w x q

    (2)A

    f g i p i

    e

    q rt f g5 v w x C

    e

    x D S i$ p i& D g5 x D C

    e

    v w x q

    (3)A

    f g i p i

    e

    q rt f g5 v w x 2 B pD x D i g5 x D C 0 pD v w x S i

    e

    q

    (4)

    At rst glance, it appears that we have made an error in the signs in equation 3 for the rotation aboutthe

    p

    -axis, since they are reversed from those for rotations about theg

    and e -axes. But all are correct.The apparent problem has to do with the fact that the standard three-dimensional coordinate system isright-handedif the

    g

    andp

    -axes are drawn as usual on a piece of paper, we must decide whether thepositive e -axis is above or below the paper. We have chosen to place positive e values above the paper.

    A left-handed system, where the positive e -axis goes down, is perfectly reasonable, but the usual conven-tion is the other way, and the difference is that the signs in some operations are switched around. Thenormal orientation is called a right-handed coordinate system and the other, left-handed. Even if wehad used a left-handed system, the signs would not be the same throughout the equations 2-4; a differentset of signs would be ipped.

    Think of the orientation of a rotation as follows: to visualize rotation about an axis, put your eye onthat axis in the positive direction and look toward the origin. Then a positive rotation corresponds to acounter-clockwise rotation. Weve done this with rotation about the e -axisyour eye is above the paperlooking down on a standard

    g

    -p

    coordinate system. But visualize the situation looking from the positivep

    and positive e directions in a right-handed coordinate system. Looking from theg

    direction, thep

    goesto the right and the e goes up, but looking from the positive

    p

    -axis, theg

    -axis goes to the left , while thee -axis goes up.

    3

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    4/14

    1.4 General Rotation

    What if you want to rotate about an axis that does not happen to be one of the three principal axes (the

    , , and axes are called the principal axes)? What if you want to rotate about a point other than theorigin? It turns out that both of these problems can be solved in terms of operations that we already knowhow to do. Lets begin by looking at rotation about non-principal axes that do pass through the origin.

    The strategy is this: we will do one or two rotations about the principal axes to get the axis we wantaligned with the -axis. Then well rotate about the -axis, and nally, well undo the rotations we didto align your axis with the -axis. To do this, assume that the axis of rotation you want points alongthe vector . Wed like to have it along another vector with its and -coordinates zero. If the

    -coordinate is non-zero, do a rotation about the -axis to make the -coordinate zero. If the -coordinateis still non-zero, do a rotation about the -axis to make the -coordinate zero. Since the rotation is aboutthe -axis, the -coordinate (which you previously rotated to be zero) will not be affected. Thus at mosttwo rotations will align an arbitrary axis with the -axis.

    So if the problem is to rotate about the origin by an angle , but with an arbitrary axis, what we need to

    do is perform two rotations to do the alignment. For concreteness, assume those rotations are by aboutthe -axis and then by about the -axis. If j j is any point in space, the new point 2 k thatresults from a rotation of about this oddball axis is:

    k

    Y lA m n o lA n o & lA m n lA n lA m n C (5)

    To interpret equation 5 remember that the operations are performed from the innermost parentheses out-ward. First, rotate about the -axis by an angle . Rotate the resulting point about the -axis by anangle . At this point, the oddball axis is aligned with the -axis, so the rotation you wanted to do origi-nally can now be done with the lA m n operator. Finally, the two outermost operations return the axis to itsoriginal orientation.

    Obviously, combining ve levels of calculations from equations 2-4 will result in a nightmarish system of

    equations, but something that is not difcult for a computer to deal with.Finally, what if the rotation is not about the origin? This time the translation operations from Section 1.2come to the rescue together with a similar strategy to what we used above for a non-standard axis. Wesimply need to translate the center of rotation to the origin, perform the rotation, and translate back. If wedenote by l any sort of rotation about any axis through the origin (possibly constructed as a compositionof ve standard rotations as illustrated in equation 5 above), and we wish to perform that rotation aboutthe point $ , here is the equation that relates an arbitrary point to its position C k after rotation:

    k

    Y m n n lB o m n o n o 2

    1.5 Scaling (Dilatation) and Reection

    What if we want to make things larger or smaller? For example, if we have the coordinates that describean automobile, what are the coordinates that would describe a scale model of an automobile that istimes smaller than the original?

    Its fairly clear that if we multiply all of our coordinates by we will get a model thats thesize, but notice that if the original coordinates had described a car a mile from the origin, the resultingminiature car would be only about mile from the origin. Thus our strategy does scale down the sizeof the car, but the scaling occurs about the origin. If we wanted to scale about the original car a mile fromthe origin, we could use the same trick we did with rotationstranslate the car to the origin, multiply allthe coordinates by , and nally translate the resulting coordinates back to the original position.

    Non-uniform scaling is also easy to doif we wish to make an object twice as large in the -direction,three times as large in the -direction, and to leave the size unchanged, we simply multiply all the

    -coordinates byz

    , all the -coordinates by{

    , and leave the -coordinates unchanged (or equivalently,multiply them all by ).

    4

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    5/14

    Thus, the most general scaling operation about the origin is given in terms of the scale factors | } , | ~ , and| , and the formula for such a function is:

    $ & '

    | }

    $

    | ~ |

    (6)

    In equation 6, if the scale values are larger than , the objects size increases; if they are less than , itdecreases, and if they are equal to one, the size is unchanged.

    Negative scale values correspond to a combination of a size change and a reection across the planeperpendicular to the axis in question passing through the origin. If | } , there is no size change, butthe object is reected through the plane

    X

    .

    The same ideas used previously can be used to produce scaling functions in directions not aligned withthe principal axes. If scaling is to occur about a non-principal axis, rotate that axis to be the -axis, scalein the -direction, and then rotate back.

    Weve considered positive and negative scalings, but what happens if, say, | }Q

    ? All -values arecollapsed to zero, and its as if the entire three-dimensional space is projected to the plane

    Y j

    . Weare going to need this operation (or something similar) when we draw our three-dimensional space on atwo-dimensional computer screen.

    As long as all three values | } , | ~ , and | are non-zero, the scale function has an inverse. It should beobvious that

    D $ j

    , and the inverse only makes sense if all three scale values arenon-zero. From a physical point of view its easy to see why. If the scaling operation is really a projectionto a plane, there is no way to undo it. Any point on the plane could have come from any of the points onthe line through space that projected to that point.

    2 Combining Rotation, Translation, and Scaling

    As we have seen above, it is often advantageous to combine the various transformations to form a morecomplex transformation that does exactly what we want. If we simply do the algebra, things can getcomplicated in a hurry. To illustrate the problem, consider a relatively simple problemwed like torotate clockwise by an angle about an axis parallel to the -axis but passing through the point .

    The combined transformation of the point to is this:

    } ~ } } ~

    $

    t A B Y 8 B

    C

    A B

    C

    8 3

    C

    and this one is pretty straight-forward. Imagine what the combination of rotations would look like.

    But there is an easy method, and well begin by looking at how to combine rotations. It turns out that all

    of the rotations about the origin can be easily expressed in terms of matrix multiplication. If we considerour points' $

    to be three-dimensional column vectors 2, every rotation corresponds exactly to amultiplication by a certain matrix. Here is the matrix that corresponds to a counter-clockwise rotation byan angle about the axis:

    B

    C 3 D

    C

    C

    D

    The other two matrices are equally simple:2For technical reasons, it is better to represent the vectors as column vectors. We could use row vectors, but there are disadvan-

    tages that are difcult to explain at this point. However, to save space in the text, we will write the components as usual: within paragraphs with the understanding that when they are expressed as vectors in equations, they will be turned vertical to make

    column vectors. When we talk about projective lines later on, well need to use actual row vectors, and to indicate this within aparagraph, well use the somewhat surprising .

    5

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    6/14

    A A Q D

    E

    Q C C

    D

    C D C

    andA

    D

    D

    D

    D C

    The beautiful thing about the matrix representation is that repeated rotations about different axes corre-sponds to matrix multiplication. Thus if you need to rotate a million vertices that describe the skin of adinosaur in Jurassic Park VI about some weird axis, you dont need to multiply each point by ve differentmatrices; you simply multiply the ve matrices together once and multiply each dinosaur point by thatone matrix. Its a savings of almost four million matrix multiplications which can take time, even on afast computer.

    The scaling matrix is even simpler:

    $

    $ Q $

    Q $

    It can be combined in any combination with the rotation matrices above to make still more complextransformations. As with the rotation matrices alone, the combination of operations simply correspondsto matrix multiplication.

    Unfortunately, when we try to do the same thing with the seemingly simpler translation operation, we aredead. It just will not and cannot work this way. Its easy to see why. If you multiply the column vector

    by any D 2 matrix, the result will be

    . The origin is xed by every matrix multiplication,yet for a translation, we require that the origin move.

    Fortunately, there is a trick 3 to get the job done. We will simply add an articial fourth component to eachvector and we will always set it to be

    . In other words, the point we used to refer to as

    , we willnow refer to as

    . If you need to nd the actual three-dimensional coordinates, simply look atthe rst three components and ignore the

    in the fourth position 4 .

    Of course none of the matrices above will work either, until we add a fourth row and fourth column withall the elements equal to zero except for the bottom corner. For example:

    D

    E

    C

    D

    C D C

    But now, with this articial fourth coordinate, it is possible to represent an arbitrary translation as a matrixmultiplication:

    0

    3

    0

    Using this scheme, every rotation, translation, and scaling operation can be represented by a matrix mul-tiplication, and any combination of the operations above corresponds to the products of the correspondingmatrices.

    3Computer scientists, of course, refer to a trick as a hack.4 But if it is not , beware. Well handle this case later, when we run into the problem head-on. For now, things are nice.

    6

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    7/14

    3 A Simple Perspective Transformation

    We know that by setting one of the scale factors to zero, we can collapse all of the -coordinates, say, to8 Y . If we think of our computer screen as having and -coordinates in the usual way, we want to dosomething like this to nd the screen coordinates for our points.

    But setting the scale factor to zero simply projects each point in space to the - plane in a perpendiculardirection. To model the real world, wed like to imagine looking at real three-dimensional objects, andprojecting them, wherever they are, to a rectangular piece of glass (the computer screen) that is a fewinches in front of our eye. These rays are not projected perpendicular to the screen; they are all projectedat the eye, and they should be drawn on the screen wherever the ray from the object to the eye hits thescreen.

    OO 11

    P = (x, y, z)P = (x, y, z)

    P = (x/z, y/z, 1)P = (x/z, y/z, 1)

    Figure 2: A Simple Perspective Projection

    For deniteness, imagine that you are looking from the origin in the direction of the negative -axis.Remember that if you look from the positive -axis toward the negative, the - plane looks normal toyou, with the positive -axis to the right and the positive -axis pointing up. Imagine that we would like

    to project all the points in front of you (they will be the points with negative -coordinates) onto the planeone unit in front of you (it will have -coordinate equal to C ). Most computer graphics folks dont likeworking with these negative coordinates, so they now switch to a left-handed coordinate system so thatthe point X is in front of them, looking into the plane. Well do that here, just so we dont need tomess with 2 as the -coordinate of projection.

    Figure 2 shows how we would like to project an arbitrary point $ to a point C on the plane.Similar triangles will show you that the coordinates of C are $ S .

    This is bad newsweve got to do a division by the -coordinate, and the only operations we can performwith matrix multiplications are multiplications and additions. How can we combine this perspectivetransform with the rotations, translations, and scales that work so well with a uniform type of matrixrepresentation?

    But with one more trick (one more hack, if youre a computer scientist), we can perform the divisionas well. It seems a shame that we have to drag around that nal fourth coordinate when its always goingto be equal to , but without it the matrix multiplications dont make sense. Here is the big trick: We willconsider two sets of coordinates to represent the same point if one is a non-zero multiple of the other. Inother words, the point 5 represents the same point as does $ $ $ S $ 5 .

    Normally, of course, , but this shows how we can convert to our standard form if we get a pointwhose fourth coordinate does not happen to be 1. As long as it is non-zero, we just let 0 ' , and wend that the points 5 and $ 2 S 2 8 are equivalent.

    This may seem weird at rst, but you should not feel at all uncomfortable with it. After all, you do it allthe time with fractions. Everybody knows that the fraction is normally written that way, but certaincalculations give results like , , or even . All are equivalent to .

    When we represent our three-dimensional points with four coordinates, its sort of like having a funnysort of fraction where the three numerators share a common denominator. And exactly as is the case with

    7

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    8/14

    fractions, as long as the denominator (the fourth term) is not equal to zero, well have no trouble.

    Here is the matrix that performs the perspective calculation shown in Figure 2 that takes the three-dimensional point to :

    ! !

    " # !

    $ % #

    $ % #

    & '

    '

    (

    & '

    '

    (0 )

    & '

    '

    (2 1

    The resulting vector after the multiplication is , but remember that we can multiply all thecomponents by the same non-zero number and get an equivalent point, and since were looking at valuesof in the half-space with negative -coordinates, we can multiply all of the coordinates by to obtainthe equivalent representation: .

    There is one problem with this matrix: it is singular, meaning that it does not have an inverse. The reasonis that our calculation effectively projected every point on the line connecting 3 and 35 4 to the same point

    on the plane ) . Any function or transformation that maps two points to the same point cannot beundone, or inverted.

    At rst, this seems like a purely aesthetic problem. After all, arent we planning to map all the pointsalong that line to the same point on the computer screen? The problem is that in computer graphics, youoften want to nd where to draw them on the screen but to avoid drawing them until youve found allthe points to be drawn there, and then to draw only the point thats nearest the eye of the viewer. Thatsbecause in the real world, objects nearer your eye block your vision of objects behind them.

    We can solve the problem easily, and at the same time, create a non-singular (invertable) matrix. We dontreally care that the coordinate is after transformationall we care about are the and coordinatesthat tell us where to paint the point on the screen. Heres a better perspective matrix:

    # ! $

    % # $

    ! % $

    ! %

    & '

    '

    (

    & '

    '

    (6 )

    8 79

    & '

    '

    (2 1

    (7)

    This transforms our point to 7@ (at least after we multiply all the coordinatesby ). The nal and coordinates are the same as beforeeverything on that line from 3 to 35 4 goesto points with the same and coordinatesbut the values are all different. The order of the points isinverted, but at least its easy to see from the transformed coordinates which ones were closer to the eye 5.

    The matrix in 7 is non-singular; its inverse is:

    # ! $

    % # $

    ! % $

    ! %

    & '

    '

    (

    A B

    )

    # ! C

    % # C

    ! ! D

    ! % $ E5

    & '

    '

    (

    Note that since we are dealing with transformations of three-dimensional space, all the transformationmatrices are FH GI F . If we were working only with points on the plane (two-dimensional space), thetransformation matrices would have been PQ GR P . For a line, they would have been SQ GR S , et cetera.

    5 In standard computer graphics packages, a more sophisticated version of the perspective matrix is generally used to control thevarious aspect ratios and to control the range of T values that emerge after the calculation. If youre interested, look at a book oncomputer graphics for the exact forms, but the basic idea is identical to that illustrated in transformation 7.

    8

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    9/14

    4 Homogeneous Coordinates

    Homogeneous coordinates provide a method to perform certain standard operations on points in Euclidean

    space by means of matrix multiplications. As we shall see, they provide a great deal more, but lets rstreview what we know up to this point.

    The usual cartesian coordinates for a point consist of a list of U points, where U is the dimension of thespace. The homogeneous coordinates corresponding to the same point require UW VY X coordinates.

    Normally, we add a coordinate to the end of the list, and make it equal to X . Thus the two-dimensionalpoint ` a b c d becomes ` a b c b X d in homogeneous coordinates, and the three-dimensional point ` ae b c b f d be-comes ` ae b c b f b X d . To learn more, it is often useful to look at the one-dimensional space (points on a line),and it is also useful to remember that the same method can be applied to higher-dimensional Euclideanspaces. Homogeneous coordinates in a seven-dimensional Euclidean space have eight coordinates.

    The nal coordinate need not be X . Since the most common use of homogeneous coordinates is for one,two, and three-dimensional Euclidean spaces, the nal coordinate is often called g since that will not

    interfere with the usuala

    ,c

    , andf

    -coordinates. In fact, two points are equivalent if one is a non-zeroconstant multiple of the other. Points corresponding to standard Euclidean points all have non-zero valuesin the nal ( g ) coordinate.

    5 Projective Geometry

    Whats really going on is, in a sense, far simpler. Homogeneous coordinates are not Euclidean coordi-nates; they are the natural coordinates of a different type of geometry called projective geometry.

    Here is the real denition of homogeneous coordinates in projective geometry, where we will considerthe two-dimensional version (with three coordinates) for concreteness.

    Every vector of three real numbers, ` ae b c b g8 d , where at least one of the numbers is non-zero, correspondsto a point in two-dimensional projective geometry. The coordinates for a point are not unique; if h is anynon-zero real number, then the coordinates ` ae b c b g8 d and ` h ae b h c b h g8 d correspond to exactly the samepoint.

    If the g -coordinate is non-zero, it will correspond to a Euclidean point, but if gp ir q (and at least one of a or c is non-zero), it will correspond to a point at innity (see Section 7).

    Furthermore, the allowable transformations in (two-dimensional) projective geometry correspond to mul-tiplication by arbitrary non-singular s5 t@ s matrices. Obviously, if two matrices are related by the fact thatone is a constant non-zero multiple of the other, they represent the same transformation.

    The coordinates are called homogeneous since they look the same all over the space, and with thecomplete exibility of multiplication by an arbitrary non-singular matrix we can convert any line to bethe line at innity, or convert points at innity to points in normal space, et cetera. In fact, if you ever

    took a perspective drawing class, the vanishing points on the horizon are really places, where, under aperspective transformation, points at innity wind up in normal space.

    There is more to projective geometry, of course. There are equations for lines, for conic sections, methodsto nd intersections of lines or for nding the lines that pass thorough a pair of points, et cetera, but wewill get to those later. Let us begin by describing a nice mental model for two-dimensional projectivegeometry.

    6 Euclidean and Projective Geometry

    Projective geometry is not the same as Euclidean geometry, but it is closely related. The two have manythings in common. Just as we can discuss Euclidean geometry in any nite number of dimensions, wecan do the same for projective geometry. Of course real-world applications are typically two and three-

    9

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    10/14

    dimensional in both geometries, but well sometimes nd it useful to think about the one-dimensionalversion of both.

    A nice way to think about various types of geometry is in terms of the allowable operations and theproperties that are preserved under those operations. For example, in Euclidean geometry, we can movegures around on the plane, rotate them, or ip them over, and if we do these things, the resulting trans-formed gures remain congruent to the originals. Two gures are congruent if all the measurements arethe samelengths of sides, angles, et cetera.

    In projective geometry, we are going to allow projection as the fundamental operation. Its easy to seewhat projection means in one and two dimensions, so well begin with those.

    Suppose you have a gure drawn on a plane. You can project it to another plane as follows: pick somepoint of projection that is on neither of the planes. Draw straight lines through every point of the originalgure that pass through the point of projection. The image of each point is the intersection of that linewith the other plane.

    Note also that we can obtain projections perpendicular to the plane of projection simply by projecting

    from a point at innitysee Section 7.Notice that we have said nothing about the orientations of the two planesthey need not be parallel, forexample. In your minds eye, try to imagine some of these two-dimensional projections.

    7 Visualizing Projective Geometry

    Here are two postulates from two-dimensional Euclidean geometry:

    u Every two points lie on a line.

    u Every two lines lie on a point, unless the lines are parallel, in which case, they dont.

    In two-dimensional projective geometry, these postulates are replaced by:

    u Every two points lie on a line.

    u Every two lines lie on a point.

    Thats basically the whole difference. How can we visualize a model for such a thing? The model mustdescribe all the points, all the lines, what points are on what lines, and so on.

    The easiest way is to take the points and lines from a standard two-dimensional Euclidean plane and addstuff until the projective postulates are satised. The rst problem is that the parallel lines dont meet.Lines that are almost parallel meet way out in the direction of the lines, so for parallel lines, add a single

    point for each possible direction and add it to all the parallel lines going that way. You can think of thesepoints as being points at innityat the ends of the lines. Note that each line includes a single point atinnitythe north-south line doesnt have both a north and south point at innity. If you go to innityto the north and keep going, you will nd yourself looping around from the south. Lines in projectivegeometry form loops.

    Now take all the new points at innity and add a single line at innity going through all of them. It, too,forms a loop that can be imagined to wrap around the whole original Euclidean plane. These points andlines make up the projective plane.

    You might make a mental picture as follows. For some small conguration of points and lines that youare considering, imagine a really large circle centered around them, so large that the part of the gure of interest is like a dot in its center. Now any parallel lines that go through that dot will hit the large circlevery close together, at a point that depends only on their direction. Just imagine that all parallel lines hit

    the circle at that point. This large circular line surrounding everything is the line at innity.

    10

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    11/14

    Check the postulates. Two points in the Euclidean plane still determine a single projective line. One pointin the plane and a point at innity determine the projective line through the point and going in the givendirection. Finally, the line at innity passes through any two points at innity.

    How about lines? Two non-parallel lines in the Euclidean plane still meet in a point (the standard Eu-clidean point), and dont meet anywhere else. Parallel lines have the same direction, so meet at the pointat innity in that direction. Every line on the original plane meets the line at innity at the point at innitycorresponding to the lines direction.

    Note: The projective postulates do not distinguish between points and lines in the sense that if you sawthem written in a foreign language:

    v Every two glorphs lie on a smynx,

    v Every two smynxes lie on a glorph,

    there is no way to gure out whether a smynx is a line and a glorph is a point or vice-versa. If you take any

    theorem in two-dimensional projective geometry and replace point with line and line with point,it makes a new theorem that is also true. This is called dualitysee any text on projective geometry.

    8 Back to the Homogeneous Coordinates

    So weve got a nice mental picturehow do we assign coordinates and calculate with them? The answeris that every triple of real numbers w x y y 5 except w y y corresponds to a projective point. If is non-zero, w x y y 5 corresponds to the Euclidean point w x Q y 5 in the original Euclidean plane; w xe y ycorresponds to the point at innity corresponding to the direction of the line passing through w y and

    w x y . Generally, if is any non-zero number, the homogeneous coordinates w xe y y 8 and w x y y 5represent the same point.

    Since projective points and lines are in some sense indistinguishable, it had better be possible to giveline coordinates as sets of three numbers (with at least one non-zero). If the points are column vectors,the lines will be row vectors 6 (written with a exponent that represents transpose), so w y yrepresents a line. The point 6 w xe y y 8 lies on the line r 6 w y y if x Y Q Y . In theEuclidean plane, the point w x y can be written in projective coordinates as w xe y y , so the conditionbecomes xW Y @ Y Q high-school algebras equation for a line. The line passing through all thepoints at innity has coordinates w y y . As with points, for any non-zero , the line coordinates

    w y y and w e y e y e represent the same line. Also, as with points, at least one of , , or mustbe non-zero to have a set of valid line coordinates.

    In matrix notation, the point lies on the line if and only if r 9 . This is like the dot product of thevectors. Since is a row vector and is a column vector of the same length, the product is essentially a

    5 H matrix, or basically, a scalar. If p p w x y y 5 and p w y y , then r 9 x@ I I . If we

    had chosen to represent lines as column vectors and points as row vectors, that would work ne, too. Ithas to work because points and lines are dual concepts.

    9 Projective Transformations

    Projective transformations transform (projective) points to points and (projective) lines to lines such thatincidence is preserved. In other words, if is a projective transformation and points and lie on line

    then @ w 5 and @ w lie on @ w . (Warning: @ w the transformation of a linedoes not simplyuse the same matrix as for transforming points. See later in this section.) Similarly, if lines and j meetat point , then the lines @ w and @ w jp meet at the point @ w .

    6Remember that we are writing column vectors in the text as rows, so were going to have to have a special notation to indicatethat a vector in the text is really a row vector. Thats what the transpose will be used for.

    11

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    12/14

    The reason projective transformations are so interesting is that if we use the model of the projectiveplane described in Section 7 where weve simply added some stuff to the Euclidean plane, the projectivetransformations restricted to the Euclidean plane include all rotations, translations, non-zero scales, and

    shearing operations. This would be powerful enough, but if we dont restrict the transformations to theEuclidean plane, the projective transformations also include the standard projections, including the veryimportant perspective projection.

    Rotation, translation, scaling, shearing (and all combinations of them) map the line at innity to itself,although the points on that line may be mapped to other points at innity. For example, a rotation of kdegrees maps each point at innity corresponding to a direction to the point corresponding to the directionrotated k degrees. Pure translations preserve the directions, so a translation maps each point at innity toitself.

    The standard perspective transformation (with a l m n eld of view, the eye at the origin, and looking downthe o -axis) maps the origin to the point at innity in the o -direction. The viewing trapezoid maps to asquare.

    Every non-singular e matrix (non-singular means that the matrix has an inverse) represents a projectivetransformation, and every projective transformation is represented by a non-singular @ R matrix. If is such a transformation matrix and is a projective point, then 0 is the transformed point. If is aline, represents the transformed line. Its easy to see why this works: if lies on , 2 r m , so

    0 p m , so z { z 0 {8 p m . The matrix representation is not uniqueas with points andlines, any constant multiple of a matrix represents the same projective transformation.

    Combinations of transformations are represented by products of matrices; a rotation represented by matrix|

    followed by a translation (matrix } ) is represented by the matrix }|

    .

    A (two-dimensional) projective transformation is completely determined if you know the images of ~independent points (or of ~ independent lines). This is easy to see. A W I matrix has nine numbersin it, but since any constant multiple represents the same transformation, there are basically degrees of freedom. Each point transformation that you lock down eliminates degrees of freedom, so the images

    of ~

    points completely determine the transformation.Lets look at a simple example of how this can be used by deriving from scratch the rotation matrix for a~ k n counter-clockwise rotation about the origin. The origin maps to itself, the points at innity along the

    and o axes map to points at innity rotated ~ k n , and the point z { maps to z m { .

    If |

    is the unknown matrix:

    |

    m

    m

    m

    m

    |

    m

    m

    m

    |

    m

    m

    m

    |

    m

    The can be any constants since any multiple of a projective points coordinates represents thesame projective point. The matrix

    |

    has basically unknowns, so those plus the ~5 s make . Eachmatrix equation represents equations, so we have a system of equations and unknowns that canbe solved. The computations may be ugly, but its a straight-forward brute-force solution that gives therotation matrix

    |

    as any multiple of:

    |

    ! m

    m

    m m

    Theres nothing special about rotation. Every projective transformation matrix can be determined in thesame brute-force manner starting from the images of 4 independent points.

    12

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    13/14

    10 Three-Dimensional Projective Space

    Three-dimensional projective space has a similar model. Take three-dimensional Euclidean space, add

    points at innity in every three-dimensional direction, and add a plane at innity going through the points.In this case there will also be an innite number of lines at innity as well. In three dimensions, pointsand planes are dual objects.

    Projective transformations in three dimensions are exactly analogous. Points are represented by -tuplecolumn vectors: e 8 , and planes by row vectors: . Any multiple of a points coordi-nates represents the same projective point. A point lies on a plane if p r 9 . All three dimensionalprojective transformations are represented by @ non-singular matrices.

    In three dimensions, the images of independent points (or planes) completely determine a projectivetransformation. (A R matrix has numbers, but degrees of freedom because any multiple rep-resents the same transformation. Each point transformation that you nail down eliminates degrees of freedom, so the images of independent points completely determine the transformation.) 7

    The brute-force solution has

    equations and

    unknowns (there will beQ

    s in addition to theunknowns), and although the solution is time-consuming, it is straight-forward.

    The calculation can be simplied. Suppose you want a transformation that takes to Q , ..., and to . Let

    !

    Find the transformation that takes e to

    and the transformation that takes to

    . Because of allthe zeroes, these are much easier to work out. The transformation you want is 5

    .

    10.1 Construction of an Arbitrary Transformation

    Based upon the idea above, here is a purely mechanical method to construct a transformation from anyfour independent points to any other four points in two-dimensional projective geometry. The method canobviously be extended to any number of dimensions, where the images of R Y points are required todetermine the transformation.

    Suppose we seek a matrix that performs the following map:

    % 5 I

    %

    %

    %

    We will construct the matrix as the product @ where:7The concept generalizes to -dimensional space. Transformations are denoted by Q 8 Q matrices having Q

    entries, but an arbitrary constant multiple reduces this to 5 e R W Q H 8 W degrees of freedom. Each timeyou nail down the image of an -dimensional point, you remove degrees of freedom, so the images of @ independent pointsare required to completely determine a projective transformation in projective -space.

    13

  • 8/3/2019 Homogeneous Coordinates and Computer Graphics

    14/14

    5

    8

    8

    and

    W I

    @ H

    @ H

    Q R

    The construction of

    and

    is obviously identical, so we will show the construction of

    only.

    We will denote the unknown entries in the matrix

    by . As usual, we will also use as the arbitraryconstants in that multiply the homogeneous coordinates of our result. The matrix

    must satisfy:

    # ! "

    % # "

    ! % $

    0

    5

    2

    (8)

    There are thirteen variables including the nine and the four , of which we can x any one. We chooseto let

    . We can actually perform the matrix multiplication on the left of equation 8 and set

    to obtain:

    0

    8

    #

    2

    (9)

    From equation 9, we can immediately conclude that

    ,

    , and that

    . Wedont yet know the values of except that

    , but we can now rewrite equation 9 as:

    e

    8

    8

    8

    "

    5

    8

    8

    (10)

    The rst three columns of equation 10 dont help at all, but we can re-write the fourth column as follows:

    % "

    5 8 8

    (11)

    We can solve equation 11 for the :

    % "

    5 8 8

    H

    (12)

    Using the values of the obtained from equation 12 and substituting those into the rst three columns of equation 9 we can nd the unknown matrix

    :

    8

    14