Computer Science 102 Test 1 Name____________________ 1. What is the length of the vector (1, 2, 2) 2. Suppose P and Q are points in 3-d space. The vector FROM P TO Q is given by: a. Q - P b. P - Q c. P + Q 3. Compute (2, 2, 3) dot (-1, 1, -1) 4. Compute (1, 2, 3) - (-3, 2, -1) 5. A unit vector from the viewpoint toward a pixel on the "screen" always has: a. a negative x component b. a negative y component c. a negative z component d. negative x, y, AND z components 6. Suppose world coordinate dimensions are 8 units wide by 6 units high and the viewpoint is at (4, 3, 6). A unit vector from the viewpoint toward the pixel at the upper left corner of the screen has: a. negative x, y, and z components b. negative y and z but positive x c. negative x and y but positive z d. negative x and z but positive y 7. Suppose the viewpoint is at location V and the world coordinates of the point on the screen through which a ray passes is W. A vector in the direction the ray is fired is given by: a. V + W b. V - W c. W - V c. (V + W) / 2.0 8. In the model description language we described in class, a set of attribute values may be followed by: a. } b. an attribute type c. a or b d. end-of-file 9. The elements of a table of attribute types declared as shown are: static char *ac_attrs[] = { "position", /* Current location of aircraft */ "direction", /* Direction of travel */ "speed", /* Speed in NM/hr */ }; a. character strings b. ints c. character variables d. pointers to characters strings 10. The proper way to define the number of entries in a table such as this one is: a. #define NUM_ATTRS (sizeof(ac_attrs[0]) / sizeof(char *)) b. #define NUM_ATTRS (sizeof(ac_attrs[0]) / sizeof(char)) c. #define NUM_ATTRS (sizeof(ac_attrs) / sizeof(char)) d. #define NUM_ATTRS (sizeof(ac_attrs) / sizeof(char *)) 11. In the model description language described in class, end-of-file can legally follow what token(s)? a. { b. } c. a collection of attribute d. any of the above values 12. Suppose prototypes for public functions are kept in "rayfuns.h" and this file is included in "ray.h" which also contains all of the structure definitions. The #include "rayfuns.h" must go a. At the start of ray.h before b. At the end of ray.h after the structure defs. the structure defs. c. Either place will work fine.. 13. Suppose a list of type list_t contains three items. The number of calls made to free() by list_del() should be a. 1 b. 3 c. 6 d. 7 14. Which is the proper way to declare a pointer to a function that returns an int and takes two ints as parameters: a. int *(pfun)(int, int); b. int (*pfun)(int, int); c. int pfun(int, int); d. int *pfun(int, int); 15. Which is the proper way to make the pointer point to a function named adder. a. pfun = adder; b. pfun = adder(0, 0); c. *pfun = adder; d. pfun = *adder; 16. Which is the proper way to actually call the adder function using the function pointer. a. sum = pfun(3, 4); b. sum = *pfun(3, 4); c. sum = (*pfun)(3, 4); d. sum = *(pfun)(3, 4); 17. Suppose a plane in 3 dimensional space has normal vector N and the P and Q are two different points that both lie in the plane. Which of the following will always have the value 0. a. N dot P b. P dot (N - Q) c. P dot Q - N d. N dot (P - Q) 18. Suppose a ray is fired from viewpoint V with unit direction vector D. The ray is parallel to the plane if: a. V dot D = 0 b. V dot N = 0 c. D dot N = 0 d. (N - D) dot V = 0 19. Suppose ray hits the plane at a distance t from V. The coordinates of the hitpoint are: a. P + tN b. V + tP c. D + tV d. V + tD 20. Suppose a plane is defined by N = (0, 0, 1) and Q = (3, 4, -8) where N is the normal and Q is a point on the plane. Suppose V = (4, 2, 5) and D = (0, 0, -1) a. The distance from V to the Hitpoint? b. Give the coordinates of the Hitpoint 21. Suppose a sphere is defined by Center = (4, 3, -8) and Radius = 2 Suppose Viewpoint = (4, 3, 4) and Direction = (0, 0, -1). What are the coordinates of the hitpoint ? Finding the intersection of a ray with a sphere requires solving a quadratic equation. 22. The ray misses the sphere entirely if: a. The discriminant is < 0 b. The discriminant is > 0 c. The discriminant is 0 23. The ray passes through the surface of the sphere at two points if a. The discriminant is < 0 b. The discriminant is > 0 c. The discriminant is 0 24. The correct root of the equation to use in determining the hitpoint is a. t = (-b - sqrt(b^2 - 4ac))/2a b. t = (-b + sqrt(b^2 - 4ac))/2a c. Either one will work fine 25. Suppose the center of the sphere is located at C and P is a point on the surface of the sphere. The normal to the surface at P is a. P b. C c. C - P d. P - C Programmming part: 1. Given the following structure definitions: typedef struct link_type typedef struct list_type { { struct link_type *next; link_t *head; void *item; link_t *tail; } link_t; } list_t; Complete the list_add() function as done in lab. void list_add( list_t *list, // pointer to list header void *entity) // pointer to item to be added { 2. Complete the getndx() function. If the candidate attribute name is in the table, its index should be returned. If not -1 should be returned. static inline int getndx( char *attab[], // pointer to table of ptrs to legit attr names int count, // number of entries in said table char *target) // pointer to candidate attribute name. { 3. Complete the vector dot product function static inline double vec_dot( vec_t *v1, vec_t *v2) { 4. Complete the cam_getdir function. It should return a unit vector from the view_point though the pixel whose pixel coordinates are passed in. You may "use" any of the vector.h functions without re-writing them. typedef struct camera_type { int pixel_dim[2]; /* Projection screen size in pix */ double world_dim[2]; /* Screen size in world coords */ vec_t view_point; /* Viewpt Loc in world coords */ irgb_t *pixmap; /* Build image here */ } cam_t; void cam_getdir( cam_t *cam, // -> camera structure int x, // X pixel coord int y, // Y pixel coord vec_t *dir) // return direction here {