Lecture 2, curves, and surfaces
Organizational remarks Tutorials: TA sessions for tutorial 1 start today Tutorial 2 will go online after lecture 3 Practicals: 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 TA sessions started this morning Deadline P1 is May 7 (make sure you downloaded the latest file for P1!) P2 will go online May 1 (or earlier)
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 (pixel-based) Projective methods (obj.-based) 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 (screen or window) 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 Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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.
: notations Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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,...
: length Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product The Euclidean length of a d-dimensional vector v is v = v1 2 + v2 2 + + v2 d In 2D, this is similar to the Pythagorean theorem: a 2 + b 2 = c 2
: special cases Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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?
: special cases Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product A vector 0 is the null vector if 0 = 0.
: algebraic interpretation Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Algebraic interpretation: A 2D vector (x v, y v ) can be seen as the point (x v, y v ) in the Cartesian plane. 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.
: geometric interpretation Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Algebraic interpretation: A 2D vector (x v, y v ) can be seen as the point (x v, y v ) in the Cartesian plane. 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.
Points vs. vectors Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Be careful: vectors are an abstract concept! 3D vectors can be used to represent points (or locations) in 3D with 3-tuples (x, y, z) but they are not the same! (This will become clearer when we ll be doing vector arithmetics.)
Addition of vectors Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 ) Example: (5, 2) + (2, 3) = (7, 5)
Addition of vectors Intro Addition of vectors is commutative, as can be seen easily from the geometric interpretation. Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Example: (2, 3) + (5, 2) = (7, 5) Exercise: show algebraically that vector addition is commutative.
Subtraction of vectors Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 )
Scalar multiplication Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product A scalar multiple of a d-dimensional vector v is defined as λ v = (λv 1, λv 2,..., λv d ) Scalar multiplication can change the length of a vector. Its direction either stays the same (if λ > 0) or it reverses (if λ < 0).
Parallel vectors Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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.
Parallel vectors and normal vectors Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Parallel vectors are also called linearly dependent. that are not parallel, are called linearly independent A vector that is perpendicular to another one is called normal vector (or just normal) to that vector.
Bases Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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. In general, any pair of linearly independent, and they form a 2D basis. The extension to higher dimensions is straightforward.
Orthonormal basis Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product We have already used this when intuitively describing the Cartesian coordinate system. In general, we say that two vectors form an orthonormal basis if 1 they are orthogonal to each other, and 2 they are unit vectors.
Left- and right-handed systems Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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
Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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
Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Dot product (inner product, scalar product) We have that cos θ = v w v w where θ is the angle between the two vectors. dot product 42 666 3.1415927
Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Dot product (inner product, scalar product) The relation v w = v w cos θ can be very useful. For example, if the dot product is... 0 and none of them is the null vector, then θ must be 90 or 270 degrees 1 and both vectors are unit vectors, then θ must be 0 or 180 degrees
Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Dot product (inner product, scalar product) Another use: Calculate the length of the projection of one vector onto another. v w = v w cos θ With cos θ = p = p v, we get v w w
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 Notice that it is only defined in 3D.
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Again, we have a relationship involving a trigonometric function, i.e. v w = v w sin θ with θ = angle betw. v and w. cross product Notice that it only involves the length of the cross product, not the vector itself!
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product 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 Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Special case: v and w are orthogonal unit vectors. Remember that v w = v w sin θ Hence, v w must be a unit vector. But which direction? We see that v w = w v (note: cross product is not commutative)
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Q: what is v v? Q: what is v w if v and w are parallel? cross product
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Q: what is v v? The null vector. 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 null vector. Parallel: w = λ v Proof for the 1st coordinate: λv 2v 3 v 3λv 2 = 0 Other coordinates: exercise! cross product
Cross product Intro Definitions Simple vector arithmetics Bases and coordinate systems Dot product and cross product Alternatively, remember that v w = v w sin θ Q: what is v v? θ = 0, so sin θ = 0 Hence, it must be the null vector. cross product Q: what is v w if v and w are parallel? θ = 0, so sin θ = 0 Hence, it must be the null vector.
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
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 (Remember the relation to 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 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 Slope m = y 2 y 1 x 2 x 1 = y x for any two points (x 1, y 1 ), (x 2, y 2 ) on the line.
Implicit representation of lines If c = 0, the line intersects the origin, and we can represent the implicit representation using vectors, i.e. Introduction General curves Circles Lines Normal vectors with p = n p = 0 ( ) x and n = y ( ) a 1 Remember the scalar product: n p = ax + y
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 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 A vector that is perpendicular to another one is called normal vector (or just normal) to that vector. 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.
Intro 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)
Parametric equation of a line The parametric equation of a line through the points p 0 = (x p0, y p0 ) and p 1 = (x p1, y p1 ) is ( ) x y = with t R. ( ) xp0 + t(x p1 x p0 ) y p0 + t(y p1 y p0 ) Alternatively, this can be written as p(t) = p 0 + t( p 1 p 0 ).
Parametric equation of a line When using this vector notation of a parametric line, i.e. p(t) = p 0 + t( p 1 p 0 ), we often call p 0 support vector and p 1 p 0 direction vector. (Some sources speak of position and displacement vectors instead.)
Conversion between representations Sometimes it is convenient to be able to convert from one representation into another. Q: how do we do that?
Conversion between representations Slope-intercept repr.: y = ax + c Implicit representation: f(x, y) = ax + y c = 0 or in its general form: f(x, y) = Ax + By + C = 0 or in vector notation: n ( p p 0 ) = 0 Parametric representation (vector form): p(t) = p 0 + t( p 1 p 0 )
How to get normal vectors in 2D If two vectors are perpendicular, their scalar product is 0. Hence, if n = (n x, n y ) is a normal to p = (x, y), we have: p n = xn x + yn y = 0 From the equation, we see that this is only true if either n = (y, x) or if n = ( y, x) (or if one of them is the null vector)
Parametric equation of a circle The parametric equation of a 2D circle with center c and radius r is ( ) x y = ( ) xc + r cos φ y c + r sin φ
Recap: Trigonometry Intro cos Φ = x r sin Φ = y r tan Φ = y x cot Φ = x y
Recap: Trigonometry Intro cos Φ = x r x = r cos Φ sin Φ = y r y = r sin Φ tan Φ = y x cot Φ = x y
Parametric equation of a circle The parametric equation of a 2D circle with center c and radius r is ( ) x y = ( ) xc + r cos φ y c + r sin φ