Advertisement

3 plane intersection and cross product question

Started by November 26, 2017 08:45 PM
3 comments, last by haegarr 7 years, 2 months ago

Im doing GTK Radiant map importer, the file structure consists of some kind of surfaces that define a shape of object.

So far i extract all surfaces, now i need to check if they collide with each other so i can define points out of it, however even when i have these surfaces calculted along with normals and distances i get some errors like: no 3 plane intersection at all, this might be something with crossproduct, calculation of normal (normalized or not?), or even with the 3plane intersection algo itself so here is the code maybe someone will find a problem (maybe i use wrong order since they use different handsystem i may doing something wrong - thus i calculate surfaces in my coord system (i believe its lefthanded [anyway the other one that quake3 uses])

so that shouldnt matter for crossproduct function itself but im so confused that i cant find an error;

 


this is a function of a surface calculation just for your eyes, shouldnt matter

void calc_plane(t3dpoint<T> p0, t3dpoint<T> p1, t3dpoint<T> p2, bool normalized)
{
	n = Normal(p0,p1,p2, !normalized);
//if (!normalized) n = Normalize(Norm);   else  n = Norm;

x = (T)p0.x;
y = (T)p0.y;
z = (T)p0.z;

A = (T)n.x;
B = (T)n.y;
C = (T)n.z;

D = -(A*x + B*y + C*z);


}



int  ClassifyPoint(t3dpoint<T> point)
{
T costam = dotproduct(point,n)+T(D);

if (costam > 0) return isFront;
if (costam < 0) return isBack;
if (betweenorequal(T(-SPECIAL_FEATURE),T(SPECIAL_FEATURE),costam) == true) return isOnPlane;

}



//--------------------------
now the code that matters
  
  
template <class type> t3dpoint<type>  vectorcross(t3dpoint<type> v1,t3dpoint<type>  v2)
{
t3dpoint<type>  crossproduct;

crossproduct.x  = (v1.y*v2.z)-(v1.z*v2.y);
crossproduct.y  = (v1.z*v2.x)-(v1.x*v2.z);
crossproduct.z  = (v1.x*v2.y)-(v1.y*v2.x);
return crossproduct;
}








original function
  
  
  bool GetIntersection ( n1, n2, n3, d1, d2, d3, &p )
{
double denom = n1.Dot ( n2.Cross ( n3 ) );
if ( denom == 0 )
{
return false;
}
p = -d1 * ( n2.Cross ( n3 ) ) – d2 * ( n3.Cross ( n1 ) ) – d3 * ( n1.Cross ( n2 ) ) / denom;
return true;
}

now mine





template <class T> bool Get3PlaneIntersection(t3dpoint<T> n1, t3dpoint<T> n2, t3dpoint<T> n3,
		T d1, T d2, T d3, t3dpoint<T> &p )
{
double denom = Dot(n1, vectorcross(n2, n3) );
if (betweenorequal(-epsilona,epsilon, denom)) return false; //check if denominator is equal or very close to 0
t3dpoint<T> tmp = vectorcross(n2, n3) * -d1;
t3dpoint<T> tmp2 = vectorcross(n3, n1) * -d2;
t3dpoint<T> tmp3 = vectorcross(n1, n2) * -d3;
p = (tmp+tmp2+tmp3) / denom;
return true;
}





---------------------
  
  

maybe someone sees difference between my function and that original one

Have you solved it already?

I just derived the plane intersection math myself and I see nothing wrong with your code except that the original GetIntersection function only divides cross(n1, n2) by denom, which is incorrect and probably a typo?

So I think your bug(s) is/are located elsewhere.

Advertisement

Paper that describes how to load map, doesnt show you how exactly you need to count through all 3 planes, that was the problem

Within ClassifyPoint(): Using an interval check for a float does not make any sense after exact checks have already been performed. So move the line with "betweenorequal" to be the first check in the containing routine.

Within Get3PlaneIntersection: Why is there an -epsilona (notice the trailing "a") used besides a +epsilon? Is the interval asymmetric due to some reason? That seems me spurious.

There is a difference between the original and your implementation in that the original does not scale the sum of the three cross products (like yours) but just the term with d3. However, that may also be a typo in the OP... as d956 already mentioned.

BTW: It is a bit confusing that t3dpoint (with that "point" in the name) is used as position vectors as well as direction vectors. Would be better to name it t3dvector instead.

This topic is closed to new replies.

Advertisement