日期:2014-05-18 浏览次数:22431 次
Vector3D vector1 = new Vector3D(20, 30, 40);//向量1=(20,30,40) Vector3D vector2 = new Vector3D(45, 70, 80);//向量2=(45,70,80) Vector3D crossProduct = new Vector3D();//叉积结果 crossProduct = Vector3D.CrossProduct(vector1,vector2);//计算向量1×向量2
------解决方案--------------------
用运算符重载:
public class Vector3D { public double x{get;set;} public double y{get;set;} public double z{get;set;} } public Vector3D operator * (Vector3D lhs,Vector3D rhs) { Vector3D reVector3D = new Vector3D(); reVector3D.x=lhs.x*rhs.x; reVector3D.y=lhs.y*rhs.y; reVector3D.z=lhs.z*rhs.z; return reVector3D; } //调用时: Vector3D vector1 = new Vector3D(20, 30, 40);//向量1=(20,30,40) Vector3D vector2 = new Vector3D(45, 70, 80);//向量2=(45,70,80) Vector3D crossProduct = new Vector3D();//叉积结果 crossProduct=vector1*vector2;
------解决方案--------------------
向量,在3D处理中经常使用,一般用float[]或者double[]表示,
------解决方案--------------------
C#提供了复数及其运算,向量可以表示成复数形式。