public static TokenMarker[] MeanSquareOrthogonalReferenceSystem(TokenMarker originalOrigin, TokenMarker originalXAxis, TokenMarker originalYAxis, float tokenSize) { TokenMarker[] result = new TokenMarker[3]; var M= Matrix<float>.Build; float[,] arrayA = { { 0.0f, 0.0f, 1.0f, 0.0f }, { 0.0f, 0.0f, 0.0f, 1.0f }, { tokenSize, 0.0f, 1.0f, 0.0f }, { 0.0f, tokenSize, 0.0f, 1.0f }, { 0.0f, -tokenSize, 1.0f, 0.0f}, { tokenSize, 0.0f, 0.0f, 1.0f } }; float[,] arrayB = { { originalOrigin.Position.x }, { originalOrigin.Position.y }, { originalXAxis.Position.x }, { originalXAxis.Position.y }, { originalYAxis.Position.x }, { originalYAxis.Position.y} }; var A = M.DenseOfArray(arrayA); var b = M.DenseOfArray(arrayB); var x = A.TransposeThisAndMultiply(A).Inverse() * A.TransposeThisAndMultiply(b); float[,] transformationMatrix = x.ToArray(); Vector2 newOrigin = new Vector2( transformationMatrix[2, 0], transformationMatrix[3, 0]); Vector2 newXAxis = new Vector2( tokenSize * transformationMatrix[0,0] + transformationMatrix[2,0], tokenSize * transformationMatrix[1,0] + transformationMatrix[3,0]); Vector2 newYAxis = new Vector2(-tokenSize * transformationMatrix[1, 0] + transformationMatrix[2, 0], tokenSize * transformationMatrix[0, 0] + transformationMatrix[3, 0]); result[0] = new TokenMarker(originalOrigin.Id, newOrigin, originalOrigin.State, MarkerType.Origin); result[1] = new TokenMarker(originalXAxis.Id, newXAxis, originalXAxis.State, MarkerType.XAxis); result[2] = new TokenMarker(originalYAxis.Id, newYAxis, originalYAxis.State, MarkerType.YAxis); return result; }
public static Dictionary<int,TokenMarker> ConvertTouchInputToMarkers(int[] orderedIndexes, Dictionary<int,TouchInput> clusterPoints) { Dictionary<int, TokenMarker> result = new Dictionary<int, TokenMarker>(); for (int i = 0; i < orderedIndexes.Length; i++) { TouchInput ti = clusterPoints[orderedIndexes[i]]; switch (i) { case 0: { TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.Origin); result.Add(tm.Id, tm); break; } case 1: { TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.XAxis); result.Add(tm.Id, tm); break; } case 2: { TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.YAxis); result.Add(tm.Id, tm); break; } case 3: { TokenMarker tm = new TokenMarker(ti.Id, ti.Position, ti.State, MarkerType.Data); result.Add(tm.Id, tm); break; } } } return result; }
public void SetMeanSquareReferenceSystem(TokenMarker[] referenceSystem) { this.meanSquaredTokenReferenceSystem = referenceSystem; Vector3[] meanSquaredAxis = CalculateAxis(this.meanSquaredTokenReferenceSystem[1].Position, this.meanSquaredTokenReferenceSystem[2].Position, this.meanSquaredTokenReferenceSystem[0].Position); this.meanSquaredTokenAngle = CalculateAngle(meanSquaredAxis[0]); }