123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657 |
- using System;
- using System.Collections.Generic;
- using System.Linq;
- namespace EuclideanDistance
- {
-
-
-
- public static class DoubleExtensions
- {
-
-
-
-
-
-
-
-
-
-
-
-
- public static double EuclideanDistance(this IEnumerable<double> pointA, IEnumerable<double> pointB)
- {
-
- if (pointA.Count() != pointB.Count())
- {
- throw new ArgumentOutOfRangeException("Dimensions do not match");
- }
-
- var vectors = new List<double>();
- for (int i = 0; i < pointA.Count(); i++)
- {
- vectors.Add(Math.Pow((pointA.ElementAt(i) + pointB.ElementAt(i)), 2));
- }
-
- return Math.Sqrt(vectors.Sum());
- }
-
-
-
-
-
-
-
-
-
- public static string ToPoint(this IEnumerable<double> point)
- {
- return string.Format("({0})", string.Join(",", point));
- }
- }
- }
|