Main Page | Namespace List | Class Hierarchy | Alphabetical List | Class List | File List | Namespace Members | Class Members | File Members | Related Pages

sampling.inl

Go to the documentation of this file.
00001 /*
00002     Sheep - A Rigid Body Dynamics Engine
00003     Copyright (C) 2001-2004 Francois Beaune
00004     Contact: http://toxicengine.sourceforge.net/
00005 
00006     This file is part of Sheep.
00007 
00008     Sheep is free software; you can redistribute it and/or modify
00009     it under the terms of the GNU General Public License as published by
00010     the Free Software Foundation; either version 2 of the License, or
00011     (at your option) any later version.
00012 
00013     Sheep is distributed in the hope that it will be useful,
00014     but WITHOUT ANY WARRANTY; without even the implied warranty of
00015     MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
00016     GNU General Public License for more details.
00017 
00018     You should have received a copy of the GNU General Public License
00019     along with Sheep; if not, write to the Free Software
00020     Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA  02111-1307  USA
00021 */
00022 
00023 inline
00024 sheep::Point2 UniformDiskSampling(sheep::Real xi1, sheep::Real xi2) {
00025     assert(xi1 >= 0.0 && xi1 <= 1.0);
00026     assert(xi2 >= 0.0 && xi2 <= 1.0);
00027 
00028     // Peter Shirley and Kenneth Chiu. A low distortion map between disk and square.
00029     // Journal of Graphics Tools, 2(3):45-52, 1997.
00030     // http://www.acm.org/jgt/papers/ShirleyChiu97/.
00031 
00032     const sheep::Real a = xi1 + xi1 - 1.0;
00033     const sheep::Real b = xi2 + xi2 - 1.0;
00034 
00035     sheep::Real phi, r;
00036 
00037     if(a > -b) {        // region 1 or 2
00038         if(a > b) {     // region 1, also |a| > |b|
00039             r = a;
00040             phi = (sheep::PI / 4.0) * (b / a);
00041         } else {        // region 2, also |b| > |a|
00042             r = b;
00043             phi = (sheep::PI / 4.0) * (2.0 - (a / b));
00044         }
00045     } else {            // region 3 or 4
00046         if(a < b) {     // region 3, also |a| >= |b|, a != 0
00047             r = -a;
00048             phi = (sheep::PI / 4.0) * (4.0 + (b / a));
00049         } else {        // region 4, |b| >= |a|, but a == 0 and b == 0 could occur
00050             r = -b;
00051             if (b != 0.0)
00052                 phi = (sheep::PI / 4.0) * (6.0 - (a / b));
00053             else
00054                 phi = 0.0;
00055         }
00056     }
00057 
00058     return sheep::Point2(r * cos(phi), r * sin(phi));
00059 }
00060 
00061 inline
00062 sheep::Point3 UniformSphereSampling(sheep::Real xi1, sheep::Real xi2) {
00063     assert(xi1 >= 0.0 && xi1 <= 1.0);
00064     assert(xi2 >= 0.0 && xi2 <= 1.0);
00065 
00066     const sheep::Real r = 2.0 * sqrt(xi1 * (1.0 - xi1));    //!\todo Turn the multiplication into an addition.
00067     const sheep::Real phi = 2.0 * sheep::PI * xi2;  //!\todo Turn the multiplication into an addition.
00068 
00069     return sheep::Point3(r * cos(phi), 1.0 - 2.0 * xi1, r * sin(phi));  //!\todo Turn the multiplication into an addition.
00070 }
00071 
00072 inline
00073 sheep::Point3 UniformHemisphereSampling(sheep::Real xi1, sheep::Real xi2) {
00074     assert(xi1 >= 0.0 && xi1 <= 1.0);
00075     assert(xi2 >= 0.0 && xi2 <= 1.0);
00076 
00077     const sheep::Real r = sqrt(1.0 - xi1 * xi1);
00078     const sheep::Real phi = 2.0 * sheep::PI * xi2;  //!\todo Turn the multiplication into an addition.
00079 
00080     return sheep::Point3(r * cos(phi), xi1, r * sin(phi));
00081 }
00082 
00083 inline
00084 sheep::Point3 CosineHemisphereSampling(sheep::Real xi1, sheep::Real xi2) {
00085     assert(xi1 >= 0.0 && xi1 <= 1.0);
00086     assert(xi2 >= 0.0 && xi2 <= 1.0);
00087 
00088     const sheep::Real r = sqrt(1.0 - xi1);
00089     const sheep::Real phi = 2.0 * sheep::PI * xi2;  //!\todo Turn the multiplication into an addition.
00090 
00091     return sheep::Point3(r * cos(phi), sqrt(xi1), r * sin(phi));
00092 }

Generated on Tue May 11 01:31:52 2004 for toxic by doxygen 1.3.6