叉积
二维叉积
View Code
1 struct point{ 2 double x,y; 3 }; 4 double xmult( point a,point b,point c ){ 5 return ( b.x-a.x )*( c.y-a.y )-( b.y-a.y )*( c.x-a.x ); 6 }
c
|
|
a-- -- -- -- --b
由b转向a!!
三维叉积
设A(x1,y1,zi)、B(x2,y2,z2)、C(x3,y3,z3)为不共线三点,
向量AB={x2-x1,y2-y1,z2-z1}
向量AC={x3-x1,y3-y1,z3-z1}
由A、B、C三点确定的平面的法向量就是向量AB与向量AC的叉积
三个分量分别是下面的三个二阶行列式
y2-y1 z2-z1 z2-z1 x2-x1 x2-x1 y2-y1
y3-y1 z3-z1 z3-z1 x3-x1 x3-x1 y3-y1
View Code
1 struct point { 2 double x,y,z; 3 }; 4 point func( point a,point b,point c ){ 5 point one,two,ans; 6 one.x=b.x-a.x,one.y=b.y-a.y,one.z=b.z-a.z; 7 two.x=c.x-a.x,two.y=c.y-a.y,two.z=c.z-a.z; 8 ans.x = one.y*two.z - one.z*two.y; 9 ans.y = -one.x*two.z + one.z*two.x; 10 ans.z = one.x*two.y - one.y*two.x; 11 return ans; 12 }
keep moving...