|
62 | 62 | programs, then it'll be good to pause and catch you up. There are two kinds of randomized |
63 | 63 | algorithms: Monte Carlo and Las Vegas. Randomized algorithms can be found everywhere in computer |
64 | 64 | graphics, so getting a decent foundation isn't a bad idea. A randomized algorithm uses some amount |
65 | | -of randomness in its computation. A Las Vegas (LV) random algorithm always produces the correct |
66 | | -result, whereas a Monte Carlo (MC) algorithm _may_ produce a correct result--and frequently gets it |
67 | | -wrong! But for especially complicated problems such as ray tracing, we may not place as huge a |
68 | | -priority on being perfectly exact as on getting an answer in a reasonable amount of time. LV |
69 | | -algorithms will eventually arrive at the correct result, but we can't make too many guarantees on |
70 | | -how long it will take to get there. The classic example of an LV algorithm is the _quicksort_ |
71 | | -sorting algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the |
72 | | -time it takes to complete is random. Another good example of an LV algorithm is the code that we use |
| 65 | +of randomness in its computation. A Las Vegas random algorithm always produces the correct result, |
| 66 | +whereas a Monte Carlo algorithm _may_ produce a correct result--and frequently gets it wrong! But |
| 67 | +for especially complicated problems such as ray tracing, we may not place as huge a priority on |
| 68 | +being perfectly exact as on getting an answer in a reasonable amount of time. Las Vegas algorithms |
| 69 | +will eventually arrive at the correct result, but we can't make too many guarantees on how long it |
| 70 | +will take to get there. The classic example of a Las Vegas algorithm is the _quicksort_ sorting |
| 71 | +algorithm. The quicksort algorithm will always complete with a fully sorted list, but, the time it |
| 72 | +takes to complete is random. Another good example of a Las Vegas algorithm is the code that we use |
73 | 73 | to pick a random point in a unit sphere: |
74 | 74 |
|
75 | 75 | ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
|
85 | 85 |
|
86 | 86 | This code will always eventually arrive at a random point in the unit sphere, but we can't say |
87 | 87 | beforehand how long it'll take. It may take only 1 iteration, it may take 2, 3, 4, or even longer. |
88 | | -Whereas, an MC program will give a statistical estimate of an answer, and this estimate will get |
89 | | -more and more accurate the longer you run it. Which means that at a certain point, we can just |
| 88 | +Whereas, a Monte Carlo program will give a statistical estimate of an answer, and this estimate will |
| 89 | +get more and more accurate the longer you run it. Which means that at a certain point, we can just |
90 | 90 | decide that the answer is accurate _enough_ and call it quits. This basic characteristic of simple |
91 | | -programs producing noisy but ever-better answers is what MC is all about, and is especially good for |
92 | | -applications like graphics where great accuracy is not needed. |
| 91 | +programs producing noisy but ever-better answers is what Monte Carlo is all about, and is especially |
| 92 | +good for applications like graphics where great accuracy is not needed. |
93 | 93 |
|
94 | 94 |
|
95 | 95 | Estimating Pi |
|
3797 | 3797 | world.add(make_shared<quad>(point3(213,554,227), vec3(130,0,0), vec3(0,0,105), light)); |
3798 | 3798 |
|
3799 | 3799 |
|
3800 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
| 3800 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ highlight |
3801 | 3801 | // Box |
3802 | 3802 | shared_ptr<hittable> box1 = box(point3(0,0,0), point3(165,330,165), white); |
3803 | 3803 | box1 = make_shared<rotate_y>(box1, 15); |
|
3807 | 3807 | // Glass Sphere |
3808 | 3808 | auto glass = make_shared<dielectric>(1.5); |
3809 | 3809 | world.add(make_shared<sphere>(point3(190,90,190), 90, glass)); |
3810 | | - ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
| 3810 | + ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~~ C++ |
3811 | 3811 |
|
3812 | 3812 | // Light Sources |
3813 | 3813 | auto empty_material = shared_ptr<material>(); |
|
0 commit comments