public double TabelaNormal(double porcentagem)
        {
            porcentagem /= 2;
            if (TabelaNormalData.ContainsKey(porcentagem))
            {
                return(TabelaNormalData[porcentagem]);
            }

            // Calculando o mais proximo
            var menorTstudent = new TNormal(TabelaNormalData.AsEnumerable().First(), porcentagem);

            foreach (var(key, value) in TabelaNormalData.AsEnumerable())
            {
                var testeMenor = Math.Abs(key - porcentagem);

                // Compliquei aqui....
                if (testeMenor < menorTstudent.Diferenca)
                {
                    menorTstudent.Diferenca = testeMenor;
                    menorTstudent.Key       = key;
                    menorTstudent.Value     = value;
                }
            }

            return(menorTstudent.Value);
        }
Пример #2
0
        //{------------------------------------------------------------------}
        //{  Function to normalize a vector                                  }
        //{------------------------------------------------------------------}
        internal void Normalize(ref TNormal vector)
        {
            // Calculates The Length Of The Vector
            float length = (float)Math.Sqrt((vector.X * vector.X) + (vector.Y * vector.Y) + (vector.Z * vector.Z));

            if (length == 0)
            {
                length = 1;
            }

            vector.X = vector.X / length;
            vector.Y = vector.Y / length;
            vector.Z = vector.Z / length;
        }
Пример #3
0
        //{------------------------------------------------------------------}
        //{  Function to calculate the normal given 2 vectors (3 vertices)   }
        //{------------------------------------------------------------------}
        internal TNormal calcNormal(TVertex[] v)
        {
            TVertex a      = new TVertex();
            TVertex b      = new TVertex();
            TNormal result = new TNormal();

            // Calculate The Vector From Point 1 To Point 0
            a.X = v[0].X - v[1].X;
            a.Y = v[0].Y - v[1].Y;
            a.Z = v[0].Z - v[1].Z;
            // Calculate The Vector From Point 2 To Point 1
            b.X = v[1].X - v[2].X;
            b.Y = v[1].Y - v[2].Y;
            b.Z = v[1].Z - v[2].Z;
            // Compute The Cross Product To Give Us A Surface Normal
            result.X = a.Y * b.Z - a.Z * b.Y;        // Cross Product For Y - Z
            result.Y = a.Z * b.X - a.X * b.Z;        // Cross Product For Z - X
            result.Z = a.X * b.Y - a.Y * b.X;        // Cross Product For X - Y

            Normalize(ref result);                   // Normalize The Vectors
            return(result);
        }