提示コードのfloat t1;変数ですがなぜ-0とprintf();されるのでしょうか?if文で0と比較しましたが同じようです。printf();で両方の値を出力してしましたが 0 と マイナスの値のため 0 / - 3; など実証してしましたが値は0になっています。 0 と-0の違いはどのようになっているのでしょうか?
※この関数は直線と直線の最短距離を求める。関数ですが未完成のためreturn する値等は無価値です。
/*Vector はfloat型変数が3つあるだけ*/ float LineLine_range(Vector line_a[2],Vector line_b[2]) { Vector L1 = line_a[1]; Vector L2 = line_b[1]; //print_vec(L1); //print_vec(L2); float a = (Vector::dot(L1, line_a[0]) - Vector::dot(L1, line_b[0])); float b = (-Vector::dot(L1, L2) - Vector::dot(L1, L1)); printf("A: %.2f\n", a); printf("B: %.2f\n",b); float t1 = a / b; //float t1 = (Vector::dot(L1,line_a[0]) - Vector::dot(L1,line_b[0])) / (-Vector::dot(L1,L2) - Vector::dot(L1, L1)); printf("自作 t1: %.2f\n",t1); if( t1 == 0.0f) { printf("aaaa\n"); } Vector p1 = line_a[0] + Vector::mul_scalar(t1 , L1); float t2 = (Vector::dot(L1,p1) - Vector::dot(L2,line_b[0])) / Vector::dot(L2,L2); Vector p2 = line_b[0] + Vector::mul_scalar(t2, L2); // p1.printf_vec(); float f = (p2 - p1).Length(); return f; }
回答2件
あなたの回答
tips
プレビュー
バッドをするには、ログインかつ
こちらの条件を満たす必要があります。