added method for generating a random point into a triangle (it generate three random barycentric coords)
This commit is contained in:
parent
a53447ab1c
commit
e3d0a6d0cb
|
@ -331,6 +331,18 @@ public:
|
||||||
return (((double)generate(0)) + 0.5)*(1.0/4294967296.0);
|
return (((double)generate(0)) + 0.5)*(1.0/4294967296.0);
|
||||||
}
|
}
|
||||||
|
|
||||||
|
/// Generate a random triple of baricentric coords
|
||||||
|
template <class PointType>
|
||||||
|
void generateBarycentric(PointType &p){
|
||||||
|
p[1] = this->generate01();
|
||||||
|
p[2] = this->generate01();
|
||||||
|
|
||||||
|
if(p[1] + p[2] > 1.0){
|
||||||
|
p[1] = 1.0 - p[1];
|
||||||
|
p[2] = 1.0 - p[2];
|
||||||
|
}
|
||||||
|
p[0]=1.0-(p[1] + p[2]);
|
||||||
|
}
|
||||||
};
|
};
|
||||||
|
|
||||||
|
|
||||||
|
|
Loading…
Reference in New Issue