A Funny C++ Bug
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){ //cout << "x=" << x << " y=" << y << endl; Here is the driven code: Code:
ML_Vertex A(1,0,0), n1(0,1,0); The problem is: when I comment the line " cout << "x=" << x << " y=" << y << endl;" out, the result is: 0 0 0 4.94321e37 1 8.38816e38 which is wrong. But if I leave the line uncommented, the result is : x=0 y=0 0 0 0 1 1.52385e314 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 
Not an answer to your question, but (if the code you presented is the code you actually use) the denominator in your equation for y appears to be incorrect.
Also, when you calculate the cross product, you seem to be using GetNormal both as a function in the "plane" class and as a standalone function. Is it really defined that way? 
Quote:
Thanks for your reply. The denominator for y is a typing error, and it's not the problem. The GetNormal() is a function in the ML_Plane Class, and it can be considered as: Cross(this>GetNormal(), plane.GetNormal() ); Note that the signature of the function is : bool ML_Plane::IntersectionPlane(ML_Plane& plane, ML_Line& line); I have tried many different ways but the problem is still there. Could this be the problem of the compiler's optimization problem? 
is p0 set up?

Also what does GetNormal() return?
a1 = GetNormal()[0]; an array? GetNormal() * (*p0); a scalar? 
Quote:

All times are GMT 5. The time now is 07:11 PM. 