Background MathematicsMathematical Foundations3D GeometryVector SpacesVectors And PointsAffine spaces vs. Vector spacesAffine SpacesSlide 8Affine Lines: An AsideDot ProductCross ProductLinear TransformationsMatricesSlide 14Matrix Transformations3D Scene Representation3D Point3D Vector3D Line Segment3D Ray3D Line3D Plane3D Polygon3D SphereBackground MathematicsAaron BloomfieldCS 445: Introduction to GraphicsFall 20062Mathematical FoundationsA very brief review of some mathematical tools we’ll employGeometry (2D, 3D)TrigonometryVector and affine spaces Points, vectors, and coordinatesDot and cross productsLinear transforms and matrices33D GeometryTo model, animate, and render 3D scenes, we must specify:LocationDisplacement from arbitrary locationsOrientationWe’ll look at two types of spaces:Vector spacesAffine spacesWe will often be sloppy about the distinction4Vector SpacesGiven a basis for a vector space:Each vector in the space is a unique linear combination of the basis vectorsThe coordinates of a vector are the scalars from this linear combinationBest-known example: Cartesian coordinatesNote that a given vector will have different coordinates for different bases5Vectors And PointsWe commonly use vectors to represent:Direction (i.e., orientation)Points in space (i.e., location)Displacements from point to pointBut we want points and directions to behave differentlyEx: To translate something means to move it without changing its orientationTranslation of a point = different pointTranslation of a direction = same direction6Affine spaces vs. Vector spacesVector spacesAll vectors originate at the originThus, can be denoted with (x,y,z) coordinatesThe head of the vectorThe origin is absoluteAffine spacesVectors can start at an arbitrary pointThus, can be denoted via (x,y,z) and starting point PThe origin is relative to the current “context”Only when the distinction matters will we specify7Affine SpacesTo be more rigorous, we need an explicit notion of position Affine spaces add a third element to vector spaces: points (P, Q, R, …)Points support these operationsPoint-point subtraction: Q - P = vResult is a vector pointing from P to QVector-point addition: P + v = QResult is a new pointP + 0 = PNote that the addition of two points is not definedPQv8Affine SpacesPoints, like vectors, can be expressed in coordinatesThe definition uses an affine combinationNet effect is same: expressing a point in terms of a basisThus the common practice of representing points as vectors with coordinates Be careful to avoid nonsensical operationsPoint + pointScalar * point9Affine Lines: An AsideParametric representation of a line with a direction vector d and a point P1 on the line:P() = Porigin + dRestricting 0 produces a raySetting d to P - Q and restricting 0 1 produces a line segment between P and Q10Dot ProductThe dot product or, more generally, inner product of two vectors is a scalar:v1 • v2 = x1x2 + y1y2 + z1z2 (in 3D)Useful for many purposesComputing the length of a vectorlength(v) = |v| = sqrt(v • v)Normalizing a vector, making it unit-lengthDivide each coordinate by the lengthComputing the angle between two vectors:u • v = |u| |v| cos(θ)Checking two vectors for orthogonalityDoes the angle equal 90º?Projecting one vector onto anotherθuv11Cross ProductThe cross product or vector product of two vectors is a vector:Cross product of two vectors is orthogonal to bothRight-hand rule dictates direction of cross productCross product is handy for finding surface orientationLightingVisibility12211221122121)(y x y xz x z xz y z yvv12Linear TransformationsA linear transformation: Maps one vector to anotherPreserves linear combinationsThus behavior of linear transformation is completely determined by what it does to a basisTurns out any and all linear transformations can be represented by a matrix13MatricesBy convention, matrix element Mrc is located at row r and column c:This is called row-major orderBy (OpenGL) convention, vectors are columns:And 2-D matrices are in column-major order!mnm2m12n22211n1211MMMMMMMMMM32vvvv114MatricesMatrix-vector multiplication applies a linear transformation to a vector:Recall how to do matrix multiplication-zyxvvvMMMMMMMMMvM33323123222113121115Matrix TransformationsA sequence or composition of linear trans-formations corresponds to the product of the corresponding matricesNote: the matrices to the right affect vector firstNote: order of matrices matters!The identity matrix I has no effect in multiplicationSome (not all) matrices have an inverse: vvMM 1163D Scene RepresentationScene is usually approximated by 3D primitivesPointLine segmentPolygonPolyhedronCurved surfaceSolid object etc.173D PointSpecifies a locationRepresented by three coordinatesInfinitely smalltypedef struct {Coordinate x;Coordinate y;Coordinate z;} Point;typedef struct {Coordinate x;Coordinate y;Coordinate z;} Point;(x,y,z)Origin183D VectorSpecifies a direction and a magnitudeRepresented by three coordinatesMagnitude ||V|| = sqrt(dx dx + dy dy + dz dz)Which is the square root of the dot productHas no location (in affine spaces!)Dot product of two 3D vectorsV1·V2 = dx1dx2 + dy1dy2 + dz1dz2V1·V2 = ||V1 || || V2 || cos()typedef struct {Coordinate dx;Coordinate dy;Coordinate dz;} Vector;typedef struct {Coordinate dx;Coordinate dy;Coordinate dz;} Vector;(dx,dy,dz)(dx2,dy2 ,dz2)193D Line SegmentUse a linear combination of two pointsParametric representation:P = P1 + t (P2 - P1), (0 t 1)typedef struct {Point P1;Point P2;} Segment;typedef struct {Point P1;Point P2;} Segment;P1P2Origin203D RayLine segment with one endpoint at infinityParametric representation: P = P1 + t V, (0 <= t < )typedef struct {Point P1;Vector V;} Ray;typedef struct {Point P1;Vector V;}
View Full Document