Beispiel #1
0
        /// <summary>
        /// Normalize the given vector using the L2 norm.
        /// </summary>
        public static double Normalize <T>(IVector a, ref T dest) where T : IVector
        {
            double len = VectorReductions.L2Norm(a);

            if (FloatComparison.CloseZero(len, FloatComparison.DefaultEps))
            {
                throw new DivideByZeroException();
            }
            double inv_len = 1.0 / len;

            for (int i = 0; i < a.Dimensions; ++i)
            {
                dest[i] = a[i] * inv_len;
            }
            return(len);
        }
Beispiel #2
0
        /// <summary>
        /// Test if vector is inside of ball.
        /// </summary>
        public bool Inside(IVector x)
        {
            Vector v = _center - x;

            return(VectorReductions.SquaredL2Norm(v) <= this.SquaredRadius);
        }