Hi all:
I wrote a piece of code for calculating the intersection between two planes. Here are my code:
Code:
bool ML_Plane::IntersectionPlane(ML_Plane& plane, ML_Line& line){
if ( Parallel(plane) ) return false;
double a1, b1, c1, d1;
double a2, b2, c2, d2;
a1 = GetNormal()[0]; b1 = GetNormal()[1]; c1 = GetNormal()[2];
d1 = GetNormal() * (*p0);
a2 = plane.GetNormal()[0]; b2 = plane.GetNormal()[1]; c2 = plane.GetNormal()[2];
d2 = plane.GetNormal() * plane[0];
double x=0;
double y=0;
if ( abs(a1*b2-a2*b1) > EPSILON){
x = (b1*d2-b2*d1)/(a1*b2-a2*b1);
y = (a2*d1-a1*d2)/(a1*b2*a2*b1);
}
//cout << "x=" << x << " y=" << y << endl;
ML_Vertex O(x,y,0);
ML_Vertex P = O + Cross(GetNormal(), plane.GetNormal() );
line = ML_Line(O,P);
return true;
}
Note that there is a line I comment out
//cout << "x=" << x << " y=" << y << endl;
Here is the driven code:
Code:
ML_Vertex A(1,0,0), n1(0,1,0);
ML_Vertex n2(0,0,1);
ML_Plane p1(A, n1), p2(A, n2);
ML_Line line;
p1.IntersectionPlane(p2, line);
cout << line[0] << endl;
cout << line.GetNormal() << endl;
line[0] is a point on the line basically. This calculates the intersection between X plane and Y Plane.
The problem is:
when I comment the line " cout << "x=" << x << " y=" << y << endl;" out, the result is:
0 0 0
-4.94321e-37 -1 8.38816e-38
which is wrong.
But if I leave the line uncommented, the result is :
x=0 y=0
0 0 0
1 -1.52385e-314 0
which is correct, the intersection line normal direction is X axis.
Can anyone tell me how to solve the problem please?
My compiler is GNU C++ 4.1.2
Thanks