Esempio n. 1
0
        /// <summary>
        /// Normalizes a homogenous vector to unit length
        /// </summary>
        public static Vec4 Normalize(Vec4 vec)
        {
            vec = NormW(vec);
            double l = Math.Sqrt(vec.X * vec.X + vec.Y * vec.Y + vec.Z * vec.Z);

            if (l > 0)
            {
                l = 1 / l;
                return(new Vec4(vec.X * l, vec.Y * l, vec.Z * l, 1));
            }
            return(new Vec4(0, 0, 0, vec.W));
        }
Esempio n. 2
0
 public static Vec3 FromHomo(Vec4 h)
 {
     return(new Vec3(h.X / h.W, h.Y / h.W, h.Z / h.W));
 }