Presentation is loading. Please wait.

Presentation is loading. Please wait.

Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin.

Similar presentations


Presentation on theme: "Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin."— Presentation transcript:

1 Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin. The number of dimensions in the coordinate system is equal to the number of perpendicular (orthogonal) axes and is also the number of values needed to specify a location with respect to the origin Basic elements of 3-D coordinate systems and linear algebra

2 One dimension: the line Two dimensions: the plane Basic elements of 3-D coordinate systems and linear algebra

3 Three dimensions: the universe as we perceive it (A right handed coordinate system is shown. In a left handed system the direction of the positive z axis is reversed. ) Two dimensions: the plane Basic elements of 3-D coordinate systems and linear algebra

4 The location of a point P in 3-D Euclidean space is given by a triple (p x, p y, p z ) The x, y, and z coordinates specify the distance you must travel in directions parallel to the the x, y, and z axes starting from the origin (0, 0, 0) to arrive at the point (p x, p y, p z ) Points in 3-D space

5 Some physical properties, such as temperature and area, are given completely by their magnitude, and only need a number to represent them (scalar). But, for other physical quantities such as force, velocity, or acceleration, we must know direction as well as size (magnitude). We represent these physical properties as direction lines or vectors. Vectors contain both magnitude and direction. Vectors in 3-D space

6 A vector in 3-D space is sometimes called a directed distance because it represents both –a direction and –a magnitude or distance In this context, the triple (p x, p y, p z ) can also be considered to represent –the direction from the origin (0, 0, 0) to (p x, p y, p z ) and –its length sqrt(p x 2 + p y 2 + p z 2 ) is the Euclidean (straight line) distance from the origin to (p x, p y, p z ) Vectors in 3-D space

7 Properties of Vectors 1.Two vectors are equal if and only if they are equal in both magnitude and direction. a != b (length is equal but not direction). Vectors c are equal! 2.If c is a vector, then –c is defined as having the same magnitude but the reverse direction to c. 3.Multiplying a vector by a number (or scalar) just has the same effect of changing its scale. Eg. 2a would be twice as long as a but the same direction as a. Vectors:

8 Free vs. Position Vectors Free Vectors: Two Vectors labelled c are defined to be equal although we need a shift to move them exactly on top of each other. Vectors that can be shifted about are called free vectors. Position Vector: A vector that indicates the position of a point in a coordinate system. –Eg: Vector r is called a position vector of the point P from the fixed origin O, and describes the displacement of P from O – must run from O to P and can’t be shifted. Vectors:

9 Points and Vectors Two points in 3D space implicitly determine a vector pointing from one to the other. Given to point P and Q, the vector R: R = P - Q = (p x - q x, p y - q y, p z - q z ) R represents the direction from Q to P. Note that the direction is a signed quantity. The direction from P to Q is the negative of the direction from Q to P. Example: Let Q = (8, 6, 5) and P = (3, 2, 0) Then: 1.Vector direction from Q to P is: (3-8, 2-6, 0-5) = (-5, -4, -5) 2.Vector direction from P to Q is: (8-3, 6-2, 5-0) = (5, 4, 5)

10 Points and Vectors The length is defined as the distance between P and Q. The distance from P to Q is always the same as the distance from Q to P. Example: Let Q = (8, 6, 5) and P = (3, 2, 0) Then: 2.Distance between Q and P is: Sqrt(25 + 16 + 25) = Sqrt(66) = 8.12.

11 Geometric Interpretation of Vector Arithmetic We illustrate vector addition in 2D, but in 3D the principles are same. Since we can think of vectors as displacements or journeys, to add two vectors, we just need to find the single displacement which gives the same result as doing the two displacements separately. Example: If a boat sets a course to move with velocity P in water flowing with velocity Q, then it will actually have a Resultant velocity of P + Q.

12 We define the sum of two vectors P and Q as the componentwise sums: R = P + Q = (p x + q x, p y + q y, p z + q z ) (3, 4, 5) + (1, 2, 6) = (4, 6, 11) The difference of two vectors is computed as the componentwise differences: R = P - Q = (p x - q x, p y - q y, p z - q z ) (3, 4, 5) - (1, 2, 6) = (2, 2, -1) Useful operations on vectors:

13 We also define multiplication (or scaling) of a vector by a scalar number a S = aP = (ap x, ap y, ap z ) 3 * (1, 2, 3) = (3, 6, 9) The length of a vector P is a scalar whose value is denoted: || P || = sqrt(p x 2 + p y 2 + p z 2 ) || (3, 4, 5) || = sqrt(9 + 16 + 25) = sqrt(50) Useful operations on vectors (cont’d):

14 A unit vector is a vector whose length is 1. Therefore an arbitrary vector P may be converted to a unit vector by scaling it by 1 / (its own length). Here U is a unit vector in the same direction as P. U = ( 1 / || P || ) P The inner product or dot product of two vectors P and Q is a scalar number. It is a value expressing the angular relationship between two vectors. The dot product is computed by taking the sum of the componentwise products of the two vectors. x = P dot Q = (p x q x + p y q y, + p z q z ) (2, 3, 4) dot (3, 2, 1) = 6 + 6 + 4 = 16 Thus || P || = sqrt(P dot P) Useful operations on vectors (cont’d):

15 The dot product has the following relationship with the lengths of two vectors and the angle between them. If U and V are vectors and q is the angle between them, then U dot V = V dot U = || U ||* || V || * cos(q) If U and V are unit vectors and q is the angle beween them then: cos (q) = U dot V = V dot U In this course, we will refer to vectors as vectors. Useful operations on vectors (cont’d):

16 There are at least two easy ways to represent a vector: Array based representation: We can use the typedef facility to create a user defined type called vector_t. An instance of vector_t is a three element double precision array: typedef double vector_t[3]; An instance of vector_t is a three element double precision array and can be created as shown. vector_t vec; It is understood that vec[0] is the x-component (coordinate) vec[1] is the y-component vec[2] is the z-component Representing vectors in C

17 Array based representation (cont’d): To make this association explicit we use the #define facility #define X 0 #define Y 1 #define Z 2 We can then create an instance of the vector (11, 2, -4) as shown: vector_t v; v[X] = 11; v[Y] = 2; v[Z] = -4; Representing vectors in C

18 Structure based representation We can also define a structured type in which the elements are explicitly named typedef struct vector_type { double x; double y; double z; } vector_t; Representing vectors in C

19 Structure based representation vector_t v; In this representation, it is explicit that v.x is the x-component v.y is the y-component v.z is the z-component Representing vectors in C

20 The vector.h file contains the following definition: typedef struct vector_type { double x; double y; double z; } vector_t; Representing vectors in C

21 vector_t ray(vector_t v1, vector_t v2); Compute a non-unitized vector from point t1 to point t2. This is just computing the componentwise difference t2 - t1 and returning the new vector value. NOTE: The vector from t1 to t2 is not the same as the vector from t2 to t1!!! double length(vector_t v); Computes the length of the vector. The length is the square root of the sum of the squares of the components of the vector: || v || = sqrt(v x 2 + v y 2 + v z 2 ) Vector functions

22 vector_t scale(vector_t v, double factor); This function multiplies each component of the input vector “v" by a scaling factor "factor" and returns a new vector that is scaled. vector_t add(vector_t v1, vector_t v2); Compute the componentwise sum v1 + v2 and return a new vector. vector_t diff(vector_t v1, vector_t v2); Compute the componentwise difference v2 – v1 and return a new vector. Vector functions

23 vector_t unitize(vector_t v); Construct a unit length vector in the direction of the input vector v. A unit vector is a vector having length 1. To obtain the unit vector in the direction of a vector "v", scale "v" by (1 / ||v||). Hint: you can use length() and scale() to do much of the work for you in this function. If this function is called with the zero vector (0 = (0, 0, 0)) it should return zero vector (i.e. (0, 0, 0)). To avoid crashing on a divide-by-zero exception, check for a zero-length vector before calling scale(). Vector functions

24 double dot(vector_t v1, vector_t v2); The inner product or dot product of two vectors P and Q is a scalar number: x = P dot Q = (p x q x + p y q y + p z q z ). Thus || P || = sqrt(P dot P) We will find that the dot product operation is very useful in the construction of the ray tracer because the dot product of two UNIT vectors (a vector is just a type of vector) yields the cosine of the angle between the two vectors. That is, if P and Q are unit vectors then P dot Q is the cosine of the angle between the vectors P and Q. If they are not unit vectors then (P dot Q) / (|| P || || Q || ) yields the cosine. Vector functions

25 void printVector(FILE *outFile, char *label, vector_t t); Print the 3 elements of a vector on a line prefixed by a label to the output stream "outfile". Each value should be printed in a field that is a minimum of 8 characters wide and with 4 decimal places (e.g. " 23.1200"). If t=(2.2, 0, -4.34567) the call: printVector(stderr, "Result: ", t); should result in the output: Result: 2.2000 0.0000 -4.3456 Vector functions

26 vector_t readVector(FILE *inFile, char *errmsg) Try to read three double values from the input stream "inFile" and store the result in the vector pointed to by t. The return value from readVector() should be the vector_t value if no errors occur. On error readvector() should print the error message pointed to by "errmsg" and exit the program. Vector functions

27 We will also find other data types that are readily represented as 3 fields, in particular a point, a pixel, or color. Representing other data


Download ppt "Coordinatate systems are used to assign numeric values to locations with respect to a particular frame of reference commonly referred to as the origin."

Similar presentations


Ads by Google