Now zonohedra construction robust to basically *any* input, no matter how degenerate.
This commit is contained in:
parent
0448e15f5b
commit
3adc453f53
|
@ -132,8 +132,17 @@ private:
|
||||||
return -v;
|
return -v;
|
||||||
}
|
}
|
||||||
|
|
||||||
|
static Vec3 altVec(int i) {
|
||||||
|
return Vec3(1, i, i*i);
|
||||||
|
}
|
||||||
|
|
||||||
|
static Scalar tripleProduct( const Vec3 &a, const Vec3 &b, const Vec3 & c){
|
||||||
|
return ( a ^ b ) * c;
|
||||||
|
}
|
||||||
|
|
||||||
// returns signof: (i x j) * k
|
// returns signof: (i x j) * k
|
||||||
bool signOf_IxJoK(VecIndex i, VecIndex j, VecIndex k){
|
bool signOf_IxJoK(VecIndex i, VecIndex j, VecIndex k){
|
||||||
|
const float EPSILON_SQUARED = 1e-12;
|
||||||
bool invert = false;
|
bool invert = false;
|
||||||
// sort i,j,k
|
// sort i,j,k
|
||||||
if (i<j) { std::swap(i,j); invert = !invert; }
|
if (i<j) { std::swap(i,j); invert = !invert; }
|
||||||
|
@ -144,15 +153,23 @@ private:
|
||||||
//Scalar res = Vec3::dot( Vec3::cross( vec[i] , vec[j] ) , vec[k] );
|
//Scalar res = Vec3::dot( Vec3::cross( vec[i] , vec[j] ) , vec[k] );
|
||||||
Scalar res = cross( i , j ) * vec[k] ;
|
Scalar res = cross( i , j ) * vec[k] ;
|
||||||
|
|
||||||
if (res==0) {
|
if (res*res<=EPSILON_SQUARED) {
|
||||||
// three coplanar vectors!
|
// three coplanar vectors!
|
||||||
res = uniqueVerse( cross(i,j) ) * cross(j,k) ;
|
// use derivative...
|
||||||
/*if (res==0) {
|
//res = uniqueVerse( cross(i,j) ) * cross(j,k) ;
|
||||||
printf("COLINEAR\n");
|
res = tripleProduct( altVec(i), vec[j], vec[k]) +
|
||||||
// three colinear vectors!
|
tripleProduct( vec[i], altVec(j), vec[k]) +
|
||||||
res = Vec3::dot( uniqueVerse(vec[i]) , vec[j])*
|
tripleProduct( vec[i], vec[j], altVec(k)) ;
|
||||||
Vec3::dot( uniqueVerse(vec[i]) , vec[k]);
|
if (res*res<=EPSILON_SQUARED) {
|
||||||
}*/
|
// zero derivative (happens, if three colinear vectors, or...)
|
||||||
|
res = tripleProduct( vec[i], altVec(j), altVec(k)) +
|
||||||
|
tripleProduct( altVec(i), vec[j], altVec(k)) +
|
||||||
|
tripleProduct( altVec(i), altVec(j), vec[k]) ;
|
||||||
|
}
|
||||||
|
if (res*res<=EPSILON_SQUARED) {
|
||||||
|
// zero second derivative (happens if three zero-vectors, i.e. never? or...)
|
||||||
|
res = tripleProduct( altVec(i), altVec(j), altVec(k) );
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
return ( (res>=0) != invert ); // XOR
|
return ( (res>=0) != invert ); // XOR
|
||||||
|
|
Loading…
Reference in New Issue