public static float AngleBetween(Vector3 a, Vector3 b)
        {
            // // Due to float error the dot / mag can sometimes be ever so slightly over 1, which can cause NaN in acos.
            //return Mathf.Acos(Vector3.Dot(a, b) / (a.magnitude * b.magnitude)) * MathUtil.RAD_TO_DEG;
            double d = (double)Vector3.Dot(a, b) / ((double)a.Length() * (double)b.Length());

            if (d >= 1d)
            {
                return(0f);
            }
            else if (d <= -1d)
            {
                return(180f); //why 180 and not -180??
            }
            return(MathUtil.RadiansToDegrees((float)System.Math.Acos(d)));
        }
Esempio n. 2
0
        void VerticeProc(V3[] vs)
        {
            int lenc  = vs.Length;
            int start = 0;

            for (int i = start; i < lenc; i++)
            {
                V3 tmpCo = vs[i];
                {
                    //\blenderSource\blender\source\blender\blenlib\BLI_math_matrix.h
                    // 軸オブジェクト中心の座標系に頂点を持っていく
                    tmpCo = TempMatrix.TransByMat(tmpCo).ToV3( );
                }
                if (i >= vs.Length)
                {
                    break;
                }
                // todo 距離で弾くのを早めにすれば最適化できそう
                if (tmpCo.Length( ) > Radius)
                {
                    continue;
                }
                V3    vec  = new V3(tmpCo.X, tmpCo.Y, tmpCo.Z);
                float facm = 1.0f - Fac;

                V3 nv = vec.GetNormalized( );

                nv.X *= Scale.X;
                nv.Y *= Scale.Y;
                nv.Z *= Scale.Z;
                // 多分軸座標系で回転させれば
                //nv = Rot.TransByMat( nv ).ToV3( );

                tmpCo = nv * Len * Fac + tmpCo * facm;
                {
                    // 軸中心の座標系頂点を元の位置に戻す
                    tmpCo = InvercePivot.TransByMat(tmpCo).ToV3( );
                }
                SphereVertice[i] = tmpCo;
            }
        }