quote:以下是引用开不了口在2013-03-28 10:07:11的发言:
平面一般方程为ax+by+cz+d=0,求出a,b,c,d即可
别人博客的文章,是用C++求的
http://blog.csdn.net/hoya5121/article/details/1484365
//已知3点,求平面方程
BOOL CGe::PanelEquationFromThreePt(CPoint3dArray ptArr,
double &a,double &b,double &c,double &d)
{//from http://blog.csdn.net/hoya5121
CPoint3d p1,p2,p3;
if(ptArr.GetSize() < 3)
{
return FALSE;
}
p1 = ptArr[0];
p2 = ptArr[1];
p3 = ptArr[2];
a = ( (p2.y-p1.y)*(p3.z-p1.z)-(p2.z-p1.z)*(p3.y-p1.y) );
b = ( (p2.z-p1.z)*(p3.x-p1.x)-(p2.x-p1.x)*(p3.z-p1.z) );
c = ( (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x) );
d = ( 0-(a*p1.x+b*p1.y+c*p1.z) );
return TRUE;
}
这个方程应该适用于三点确定的一个无限平面吧!
用这个方法做了个子程序,供大家参考指点:
源文件,编译后使用。
FUNCTION FC 35 : VOID
TITLE =
VERSION : 0.1
VAR_INPUT
x1 : REAL ;
y1 : REAL ;
z1 : REAL ;
x2 : REAL ;
y2 : REAL ;
z2 : REAL ;
x3 : REAL ;
y3 : REAL ;
z3 : REAL ;
y4 : REAL ;
z4 : REAL ;
END_VAR
VAR_OUTPUT
x4 : REAL ;
END_VAR
VAR_TEMP
temp1 : REAL ;
temp2 : REAL ;
temp3 : REAL ;
temp4 : REAL ;
a : REAL ;
b : REAL ;
c : REAL ;
d : REAL ;
END_VAR
BEGIN
NETWORK
TITLE =
//平面一般方程为ax+by+cz+d=0,求出a,b,c,d即可
// a = ( (p2.y-p1.y)*(p3.z-p1.z)-(p2.z-p1.z)*(p3.y-p1.y) );
//
//
L #y2;
L #y1;
-R ;
T #temp1;
L #z3;
L #z1;
-R ;
T #temp2;
L #z2;
L #z1;
-R ;
T #temp3;
L #y3;
L #y1;
-R ;
T #temp4;
L #temp1;
L #temp2;
*R ;
T #temp2;
L #temp3;
L #temp4;
*R ;
T #temp4;
L #temp2;
L #temp4;
-R ;
T #a;
NETWORK
TITLE =
// b = ( (p2.z-p1.z)*(p3.x-p1.x)-(p2.x-p1.x)*(p3.z-p1.z) );
//
L #z2;
L #z1;
-R ;
T #temp1;
L #x3;
L #x1;
-R ;
T #temp2;
L #x2;
L #x1;
-R ;
T #temp3;
L #z3;
L #z1;
-R ;
T #temp4;
L #temp1;
L #temp2;
*R ;
T #temp2;
L #temp3;
L #temp4;
*R ;
T #temp4;
L #temp2;
L #temp4;
-R ;
T #b;
NETWORK
TITLE =
// c = ( (p2.x-p1.x)*(p3.y-p1.y)-(p2.y-p1.y)*(p3.x-p1.x) );
//
L #x2;
L #x1;
-R ;
T #temp1;
L #y3;
L #y1;
-R ;
T #temp2;
L #y2;
L #y1;
-R ;
T #temp3;
L #x3;
L #x1;
-R ;
T #temp4;
L #temp1;
L #temp2;
*R ;
T #temp2;
L #temp3;
L #temp4;
*R ;
T #temp4;
L #temp2;
L #temp4;
-R ;
T #c;
NETWORK
TITLE =
//d = ( 0-(a*p1.x+b*p1.y+c*p1.z) );
L #a;
L #x1;
*R ;
T #temp1;
L #y1;
L #b;
*R ;
T #temp2;
L #c;
L #z1;
*R ;
L #temp3;
L 0.000000e+000;
L #temp1;
-R ;
L #temp2;
-R ;
L #temp3;
-R ;
T #d;
NETWORK
TITLE =
//ax+by+cz+d=0:ax=0-by-cz-d:x=(0-by-cz-d)/a
L #b;
L #y4;
*R ;
T #temp1;
L #c;
L #z4;
*R ;
T #temp2;
L 0.000000e+000;
L #temp1;
-R ;
L #temp2;
-R ;
L #d;
-R ;
L #a;
/R ;
T #x4;
END_FUNCTION