double angle4h(double v0[], double v1[]){ double cos_theta = (dot4h(v0, v1)) / (length4h(v0)*length4h(v1)); double theta; // theta = acos(cos_theta) * 180 / M_PI; theta = acos(cos_theta); #ifdef DEBUG printf("角度: %lf\n", theta); #endif return theta; }
// ベクトル間の角度 double angle4h(double v0[], double v1[]) { double cos_theta = 0; double length_0 = length4h(v0); double length_1 = length4h(v1); if (length_0 != 0.0 && length_1 != 0.0) { cos_theta = dot4h(v0, v1) / (length_0 * length_1); return acos(cos_theta); } else { return 0; } }
bool normalize4h(double u[], double v[]){ double norm_v = length4h(v); if (norm_v == 0){ printf("ベクトルの大きさが0です。\n"); return false; } else{ for (int i = 0; i < VEC_SIZE - 1; ++i){ u[i] = v[i] / norm_v; } u[VEC_SIZE - 1] = 1; return true; } }
// 単位ベクトル int normalize4h(double u[], double v[]) { double length = length4h(v); if (length == 0.0){ return 0; } else{ for (int i = 0; i < VECTOR_LEN; i++) { u[i] = v[i] / length; } //u[VECTOR_LEN - 1] = 0; } return 1; }