Normalize Bug
Status: Inactive
Brought to you by:
vijeth_d
- The function Helper.Normalize(double[] vector, double magnitude) returns wrong values for any magnitude values other than 1.0
- For example Helper.Normalize(new double[] { 5.0 , 6.0 } ,10.0 ) returns { 2.0244 , 2.4293 } instead of { 6.4018, 7.6822 }
- The reason for this bug is obvious; the code calculates the factor with square root of magnitude instead of magnitude itself...
factor = Math.Sqrt(magnitude / factor);
- The suggested fix is:
factor = Math.Abs(magnitude) / Math.Sqrt( factor);
- Attached is the Helper.cs file with the suggested fix
Helper.cs file with the suggested fix for normalize bug