1 / 24

Basic elements of 3-D coordinate systems and linear algebra

Basic elements of 3-D coordinate systems and linear algebra.

kathy
Download Presentation

Basic elements of 3-D coordinate systems and linear algebra

An Image/Link below is provided (as is) to download presentation Download Policy: Content on the Website is provided to you AS IS for your information and personal use and may not be sold / licensed / shared on other websites without getting consent from its author. Content is provided to you AS IS for your information and personal use only. Download presentation by click this link. While downloading, if for some reason you are not able to download a presentation, the publisher may have deleted the file from their server. During download, if you can't get a presentation, the file might be deleted by the publisher.

E N D

Presentation Transcript


  1. Basic elements of 3-D coordinate systems and linear algebra Coordinatatesystems 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. Two dimensions: the plane

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

  3. Basic elements of 3-D coordinate systems and linear algebra 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

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

  5. Vectors in 3-D space A vectorin 3-D space is sometimes called a directed distance because it represents both • adirection and • a magnitude or distance In this context, the tuple(px, py, pz) can also be considered to represent • the direction from the origin (0, 0, 0) to (px, py, pz) and • its length, sqrt(px2 + py2 +pz2), is the Euclidean (straight line) distance from the origin to (px, py, pz) For a vector P, the Euclidean distance or length of a vector is denoted

  6. Points and vectors Two points in 3-D space implicitly determine a vector pointing from one to the other. Given two points P and Q in 3-D Euclidean space, the vector R = P - Q = (px - qx, py - qy, pz - qz) represents the direction fromQtoP. Its length, as defined above, is the distance between P and Q. Note that the direction is a signed quantity. The direction from P to Q is the negative of the direction from Q to P. However, the distance from P to Q is always the same as the distance from Q to P.

  7. Points and vectors R = P - Q = (px - qx, py - qy, pz - qz) represents the direction fromQtoP. Its length, as defined above, is the distance between P and Q. Example: Let V = (8, 6, 5) and P = (3, 2, 0). Then the vector direction from V to P is (3 - 8, 2 - 6, 0 - 5) = (-5, -4, -5) The vector direction from P to V is (5, 4, 5) The distance between V and P is sqrt(25 + 16 + 25) = sqrt(66) = 8.12.

  8. The geometric interpretation of vector arithmetic Here we work with 2 dimensional vectors to simplify the visual interpretation, but in 3-d the principles are the same. P = (5, 1) => +5in the x direction and then +1 in the y direction Q = (2, 4) => +2in the x direction and +4 in the y direction. R = P + Q = (7, 5) P = R + (– Q) = R - Q

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

  10. Representing vectors in C Structure based representation We can also define a structured type in which the elements are explicitly named typedefstructtuple_type { double x; double y; double z; } tuple_t; tuple_t v;

  11. Representing vectors in C Structure based representation tuple_t v; In this representation, it is explicit that v.xis the x-component v.yis the y-component v.zis the z-component

  12. Useful operations on vectors: We define the sum of two vectors P and Q as the componentwise sums: R = P + Q = (px + qx, py + qy, pz + qz) (3, 4, 5) + (1, 2, 6) = (4, 6, 11) The difference of two vectors is computed as the componentwise differences: R = P - Q = (px - qx, py - qy, pz - qz) (3, 4, 5) - (1, 2, 6) = (2, 2, -1)

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

  14. Useful operations on vectors (cont’d): 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 = (pxqx+ pyqy, + pzqz) (2, 3, 4) dot (3, 2, 1) = 6 + 6 + 4 = 16 Thus || P || = sqrt(P dot P)

  15. Useful operations on vectors (cont’d): 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 between them then: cos(q) = U dot V = V dot U

  16. tuple library Since the previous operations will be commonly required in the raytracer, you will build a library of functions which we will call tuple.hto perform them. The tuple.hfile contains the following tuple_t definition: typedefstructtuple_type { double x; double y; double z; } tuple_t;

  17. Tuple functions tuple_tray(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(tx2 + ty2 + tz2)

  18. Tuple functions tuple_tscale(tuple_tt, 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_tadd(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.

  19. Tuple functions tuple_tscale(tuple_tt, 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_tadd(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.

  20. Tuple functions tuple_tunitize(tuple_tt); 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().

  21. Tuple functions 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 = (pxqx + pyqy + pzqz).  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.

  22. Tuple functions void printTuple(FILE *outFile, char *label, tuple_tt); 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. " 23.1200"). If t=(2.2, 0, -4.34567) the call: printTuple(stderr, "Result: ", t); should result in the output: Result: 2.2000 0.0000 -4.3456

  23. Tuple functions tuple_treadTuple(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.

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

More Related