C++-ベクトルの点乗、フォーク乗などの操作

959 ワード

総括する
ベクトルの点乗、フォーク乗などの操作.
コード#コード#


double ThreeDot(Point p,Point a,Point b){
    return(a[0]-p[0])*(b[0]-p[0])+(a[1]-p[1])*(b[1]-p[1])+(a[2]-p[2])*(b[2]-p[2]);
}//pa pb    (3 )   

Point ThreeCross(Point p,Point a,Point b){
    double x,y,z;
    x=(a[1]-p[1])*(b[2]-p[2])-(a[2]-p[2])*(b[1]-p[1]);
    y=(a[2]-p[2])*(b[0]-p[0])-(a[0]-p[0])*(b[2]-p[2]);
    z=(a[0]-p[0])*(b[1]-p[1])-(a[1]-p[1])*(b[0]-p[0]);
    Point C(x,y,z);
    return C;
}//pa pb   (3 )

double ThreeDot(Point a,Point b){
    return a[0]*b[0]+a[1]*b[1]+a[2]*b[2];
}//  a b    (  )

Point ThreeCross(Point a,Point b){

    int C[3];
    C[0]=a[1]*b[2]-a[2]*b[1];
    C[1]=a[2]*b[0]-a[0]*b[2];
    C[2]=a[0]*b[1]-a[1]*b[0];
    Point nC(C[0],C[1],C[2]);
    return nC;
}//  a b   (  )
double TetrahedronArea(Point a,Point b,Point c,Point d) {

    Point temp(d[0] - a[0], d[1] - a[1], d[2] - a[2]);
    return abs(ThreeDot(ThreeCross(a, b, c), temp)) / 6;
}