3D Geometry

twu.seanho.com

3D Geometry

3D Geometry17 February 2009CMPT370Dr. Sean HoTrinity Western University


OpenGL state machine Two kinds of OpenGL functions● Generate primitives Vertex, line, triangle, polygon, etc.● Change state Current colour Material properties (shininess, etc.) Transformations: view, model Each primitive gets whatever state was currentwhen it was drawnCMPT370: geometry 17 Feb 20092


OpenGL functions Most core OpenGL functions look like this:● glVertex3f( x, y, z ) gl: belongs to core OpenGL library (glu for GLU) Vertex: name of function 3f: argument type: 3 floats Not overloaded, for efficiency● glVertex3fv( vec ) takes a pointer to an array of 3 floats● glVertex3i( x, y, z ): ints● glVertex3d( x, y, z ): doublesCMPT370: geometry 17 Feb 20093


OpenGL primitives glBegin(GL_*) starts a set of primitives Polygons must be simple: edges cannot cross Must be convex Must be flat: all vertices in the same planeCMPT370: geometry 17 Feb 20094


Projection matrix The coordinates of glVertex are in world coords● OpenGL converts to camera coords, then toscreen coords The projection matrix specifies the camera: glMatrixMode( GL_PROJECTION ); Specify the viewing volume: glLoadIdentity(); glOrtho(left, right, bottom, top, near, far)● Orthographic (parallel) projectionCMPT370: geometry 17 Feb 20096


Coordinate-free geometry Cartesian geometry:● Points are locations in space (x,y,z)● Tied to a particular coordinate system Euclidean (coordinate-free) geometry:● Points exist regardless of the coordinatesystem● e.g.: two triangles are identical if all threelegs are same length Regardless of where in space the triangle isCMPT370: geometry 17 Feb 20097


Scalars, vectors, and points Three basic elements in geometry● Scalars (α) Addition, multiplication Associativity, commutativity, etc. (field) No geometric properties E.g., reals, complex numbers● Vectors (v)● Points (P)CMPT370: geometry 17 Feb 20098


Vectors Vectors have two attributes:● Direction● Magnitude No position Physically-inspired definition● e.g., force, velocity, directed line segmentsvvCMPT370: geometry 17 Feb 20099


Vector spaces Every vector v has an inverse -vv-v There is a zero vector (zero magnitude) Adding two vectors gives another vector u+v =wuu+vv Vectors can be multiplied by scalars αv = wvαvCMPT370: geometry 17 Feb 200910


Points Location in space (no direction) Relationships between vectors and points:● Subtracting two points gives vector: P – Q = v● Adding a vector to a point: Q + v = PQvPCMPT370: geometry 17 Feb 200911


Affine spaces Combine a point (origin) with a vector space● Vector-vector addition: u + v● Scalar-vector multiplication: α * v● Point-vector addition: P + v● Scalar-scalar operations: α+β*γ For any point P, let● 1 * P = P● 0 * P = (zero vector) 0CMPT370: geometry 17 Feb 200912


Lines Parametric definition of a line:● All points P that pass through a point P 0in thedirection of the vector v:● P(α) = P 0+ α*v Alternate forms in 2D:P 1● Parametric: x(α) = (1-α)x 0+ (α)x 1,y(α) = (1-α)y 0+ (α)y 1● Explicit: y = mx + hP 0● Implicit: ax + by + c = 0vCMPT370: geometry 17 Feb 200913


Rays A ray is one side of a line:● All points P(α) = P 0+ α*vfor which α ≥ 0P 0v A line segment between points P 0and P 1is● All points P(α) = (1-α)P 0+ (α)P 1for which 0 ≤ α ≤ 1vP 0P 1CMPT370: geometry 17 Feb 200914


Curves We can generalize from lines to curves: Curves are one-parameter geometric entitiesP(α)● Often have a starting point P 0● α can be thought of as time Curve describes motion of a point through timeCMPT370: geometry 17 Feb 200915


Surfaces Curves P(α) have one parameter α Surfaces P( α,β) have two parameters α,β● Linear functions of α,β give planes andpolygons A plane in 3D can be defined by● Point + 2 vectors: P( α, β) = P+ αu+ βv0● Or 3 points: P( α, β) = P + α(Q-P) + β(R-P)0 0 0uQvP 0P 0RCMPT370: geometry 17 Feb 200916


Normal vectors Every plane has a vector n which is normal(perpendicular, orthogonal) to it Use cross-product: n = u x v Unit normal is the normal vectorwhich has magnitude 1 Perpendicular meansdotproduct is zero: n * v = 0nuP 0vCMPT370: geometry 17 Feb 200917


Convex hull The convex hull of a set of points {P 1, P 2, ..., P n}is the smallest convex area containing thepoints:● Convex: connect any two points in the area,the line segment is completely within thearea● “Shrink-wrap” of the points Points are convex sums of {P i}:● ∑α iP i, where ∑α i≤1 Triangles are the convex hullsof 3 pointsCMPT370: geometry 17 Feb 200918


Linear independence A set of vectors {v 1, v 2, ..., v n} islinearly independent if● α 1v 1+ α 2v 2+ ... + α nv n= 0only when all the α iare zero.● i.e., cannot represent one vector v iasa linear combination of the othersvuvindependentudependentCMPT370: geometry 17 Feb 200919


Basis Any vector space has a dimension:● Max # of linearly independent vectors A basis for an n-D vector space is a set of nvectors {v i} such that any vector w in the spacecan be written as a combination of them:● w = α 1v 1+ α 2v 2+ ... + α nv n● These {α i} are a unique representation forthe vector w with respect to this basis If the basis vectors are unit-length, this unitbasis is usually written {e i}CMPT370: geometry 17 Feb 200920


Frame A basis is enough to represent vectors, but● Holds no position information We use a frame to represent points● Basis + a point (origin): affine space In 3D: frame F = (P 0, e 1, e 2, e 3)● Any vector w = α 1e 1+ α 2e 2+ ... + α ne n● Any point P = P 0+ β 1e 1+ β 2e 2+ ... + β ne n● The representation is the scalar coefficients(α 1, α 2, ..., α n) or (β 1, β 2, ..., β n)CMPT370: geometry 17 Feb 200921

More magazines by this user
Similar magazines