i want to compute intersection line, given by 2 planes. my main program gives me, plane parameters a,b,-1,d (my equation is ax+by-z+d=0). so, my function for computing equation of intersection line is as;
vector<double> LineofIntersection(vector<double> plane1,vector<double> plane2) {
double a1=plane1.at(0); double a2=plane2.at(0);
double b1=plane1.at(1); double b2=plane2.at(1);
double d1=plane1.at(2); double d2=plane2.at(2);
int c1=-1,c2=-1;
double cros_x=fabs((b1*c2)-(b2*c1));
double cros_y=fabs((a2*c1)-(a1*c2));
double cros_z=fabs((a1*b2)-(a2*b1));
vector <double> point; vector <double> pointout;
int maxc; // max coordinate
if (cros_x > cros_y){
if (cros_x > cros_z)
maxc = 1;
else maxc = 3;
}
else {
if (cros_y > cros_z)
maxc = 2;
else maxc = 3;
}
//
vector <double> point; vector <double> pointout;
switch (maxc) { // select max coordinate
case 1: // intersect with x=0
point.at(0)=0;
point.at(1)=(d2-d1)/(b2-b1);
point.at(2)=(b1*d2-2*b1*d1+d1*b2)/(b2-b1);
break;
case 2: // intersect with y=0
point.at(0)=(d2-d1)/(a1-a2);
point.at(1)=0;
point.at(2)=(a1*d2-a2*d1)/(a1-a2);
break;
case 3: // intersect with z=0
point.at(0)=(b1*d2-b2*d1)/(a1*b2-a2*b1);
point.at(1)=(a2*d1-a1*d2)/(a1*b2-a2*b1);
point.at(2)=0;
break;
}
pointout.push_back(point.at(0));
pointout.push_back(point.at(1));
pointout.push_back(point.at(2));
return pointout;
}
in the main program, i call this function as:
vector<double> linep=LineofIntersection(plane1,plane2);
cout<<linep.at(1)<<" "<<linep.at(1)<<" "<<linep.at(2);
but, i got error message and cannot run the program. any help please.
Fundementally, your problem is that you are assigning to locations in the
pointvector without first allocating them. Additionally,pointoutserves no purpose, and you have a syntax error. Here are my recommendations:This line appears twice. Delete the line the first time it appears, and replace the second instance with:
Notice the
(3). Without it,pointis an empty vector, i.e. it has no doubles in it at all. With it, it has 3 doubles.The
pointoutobject serves no purpose. Replace these two lines:with this line: