AR + GPS Location  3.0.0
All Classes Namespaces Functions Variables Properties Events Pages
MovingAveragePosition.cs
1 // ReSharper disable ParameterHidesMember
2 namespace ARLocation.Utils
3 {
4  public class MovingAveragePosition
5  {
6  public DVector3 CalculateAveragePosition()
7  {
8  return mPosition;
9  }
10 
11  public double aMin = 2.0;
12  public double aMax = 10.0;
13  public double cutoff = 0.01;
14  public double alpha = 0.25;
15 
16  private DVector3 mPosition;
17  private bool first = true;
18 
19  private double Weight(double a, double aMin, double aMax, double cutoff = 0.01)
20  {
21  if (a <= aMin)
22  {
23  return 1.0;
24  }
25 
26  if (a >= aMax)
27  {
28  return 0.0;
29  }
30 
31  var lambda = System.Math.Log(1 / cutoff) / (aMax - aMin);
32 
33  return System.Math.Exp(-lambda * (a - aMin));
34  }
35 
36  public void AddEntry(DVector3 position, double accuracy)
37  {
38  if (first)
39  {
40  mPosition = position;
41  first = false;
42  }
43  else
44  {
45  var b = Weight(accuracy, aMin, aMax, cutoff);
46  var a = alpha * b;
47 
48  mPosition = a * position + (1 - a) * mPosition;
49  }
50  }
51 
52  public void Rest()
53  {
54  first = true;
55  mPosition = new DVector3();
56  }
57  }
58 }
ARLocation.Utils.MovingAveragePosition
Definition: MovingAveragePosition.cs:5
ARLocation.DVector3
Definition: DVector3.cs:9
ARLocation.Utils
Definition: CreatePointOfInterestTextMeshes.cs:9