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 (orthgonal) 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 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. The length as defined is the distance between P to 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: 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) 3.Distance between Q and P is: Sqrt( ) = Sqrt(66) = 8.12.

10 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.

11 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:

12 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( ) = sqrt(50) Useful operations on vectors (cont’d):

13 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) = = 16 Thus || P || = sqrt(P dot P) Useful operations on vectors (cont’d):

14 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 tuples. Useful operations on vectors (cont’d):

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

16 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: tuple_t t; t[X] = 11; t[Y] = 2; t[Z] = -4; Representing tuples in C

17 Structure based representation We can also define a structured type in which the elements are explicitly named typedef struct tuple_type { double x; double y; double z; } tuple_t; Representing tuples in C

18 Structure based representation tuple_t t; In this representation, it is explicit that t.x is the x-component t.y is the y-component t.z is the z-component Representing tuples in C

19 The tuple.h file contains the following definition: typedef struct tuple_type { double x; double y; double z; } tuple_t; Representing tuples

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

21 tuple_t scale(tuple_t t, double factor); This function multiplies each component of the input tuple “t" by a scaling factor "factor" and returns a new tuple that is scaled. tuple_t add(tuple_t t1, tuple_t t2); Compute the componentwise sum t1 + t2 and return a new tuple. tuple_t diff(tuple_t t1, tuple_t t2); Compute the componentwise difference t2 – t1 and return a new tuple. Tuple functions

22 tuple_t unitize(tuple_t t); Construct a unit length tuple in the direction of the input tuple t. A unit tuple is a tuple having length 1. To obtain the unit tuple in the direction of a tuple "t", scale "t" by (1 / ||t||). 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 tuple (0 = (0, 0, 0)) it should return zero tuple (i.e. (0, 0, 0)). To avoid crashing on a divide-by-zero exception, check for a zero-length tuple before calling scale(). Tuple functions

23 double dot(tuple_t t1, tuple_t t2); The inner product or dot product of two tuples 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 tuple) 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. Tuple functions

24 void printTuple(FILE *outFile, char *label, tuple_t t); Print the 3 elements of a tuple 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. " "). If t=(2.2, 0, ) the call: printTuple(stderr, "Result: ", t); should result in the output: Result: Tuple functions

25 tuple_t readTuple(FILE *inFile, char *errmsg) Try to read three double values from the input stream "inFile" and store the result in the tuple pointed to by t. The return value from readTuple() should be the tuple_t value if no errors occur. On error readTuple() should print the error message pointed to by "errmsg" and exit the program. Tuple functions

26 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