我想计算由2个平面给出的交线。我的主程序给出了平面参数a,b,-1,d(我的方程是ax + by-z + d = 0)。所以,我计算交线方程的函数为;交叉线:矢量函数中的误差
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;
}
在主程序中,我调用这个函数为:
vector<double> linep=LineofIntersection(plane1,plane2);
cout<<linep.at(1)<<" "<<linep.at(1)<<" "<<linep.at(2);
但是,我得到错误信息而无法运行该程序。请任何帮助。
你得到什么错误讯息? – 2011-04-06 14:30:53
@ oli =>此应用程序已请求运行时以不寻常的方式终止它。 有关更多信息,请联系应用程序的支持团队。 – niro 2011-04-06 14:33:07
看起来你没有正确初始化plane1和plane2 - 你怎么设置它们? – ltjax 2011-04-06 14:36:14