Lecture 2, curves, and surfaces
Organizational remarks Tutorials: Tutorial 1 will be online later today TA sessions for questions start next week Practicals: Exams: Make sure to find a team partner very soon Make sure to start working on the assignment very soon Make sure to contact me about exceptions, etc. very soon Dates will change Check website for exact data Inform us about conflicts as soon as possible
Recap: From 3D to 2D... Computer graphics: Modelling (creating 3d virtual worlds) Rendering (creating shaded 2d images from 3d models) Two basic methods: Ray tracing Projective methods The graphics pipeline: A sequence of operations transforming 3D models into pixels on the screen
From 2D geometry to pixels... In graphics, we usually deal with raster displays (not covered here; read chapter 3 if you want to know more). Raster displays = rectangular arrays of pixels Pixels (short for picture element ) = the smallest unit on the screen Single dots that make up the final image Remember: going from 2D geometry to fragments/pixels is called rasterization.
Screen coordinates (2D) How do we describe pixels on the screen? Usually pixels are usally indexed by their column i and row j with respect to a reference called the origin where i = 0 and j = 0. Be careful: in actual calculations, we sometimes deal with the pixel center (i.e. i + 0.5, j + 0.5 instead of i, j).
Screen coordinates (2D) Calculating the concrete coordinates of the center of pixel[i, j] from the abstract 2D geometry is easy, if we know The resolution n x n y of the image The x- and y-coordinates of the corners of the projection rectangle The order of the pixel rows (up or down)
Coordinates & coordinate systems Pixel coordinates give us a way to describe all points on the 2D screen. If we extend our screen to an infinite size, we can describe all points in a 2D space. If we add a third dimension, we can describe all points in a 3D space.
Coordinates & coordinate systems In graphics, such a system to describe n-dimensional spaces is often called a coordinate system. The required reference point (0, 0,..., 0) is called the origin. (More on coordinate systems later... )
Coordinates & coordinate systems We can not only use this to address the single pixels on the 2D screen, but also to describe our 3D world! We do this by using the mathematical concept of vectors (or vector spaces).
: definition Intro In R d a vector can be defined as an ordered d-tuple: v 1 v 2 v =. v d Alternatively, we can define a vector by its length and direction. v ( ) 5 v = 1
Points vs. vectors Intro 3D vectors and points (or locations) in 3D can both be represented with 3-tuples (x, y, z) but they are not the same! We can calculate with vectors (e.g. add them) We can add vectors to locations (resulting in new locations) But we can t add locations
: notations Intro In R 3, for example: v 1 v x x v v = v 2 or v y or y v v 3 v z z v or (v 1, v 2, v 3 ) or (v 1 v 2 v 3 ) T or... Note: there are also different symbols used for vectors, e.g. v, v, v,... v ( ) 5 v = 1
: algebraic interpretation A 2D vector (x v, y v ) can be seen as the point (x v, y v ) in the Cartesian plane. v ( ) 5 v = 1
: geometric interpretation A 2D vector (x v, y v ) can be seen as an offset from the origin. Such an offset (arrow) can be translated. v v v v = ( ) 5 1
of vectors Intro Given two vectors in R d, v = (v 1, v 2,..., v d ) and w = (w 1, w 2,..., w d ) their sum is defined as v + w = (v 1 + w 1, v 2 + w 2,..., v d + w d )
of vectors Intro of vectors is commutative, as can be seen easily from the geometric interpretation. Q: show algebraically that vector addition is commutative.
: length Intro The Euclidean length of a d-dimensional vector v is v = v1 2 + v2 2 + + v2 d v ( ) 5 v = 1
Null vector and unit vectors A vector 0 is the null vector if 0 = 0. A vector v is a unit vector if v = 1. Normalization: Given an arbitrary vector v, we can find a unit vector parallel to v by v unit = v v Q: Can every vector be normalized?
: scalar multiple A scalar multiple of a d-dimensional vector v is λ v = (λv 1, λv 2,..., λv d ) Note that v and λ v have either the same direction or opposite directions
Subtraction of vectors Intro Given two vectors in R d, v = (v 1, v 2,..., v d ) and w = (w 1, w 2,..., w d ) subtraction is defined as v w = (v 1 w 1, v 2 w 2,..., v d w d )
Parallel vectors Intro Two vectors v and w are parallel if one is a scalar multiple of the other, i.e., there is a λ such that v = λ w. Note that if one of the vectors is the null vector, then the vectors are considered neither parallel nor not parallel.
Bases Intro A 2D vector can be expressed as a combination of any pair of non-parallel vectors, i.e. a = λ 1 v + λ 2 w For instance, in the image, a = 1.5 v + 0.6 w. Such a pair is called linearly independent, and they form a 2D basis. v w a The extension to higher dimensions is straightforward.
Orthonormal basis Intro Two vectors form an orthonormal basis if (1) they are orthogonal to each other, and (2) they are unit vectors. The advantage of an orthonormal basis is that lengths of vectors, expressed in the basis, are easy to calculate.
Left- and right-handed systems Coordinate systems in 3D come in two flavors: left-handed and right-handed. There are arguments for both left- and right-handed systems for The global system The camera system Object systems Z X Y Y Y Z X X Z Camera coordinate system Z Y Y X X Z World coordinate system
Coordinate transformations A frequent operation in graphics is the change from one coordinate system (e.g., the (u, v, w) camera system) to another (e.g., the (x, y, z) global system). v u w Having orthonormal bases for both systems makes the transformations simpler. Z Y X
Dot product (inner product, scalar product) For two vectors v, w R d, the dot product (or inner product or scalar product) is defined as v w = v 1 w 1 +v 2 w 2 + +v d w d, dot product or v w = d i=1 v iw i 42 666 3.1415927
Dot product (inner product, scalar product) v w v w, We have that cos θ = where θ is the angle between the two vectors. dot product 42 666 3.1415927
Dot product (inner product, scalar product) Q: what is the inner product of an arbitrary unit vector with itself? Q: what do we know if for two vectors v and w we have that v w = 0? dot product 42 666 3.1415927
Dot product (inner product, scalar product) Another use: Calculate the length of the projection of one vector onto another. dot product 42 666 3.1415927
Cross product Intro For two vectors v, w R 3, the cross product is defined as v 2 w 3 v 3 w 2 v w = v 3 w 1 v 1 w 3 v 1 w 2 v 2 w 1 cross product We have that v w = v w sin θ, where θ is the angle between v and w.
Cross product Intro Q: show that v w is orthogonal to both v and w. Proof: (Remember the scalar product and cos 90 = 0) (a) v is perpendicular to v w v ( v w) = (v 1, v 2, v 3) (v 2w 3 v 3w 2, v 3w 1 v 1w 3, v 1w 2 v 2w 1) = (v 1v 2w 3 v 1v 3w 2 + v 2v 3w 1 v 2v 1w 3 + v 3v 1w 2 v 3v 2w 1) = 0 (b) w is perpendicular to v w Exercise cross product
Cross product Intro Special case: v and w are orthogonal unit vectors
Cross product Intro Q: what is v v? Q: what is v w if v and w are parallel? cross product
Cross product Intro Q: what is v v? The nullvector. Proof for the 1st coordinate: v 2v 3 v 3v 2 = 0 Other coordinates: exercise! Q: what is v w if v and w are parallel? Again, the nullvector. Parallel: w = λ v Proof for the 1st coordinate: λv 2v 3 v 3λv 2 = 0 Other coordinates: exercise! cross product
Cross product Intro Alternatively, remember that v w = v w sin θ Q: what is v v? θ = 0, so sin θ = 0 Hence, it must be the nullvector. cross product Q: what is v w if v and w are parallel? θ = 0, so sin θ = 0 Hence, it must be the nullvector.
Basic geometric entities (2D) Introduction General curves Circles Lines Normal vectors (and the related arithmetic) provide us with a powerful tool to create complex 3D graphics (and manipulate it). Let s look at some basic geometric shapes: lines and circles in 2D (3D later) There are different ways to represent such basic geometric entities, e.g.: implicit parametric v w a
2D Implicit curves Intro Introduction General curves Circles Lines Normal vectors An implicit curve in 2D has the form f(x, y) = 0 f maps two-dimensional points to a real value, i.e. (x, y) f(x, y) The points for which this value is 0 are on the curve, while other points are not on the curve.
Implicit representation of circles Introduction General curves Circles Lines Normal vectors The implicit representation of a 2D circle with radius r around the origin is x 2 + y 2 r 2 = 0 Why? If p = (x, y) is a vector pointing to a random point on the circle, it s length must be the circle s radius r, so p = r. x2 + y 2 = r x 2 + y 2 = r 2 x 2 + y 2 r 2 = 0 Note: alternatively, we could look at the related triangle and use Pythagoras.
Implicit representation of circles Introduction General curves Circles Lines Normal vectors The implicit representation of a 2D circle with center c and radius r is (x x c ) 2 + (y y c ) 2 r 2 = 0 Again, why?
Implicit representation of lines Introduction General curves Circles Lines Normal vectors A well-known representation of lines is the slope-intercept form y = ax + c This can easily be converted to ax + y c = 0 which is the implicit representation of a line, or in its general form: Ax + By + C = 0
Implicit representation of lines Introduction General curves Circles Lines Normal vectors If c = 0, the line intersects the origin, and we can represent the implicit representation using vectors, i.e. with p = n p = 0 ( ) x and n = y ( ) a 1
Implicit representation of lines Introduction General curves Circles Lines Normal vectors If the line does not intersect with the origin, we have with p = n ( p p 0 ) = 0 ( ) x, n = y ( ) a, p 1 0 = p 0 is a vector to a point on the line. ( p0x p 0y )
Implicit representation of lines Introduction General curves Circles Lines Normal vectors The vector notation is important, because the vector n = ( a, 1) is perpendicular to the line. (This is true for the first 2 coefficiants of any implicit line representation.) How can we prove that?
Implicit representation of lines Introduction General curves Circles Lines Normal vectors Proof: Assume the implicit representation f( p) = Ax + By + C = 0 of a line and two random points p 1 = (x 1, y 1), p 2 = (x 2, y 2) on this line. Then the vector p 2 p 1 must be on the line. We know that n = (n x, n y) is perpendicular to the line if and only if n ( p 2 p 1) = 0. n ( p 2 p 1) = n x(x 2 x 1) + n y(y 2 y 1) = n xx 2 n xx 1 + n yy 2 n yy 1 + C C = f( p 2) f( p 1) = 0
Normal vectors Intro Introduction General curves Circles Lines Normal vectors that are prependicular to another vector or line, are called normal vectors. Or, more general, if a vector is perpendicular to the tangent plane of a surface at a particular point p on that surface, we call it the surface normal (or just normal) to that surface at p.
General curves Lines Circles A parametric curve is controlled by a single parameter, and has the form ( ) x = y ( ) g(t) h(t) Parametric representations have some advantages over functions, even if a function would suffice to represent the curve. h(t) g(t)
General curves Lines Circles Parametric equation of a line The parametric equation of a line through the points p 0 and p 1 is p(t) = p 0 + t( p 1 p 0 ). with t R. We often call p 0 support vector and p 1 p 0 direction vector. (Or sometimes position and displacement vectors.) p 0 p 1
Parametric equation of a line General curves Lines Circles Alternatively, p(t) = p 0 + t( p 1 p 0 ). p can be written as 1 ( ) ( ) p 0 x xp0 + t(x = p1 x p0 ) y y p0 + t(y p1 y p0 )
General curves Lines Circles Conversion between representations Sometimes it is convenient to be able to convert from one representation into another. Q: how do we do that? p 0 p 1
General curves Lines Circles Conversion between representations Slope-intercept repr.: y = ax + b Implicit representation: f(x, y) = ax + y c = 0 or in its general form: f(x, y) = Ax + By + C = 0 p 0 p 1 Parametric representation (vector form): p(t) = p 0 + t( p 1 p 0 )
Parametric equation of a circle General curves Lines Circles The parametric equation of a 2D circle with center c and radius r is ( ) x y = ( ) xc + r cos φ y c + r sin φ p φ c