public Transformation(DWMatrix initialPlane, DWMatrix newPlane, DWMatrix inverseMatrix, double degrees) { InitialPlane = initialPlane; NewPlane = newPlane; InverseMatrix = inverseMatrix; Degrees = degrees; }
/// <summary> /// Animates the inversion of a transformation /// </summary> /// <param name="initMatrix"></param> /// <param name="transformedMatrix"></param> /// <param name="inverseMatrix"></param> public void AnimateInversion(DWMatrix initMatrix, DWMatrix transformedMatrix) { if (!Animation.AnimationEnabled) { IHat.X = initMatrix.IX; IHat.Y = initMatrix.IY; JHat.X = initMatrix.JX; JHat.Y = initMatrix.JY; UpdateVectorLines(); } else { DWMatrix stepMatrix = (initMatrix - transformedMatrix) / (Animation.GetFactoredSpeed()); Task.Run(() => Application.Current.Dispatcher.Invoke(() => { for (int i = 0; i < (Animation.GetFactoredSpeed()); i++) { DWMatrix newPlane = transformedMatrix + stepMatrix; IHat.X = newPlane.IX; IHat.Y = newPlane.IY; JHat.X = newPlane.JX; JHat.Y = newPlane.JY; UpdateVectorLines(); Application.Current.Dispatcher.Invoke(delegate { }, System.Windows.Threading.DispatcherPriority.Render); Thread.Sleep(1); transformedMatrix = newPlane; } })); } }
// TRANSFORMATION METHODS /// <summary> /// Animates the linear transformation if animations enabled /// </summary> /// <param name="currentMatrix"></param> /// <param name="targetMatrix"></param> /// <param name="stepMatrix"></param> public void AnimateTransformation(DWMatrix currentMatrix, DWMatrix targetMatrix) { DWMatrix transformedTarget = VectorMath.MakeLinearTransformation(currentMatrix, targetMatrix); Animation.TransformationsList.Add( new Transformation(currentMatrix, transformedTarget, VectorMath.GetInverseMatrix(targetMatrix), 0) ); if (!Animation.AnimationEnabled) { TransformPlane(transformedTarget); } else { DWMatrix stepMatrix = (transformedTarget - currentMatrix) / (Animation.GetFactoredSpeed()); Task.Run(() => Application.Current.Dispatcher.Invoke(() => { for (int i = 0; i < (Animation.GetFactoredSpeed()); i++) { DWMatrix newPlane = currentMatrix + stepMatrix; IHat.X = newPlane.IX; IHat.Y = newPlane.IY; JHat.X = newPlane.JX; JHat.Y = newPlane.JY; UpdateVectorLines(); Application.Current.Dispatcher.Invoke(delegate { }, System.Windows.Threading.DispatcherPriority.Render); Thread.Sleep(1); currentMatrix = newPlane; } })); } }
/// <summary> /// Animates the rotation based on the animation speed /// </summary> /// <param name="degree"></param> public void AnimateRotation(double degree, bool undo = false) { DWMatrix currentMatrix = new DWMatrix(IHat.X, IHat.Y, JHat.X, JHat.Y); DWMatrix targetMatrix = VectorMath.RotateNRadiansAntiClockwise(new DWMatrix(IHat, JHat), ((degree * Math.PI) / 180)); // jump to full rotation if animation is off if (!Animation.AnimationEnabled) { RotateNDegreesAntiClockwise(degree); } else { // rotates a part of the way and then re-renders Task.Run(() => Application.Current.Dispatcher.Invoke(() => { for (int i = 0; i < Animation.GetFactoredSpeed(); i++) { RotateNDegreesAntiClockwise(degree / (Animation.GetFactoredSpeed())); Application.Current.Dispatcher.Invoke(delegate { }, System.Windows.Threading.DispatcherPriority.Render); Thread.Sleep(1); } })); } if (!undo) { Animation.TransformationsList.Add( new Transformation(currentMatrix, targetMatrix, VectorMath.GetInverseMatrix(targetMatrix), degree) ); } }
/// <summary> /// Takes a matrix to perform a linear transformation. /// Sets the values of i-hat and j-hat based on this transformation matrix (matrix multiplication) /// </summary> /// <param name="matrix"></param> public void TransformPlane(DWMatrix matrix) { DWMatrix newPlane = VectorMath.MakeLinearTransformation(matrix, new DWMatrix(IHat, JHat)); IHat.X = newPlane.IX; IHat.Y = newPlane.IY; JHat.X = newPlane.JX; JHat.Y = newPlane.JY; UpdateVectorLines(); }
/// <summary> /// Calculates a new plane after a rotation (based on VectorMath), then sets the values of i-hat and j-hat to the new plane. /// Uses radian conversion to work in a 360 space /// </summary> /// <param name="degrees"></param> public void RotateNDegreesAntiClockwise(double degrees) { DWMatrix newPlane = VectorMath.RotateNRadiansAntiClockwise(new DWMatrix(IHat, JHat), ((degrees * Math.PI) / 180)); IHat.X = newPlane.IX; IHat.Y = newPlane.IY; JHat.X = newPlane.JX; JHat.Y = newPlane.JY; UpdateVectorLines(); }