proj home

Files   Classes   Functions   Hierarchy  

generaterandompoints.h

Go to the documentation of this file.
00001 #ifndef GENERATERANDOMPOINTS_H
00002 #define GENERATERANDOMPOINTS_H
00003 
00004 #include <vector>
00005 using namespace std;
00006 
00007 #include <typedefs.h>
00008 
00009 
00013 template< typename T, typename D, typename RG >
00014 class generateRandomPointsInCircle
00015 {
00016 public:
00017 
00019   generateRandomPointsInCircle
00020   (
00021     vector< T > & v,
00022     uintc n
00023   );
00024 };
00025 
00026 
00030 template< typename T, typename D, typename RG >
00031 class generateRandomPointsInSphere
00032 {
00033 public:
00034 
00036   generateRandomPointsInSphere
00037   (
00038     vector< T > & v,
00039     uintc n
00040   );
00041 };
00042 
00043 
00044 
00045 //---------------------------------------------------------
00046 //  Implementation
00047 
00048 
00049 template< typename T, typename D, typename RG >
00050 generateRandomPointsInCircle<T,D,RG>::generateRandomPointsInCircle
00051 (
00052   vector< T > & v,
00053   uintc n
00054 )
00055 {
00056   RG r;
00057   D x;
00058   D y;
00059   for (uint i=0; i<n; )
00060   {
00061     x = (D)2.0*r()-(D)1.0;
00062     y = (D)2.0*r()-(D)1.0;
00063     if (x*x+y*y <= (D)1.0)
00064     {
00065       v.push_back( T(x,y) );
00066       ++i;
00067     }
00068   }
00069 }
00070 
00071 
00072 template< typename T, typename D, typename RG >
00073 generateRandomPointsInSphere<T,D,RG>::generateRandomPointsInSphere
00074 (
00075   vector< T > & v,
00076   uintc n
00077 )
00078 {
00079   RG r;
00080   D x;
00081   D y;
00082   D z;
00083   for (uint i=0; i<n; )
00084   {
00085     x = (D)2.0*r()-(D)1.0;
00086     y = (D)2.0*r()-(D)1.0;
00087     z = (D)2.0*r()-(D)1.0;
00088     if (x*x+y*y+z*z <= (D)1.0)
00089     {
00090       v.push_back( T(x,y,z) );
00091       ++i;
00092     }
00093   }
00094 }
00095 
00096 
00097 
00098 
00099 
00100 
00101 #endif
00102 
00103 

Generated on Fri Mar 4 00:49:26 2011 for Chelton Evans Source by  doxygen 1.5.8