480 likes | 617 Views
CSE 470: Computer Graphics. Geometric Objects. A vector space contains vectors and scalars. A vector has direction and magnitude (but not position). Vectors are denoted by u, v, w (lower case). A scalar is a real number. Scalars are denoted by a, b, g
E N D
Geometric Objects • A vector space contains vectors and scalars. A vector has direction and magnitude (but not position). Vectors are denoted by u, v, w (lower case). A scalar is a real number. Scalars are denoted by a, b, g • An affine space is an extension of the vector space to include points (positions in space). Points are denoted by P, Q, R (upper case) 3. A Euclidean space extends the linear vector space to add a measure of size or distance.
Combining entities in affine space • Vector-scalar multiplication |av| = |a| |v|, where |v| is the magnitude of v The direction of av is the same as the direction of v v 2v • Point-vector addition Adding a vector to a point results in another point. P Q + v = P v Q v = P - Q
Vector addition u = (x1, y1) (x1 is horizontal component of u, y1 is vertical component of u.) v = (x2, y2) u+v = (x1+x2, y1+y2) v v u+v u u Place the tail of v at the head of u. Draw a vector from the tail of u to the head of v.
A parametric line P(a) A line in space: P(a) = P0 + av P0 v • Affine sums: • P(a) = Q + av defines a line • There exists R such that • R = Q + v or v = R - Q • P = Q + a(R-Q) = aR + (1-a)Q = a1R + a2Q where a1 + a2 = 1 If 0 <= a <= 1, then all P lie on the line between Q and R.
A parametric line P(a) A line in space: P(a) = P0 + av P0 v • Affine sums: • P(a) = Q + av defines a line • There exists R such that • R = Q + v or v = R - Q • P = Q + a(R-Q) = aR + (1-a)Q = a1R + a2Q where a1 + a2 = 1 If 0 <= a <= 1, then all P lie on the line between Q and R. a = 1 R a = 0 Q
Affine sums for more points The affine sum for three points: P3 P = a1P1 + a2P2 + a3P3, where a1 + a2 + a3 = 1, ai >=0 defines all points inside triangle P1P2P3. P2 P1 The affine sum for n points: P = a1P1 + a2P2 + ... + anPn, where a1 + a2 + ...+ an = 1, ai >=0 defines all points inside convex hull around P1P2...Pn. A convex hull is like shrink-wrap around all n points.
The dot product The dot product (or inner product) of two vectors is defined as follows: where q represents the angle between the two vectors. u Projection of u onto v: q w v
The cross product The cross product of two linearly independent (non-parallel) vectors is a third vector that is orthogonal to both of them. n v u The direction of n is defined by the right handed coordinate system.
A parametric plane A plane in affine space can be defined in terms of two linearly independent vectors as follows: au bv P au bv P0
Defining a coordinate system Any 3D vector, w, can be defined in terms of 3 linearly independent vectors, v1, v2, v3: v2 w v1 v3 a1, a2 and a3 are components of w with respect to the basis (v1, v2, v3).
Matrix representation of vectors We can represent w as a column matrix:
Adding a point of reference Because vectors have no position, we must add a reference point to specify a coordinate frame. Choose P0 as reference. Vectors can be written as: v2 P Points can be written as: v1 P0 v3
Matrices A Matrix is a rectangular array of quantities: 2x3 Matrix 2x2 Matrix 3x1 Matrix M x N Matrix
Matrix multiplication To multiply two matrices, multiply the rows in the first matrix by the columns of the second matrix. Example:
Matrix multiplication In general:
Matrix terminology 1. The transpose of a matrix, exchanges the rows and columns of that matrix. 2. When a matrix, A, is multiplied by the identity matrix, the result is the same matrix A. AI = A 3. The a matrix, A, is multiplied by its inverse, A-1, the result is the identity matrix. AA-1 = I
Recall Coordinate systems Coordinate systems are represented by a set of basis vectors (v1, v2, v3) and a reference point, P0. Vectors can be written as: Points can be written as: v2 P v1 P0 v3
Changing the basis set We can move from basis (v1, v2, v3) to basis (u1, u2, u3) using the following set of equations: v2 u2 u1 v1 v3 u3 In matrix form: u = Mv
Representing a vector in the new basis set Suppose: We would like to find b, such that:
Solving for b bTM = aT (aT)T = a = (bTM)T = MTb b = (MT)-1a
Homogeneous coordinates Transformation of basis vectors leaves the origin unchanged. Homogeneous coordinates allow us to transform the origin. Recall representation of a point: To represent P with matrices, we add a 4th dimension so we can include position: P is represented by: For vectors, the fourth coordinate is zero.
Changing frames in homogeneous coordinates Changing from (v1, v2, v3, P0) to (u1, u2, u3, Q0): u2 u1 v2 Q0 u3 v1 P0 v3 In matrix form:
Transforming a point between coordinate systems Suppose P is represented by b in the u, Q0 space and by a in the v, P0 space. (bT = [b1, b2, b3, 1], aT = [a1, a2, a3, 1]) a = MTb b = (MT)-1a
Affine transformations Affine transformations are linear transformations from a point in one frame to another frame: f(ap + bq) = af(p) + bf(q) a, b are scalars; p, q are vertices. Affine transformations preserve lines. We can represent the transformation as: v = Au where
Recall Affine transformations Affine transformations are linear transformations from a point in one frame to another frame. Affine transformations preserve lines. We can represent the transformation as: v = Au where
Translation Translation: Displace points by a fixed distance in a given direction. d Equations: In matrix form: x' = x + ax y' = y + ay z' = z + az p' = Tp where
Inverse translation T is the translation matrix Inverse translation: Displace by -d
Rotation about the Z axis Rotation about the Z axis y x = rcosf y = rsinf (x', y') r q (x, y) f x' = rcos(q+f) y' = rsin(q+f) x x' = rcos(f)cos(q) - rsin(f)sin(q) = xcos(q) - ysin(q) y' = rsin(q)cos(f) + rcos(q)sin(f) = xsin(q) + ycos(q)
The rotation matrix The equations: x' =xcos(q) - ysin(q) y' =xsin(q) + ycos(q) z' = z In matrix form: P' = RZP where
Rotation about the X axis The equations: z (y', z') y' =ycos(q) - zsin(q) z' =ysin(q) + zcos(q) x' = x r q (y, z) f y In matrix form: P' = RXP where
Rotation about the Y axis The equations: x (z', x') z' =zcos(q) - xsin(q) x' =zsin(q) + xcos(q) y' = y r q (z, x) f z In matrix form: P' = RYP where
Reversing Rotations We use the facts that cos(-q) = cos(q) sin(-q) = -sin(q)
Scaling Translation and Rotation are rigid body transformations. Scaling is not rigid. Equations: x' = bxx y' = byy z' = bzz P' = SP Scale with S(1/bx, 1/by, 1/bz) Inverse scaling:
Concatenation of Transformations • Suppose you want to: • Scale an object • Rotate the object • Translate the object For each vertex, we apply a series of transformations: P1 = SP P2 = RP1 = RSP P3 = TP2 = TRSP For efficiency, we create a new matrix, M = TRS. Each new point can be computed directly as P3 = MP Note: Matrix multiplication is not commutative. Order Matters!
Example P1 P3 P2 • Transformations: • Double the height • Rotate by 90 deg clockwise about the Z axis • Translate horizontally by
Trigonometry review r y q x
Shear y y (x, y) (x', y') q x x Equations: x' = x+ycosq y' = y z' = z Matrix:
Rotation about a fixed point Suppose you want to rotate an object about a fixed point, pf = (xf, yf, zf), about an axis parallel to the Z axis. y pf x z Translate object so that pf is at the origin. Rotate object about the Z axis Translate object back to pf
General Rotation Can generate any rotation with a combination of RxRyRz = R. Calculating the angles can be tricky. • Rotation about an arbitrary axis through the origin: • Use rotations to align the axis with the Z axis. • Rotate about the Z axis • Undo the rotations from (1).
Defining the Rotation Axis 1. Define rotation axis as a vector of length 1 (a unit vector) with x, y and z components: ax, ay, az where ax az v ay
Calculating qx Project vector v to the y-z plane. (Draw line from tip of v perpendicular to y-z plane). qx is the angle of this projection from the z axis. y az d v ay q x z where
Calculating qy When rotating about the X axis, the x component stays the same, but the y and z components change. y ax r x cosqy = d sinqy = ax 1 qy z Note: The rotation is clockwise, so the angle will be negative.
The full rotation Rotation about an arbitrary axis: Rotation about a fixed point, pf, parallel to an arbitrary axis:
Most slides are selected from:http://mathcs.holycross.edu/~croyden/csci343 Thank You