Free cookie consent management tool by TermsFeed Policy Generator

source: branches/HeuristicLab.Analysis.AlgorithmBehavior/HeuristicLab.Analysis.AlgorithmBehavior.Analyzers/3.3/DoubleArrayExtensions.cs @ 10663

Last change on this file since 10663 was 10274, checked in by ascheibe, 11 years ago

#1886 added calculation of the centroid of a convex hull and measures for motion characteristics

File size: 1.6 KB
Line 
1#region License Information
2/* HeuristicLab
3 * Copyright (C) 2002-2013 Heuristic and Evolutionary Algorithms Laboratory (HEAL)
4 *
5 * This file is part of HeuristicLab.
6 *
7 * HeuristicLab is free software: you can redistribute it and/or modify
8 * it under the terms of the GNU General Public License as published by
9 * the Free Software Foundation, either version 3 of the License, or
10 * (at your option) any later version.
11 *
12 * HeuristicLab is distributed in the hope that it will be useful,
13 * but WITHOUT ANY WARRANTY; without even the implied warranty of
14 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE.  See the
15 * GNU General Public License for more details.
16 *
17 * You should have received a copy of the GNU General Public License
18 * along with HeuristicLab. If not, see <http://www.gnu.org/licenses/>.
19 */
20#endregion
21
22using System;
23
24namespace HeuristicLab.Analysis.AlgorithmBehavior.Analyzers {
25  public static class DoubleArrayExtensions {
26    public static double EuclideanDistance(this double[] p1, double[] p2) {
27      double result = 0.0;
28      for (int i = 0; i < p1.Length; i++) {
29        result += Math.Pow(p1[i] - p2[i], 2);
30      }
31      return Math.Sqrt(result);
32    }
33
34    public static double EuclideanNorm(this double[] p) {
35      double norm = 0.0;
36      for (int i = 0; i < p.Length; i++) {
37        norm += p[i] * p[i];
38      }
39      return Math.Sqrt(norm);
40    }
41
42    public static double DotProduct(this double[] p1, double[] p2) {
43      double sum = 0.0;
44      for (int i = 0; i < p1.Length; i++) {
45        sum += p1[i] * p2[i];
46      }
47      return sum;
48    }
49  }
50}
Note: See TracBrowser for help on using the repository browser.