Esempio n. 1
0
        public static float AngleBetweenVectors(Single3 p1, Single3 p2)
        {
            double l1 = p1.Length();
            double l2 = p2.Length();

            if ((l1 == 0) || (l2 == 0))
            {
                throw new Exception("Angle between vectors is not defined if length of the vector(s) is zero");
            }
            double cs = (p1 * p2) / (l1 * l2);
            double ad;

            if (Abs(cs) < 1d)
            {
                ad = Acos(cs).ToDegrees();
            }
            else
            {
                ad = (cs > 0) ? 0d : 180d;
            }
            return((float)ad);
        }
Esempio n. 2
0
        public static bool IsUnitVector(Single3 p)
        {
            const double Tiny = 0.000001f;

            return(Abs(p.Length() - 1f) < Tiny);
        }