a向量正交投影到b

来源:互联网 发布:中国网络书画论坛 编辑:程序博客网 时间:2024/05/14 10:37

1.连个向量 点 乘

//两个向量点乘static double Dot(const double a[3],const double b[3]){    return (a[0]*b[0] + a[1]*b[1] + a[2]*b[2]);}

2.两个向量 x 乘

//向量x乘void CrossVector(const double a[3],const double b[3],double normal[3]){    normal[0] = a[1] * b[2] - a[2] * b[1];    normal[1] = a[2] * b[0] - a[0] * b[2];    normal[2] = a[0] * b[1] - a[1] * b[0];}

3.对一个数值与一个向量相乘

//对一个向量进行乘积static void MultiplyVector(double a[3],double scalar){    for(unsigned int i=0; i<3; i++){        a[i] *= scalar;    }}

4.a向量正交投影到b

//a向量正交投影到bbool VectorProjection(const double a[3],const double b[3],double a1[3]){    double bSq = Dot(b,b);    //判断b是否为0    if(0 == bSq){        a1[0] = 0;        a1[1] = 0;        a1[2] = 0;        return false;    }    float ratio = Dot(a,b)/bSq;    for(unsigned int i=0; i<3; i++){        a1[i] = b[i];    }    MultiplyVector(a1,ratio);    return true;}

向量投影详细解读https://www.cnblogs.com/graphics/archive/2010/08/03/1791626.html