Suppose that in ordering the triangles we place the largest


(a) Write a WPF program that uses the method in Exercise 32.6 to generate points in a triangle. The user should be able to drag the three triangle vertices, and press buttons to generate either a single point or 100 points, each of which should be displayed as a colored dot within the triangle. Another button should clear the points.

(b) Extend your program to handle meshes. Generate a 2D mesh (perhaps the Delaunay triangulation for a random set of points), and then improve your program to pick a point (or 100 points) in the mesh uniformly at random. Do so by precomputing the triangle areas, summing them, and then assigning each triangle a probability given by its area divided by the total area. Put the triangles in some order, and compute probability sums s[0] = p[0], s[1] = p[0] + p[1], s[2] = p[0] + p[1] + p[2], etc. Given a uniform random variable u, you can now identify the largest index i with u ≤ s[i]. To generate a random mesh point, you can pick a uniform random number u, identify the last triangle i with u ≤ s[i], and then generate a random point in that triangle (see Exercise 32.6).

(c) Briefly discuss how to make the triangle-selection process faster than O(n), where n is the number of triangles in the mesh.

(d) Suppose that in ordering the triangles, we place the largest ones first. Then in a search of the list, we're likely to examine relatively few triangles to find the "right" one. Would you, in working with a typical graphics model, expect this to have a large impact on the sampling time? Why or why not?

Request for Solution File

Ask an Expert for Answer!!
Basic Computer Science: Suppose that in ordering the triangles we place the largest
Reference No:- TGS02153030

Expected delivery within 24 Hours