public void TestSolveNEquationsNUnknowns(int testCaseId) { double epsilon = 0.0001; var matrixUtilities = new MatrixUtilities(); var testCase = this.TestCaseIdToMatrixDictionary[testCaseId]; var solution = matrixUtilities.SolveNEquationsNUnknowns(testCase.Equations, testCase.Constants); var resultFromMultiplication = matrixUtilities.MultiplyMatrixByVector(testCase.Equations, solution); Assert.AreEqual(testCase.Solution.Length, solution.Length); Assert.AreEqual(testCase.Constants.Length, resultFromMultiplication.Length); for (int i = 0; i < solution.Length; i++) { Assert.LessOrEqual(Math.Abs(solution[i] - testCase.Solution[i]), epsilon); Assert.LessOrEqual(Math.Abs(resultFromMultiplication[i] - testCase.Constants[i]), epsilon); } var linearEquationRepresentation = this.ConvertMatrixIntoLinearEquations(testCase.Equations, testCase.Constants); var solutionOfLinearEquations = matrixUtilities.SolveLinearSystemOfEquations(linearEquationRepresentation); Assert.AreEqual(testCase.Solution.Length, solutionOfLinearEquations.Length); for (int i = 0; i < solution.Length; i++) { Assert.LessOrEqual(Math.Abs(solution[i] - testCase.Solution[i]), epsilon); } }
public override void Execute(EpsInterpreter interpreter) { var operandStack = interpreter.OperandStack; var dy3 = operandStack.PopRealValue(); var dx3 = operandStack.PopRealValue(); var dy2 = operandStack.PopRealValue(); var dx2 = operandStack.PopRealValue(); var dy1 = operandStack.PopRealValue(); var dx1 = operandStack.PopRealValue(); GraphicsState graphicState = interpreter.GraphicState; var currentPoint = graphicState.CurrentPoint; var x1 = currentPoint.X + dx1; var y1 = currentPoint.Y + dy1; var x2 = currentPoint.X + dx2; var y2 = currentPoint.Y + dy2; var x3 = currentPoint.X + dx3; var y3 = currentPoint.Y + dy3; var ctm = graphicState.CurrentTransformationMatrix; var bezier = new GraphicCubicBezierSegment(); graphicState.CurrentGeometry.Segments.Add(bezier); bezier.ControlPoint1 = MatrixUtilities.TransformPoint(x1, y1, ctm); bezier.ControlPoint2 = MatrixUtilities.TransformPoint(x2, y2, ctm); bezier.EndPoint = MatrixUtilities.TransformPoint(x3, y3, ctm); graphicState.CurrentPoint = new Point(x3, y3); }
protected static int getMinIndexOfMinRatioVector(Matrix /*<Type, Eigen.Dynamic, 1>*/ vector) { int index; MatrixUtilities.minCoeff(vector, out index); return(index); }
public override void Execute(EpsInterpreter interpreter) { var operandStack = interpreter.OperandStack; var y = operandStack.PopRealValue(); var x = operandStack.PopRealValue(); GraphicsState graphicState = interpreter.GraphicState; if (graphicState.CurrentGeometry == null) { graphicState.CurrentGeometry = new GraphicPathGeometry(); } var point = MatrixUtilities.TransformPoint(x, y, graphicState.CurrentTransformationMatrix); var move = new GraphicMoveSegment { StartPoint = point }; graphicState.CurrentGeometry.Segments.Add(move); graphicState.LastMove = move; graphicState.CurrentPoint = new Point(x, y); }
private void AddRectangle(GraphicPathGeometry geometry, double x, double y, double width, double height, Matrix ctm) { var point1 = MatrixUtilities.TransformPoint(x, y, ctm); var point2 = MatrixUtilities.TransformPoint(x + width, y + height, ctm); var move = new GraphicMoveSegment { StartPoint = point1 }; geometry.Segments.Add(move); var lineTo = new GraphicLineSegment { To = new Point(point2.X, point1.Y) }; geometry.Segments.Add(lineTo); lineTo = new GraphicLineSegment { To = new Point(point2.X, point2.Y) }; geometry.Segments.Add(lineTo); lineTo = new GraphicLineSegment { To = new Point(point1.X, point2.Y) }; geometry.Segments.Add(lineTo); move.IsClosed = true; }
private List <GraphicPathSegment> TransformSegments(List <GraphicPathSegment> segments) { var transformedSegments = new List <GraphicPathSegment>(); foreach (var segment in segments) { switch (segment) { case GraphicMoveSegment graphicMove: { var normalizedMove = new GraphicMoveSegment(); transformedSegments.Add(normalizedMove); normalizedMove.StartPoint = MatrixUtilities.TransformPoint(graphicMove.StartPoint, transformMatrix); normalizedMove.IsClosed = graphicMove.IsClosed; break; } case GraphicLineSegment graphicLineTo: { var normalizedLineTo = new GraphicLineSegment(); transformedSegments.Add(normalizedLineTo); normalizedLineTo.To = MatrixUtilities.TransformPoint(graphicLineTo.To, transformMatrix); break; } case GraphicCubicBezierSegment graphicCubicBezier: { var normalizedCubicBezier = new GraphicCubicBezierSegment(); transformedSegments.Add(normalizedCubicBezier); normalizedCubicBezier.ControlPoint1 = MatrixUtilities.TransformPoint(graphicCubicBezier.ControlPoint1, transformMatrix); normalizedCubicBezier.ControlPoint2 = MatrixUtilities.TransformPoint(graphicCubicBezier.ControlPoint2, transformMatrix); normalizedCubicBezier.EndPoint = MatrixUtilities.TransformPoint(graphicCubicBezier.EndPoint, transformMatrix); break; } case GraphicQuadraticBezierSegment graphicQuadraticBezier: { var normalizedQuadraticBezier = new GraphicQuadraticBezierSegment(); transformedSegments.Add(normalizedQuadraticBezier); normalizedQuadraticBezier.ControlPoint = MatrixUtilities.TransformPoint(graphicQuadraticBezier.ControlPoint, transformMatrix); normalizedQuadraticBezier.EndPoint = MatrixUtilities.TransformPoint(graphicQuadraticBezier.EndPoint, transformMatrix); break; } default: break; } } return(transformedSegments); }
protected ManifoldBase(MatrixLL metric, VectorOperatorL del) { this.CovariantMetric = metric; this.ContravariantMetric = this.CreateContravariantMetric( MatrixUtilities.MatrixInverse((i, j) => this.CovariantMetric[i, j], Symbol.Zero, x => 1 / x, (x, y) => x == y)); this.Del = del; int length = this.Size; this.christoffelSymbols = new Symbol[length, length, length]; }
/// <summary> /// Normalize a brush /// </summary> private GraphicBrush TransformBrush(GraphicBrush graphicBrush) { GraphicBrush retBrush; switch (graphicBrush) { case GraphicLinearGradientBrush linearGradientBrush: { if (linearGradientBrush.MappingMode == GraphicBrushMappingMode.Absolute) { var newlinearGradientBrush = new GraphicLinearGradientBrush(); retBrush = newlinearGradientBrush; newlinearGradientBrush.StartPoint = MatrixUtilities.TransformPoint(linearGradientBrush.StartPoint, transformMatrix); newlinearGradientBrush.EndPoint = MatrixUtilities.TransformPoint(linearGradientBrush.EndPoint, transformMatrix); newlinearGradientBrush.MappingMode = linearGradientBrush.MappingMode; newlinearGradientBrush.GradientStops = linearGradientBrush.GradientStops; } else { retBrush = linearGradientBrush; } break; } case GraphicRadialGradientBrush radialGradientBrush: { if (radialGradientBrush.MappingMode == GraphicBrushMappingMode.Absolute) { var newlinearGradientBrush = new GraphicRadialGradientBrush(); retBrush = newlinearGradientBrush; newlinearGradientBrush.StartPoint = MatrixUtilities.TransformPoint(radialGradientBrush.StartPoint, transformMatrix); newlinearGradientBrush.EndPoint = MatrixUtilities.TransformPoint(radialGradientBrush.EndPoint, transformMatrix); (newlinearGradientBrush.RadiusX, newlinearGradientBrush.RadiusY) = MatrixUtilities.TransformSize(radialGradientBrush.RadiusX, radialGradientBrush.RadiusY, transformMatrix); newlinearGradientBrush.MappingMode = radialGradientBrush.MappingMode; newlinearGradientBrush.GradientStops = radialGradientBrush.GradientStops; } else { retBrush = radialGradientBrush; } break; } default: retBrush = graphicBrush; break; } return(retBrush); }
/// <summary> /// Set common shape attributes /// </summary> private void SetShapeAttributes(GraphicPath graphicPath, GraphicPath transformedPath) { transformedPath.FillBrush = TransformBrush(graphicPath.FillBrush); transformedPath.StrokeBrush = TransformBrush(graphicPath.StrokeBrush); transformedPath.StrokeThickness = MatrixUtilities.TransformScale(graphicPath.StrokeThickness, transformMatrix); transformedPath.StrokeMiterLimit = MatrixUtilities.TransformScale(graphicPath.StrokeMiterLimit, transformMatrix); transformedPath.StrokeLineCap = graphicPath.StrokeLineCap; transformedPath.StrokeLineJoin = graphicPath.StrokeLineJoin; transformedPath.StrokeDashOffset = graphicPath.StrokeDashOffset; transformedPath.StrokeDashes = graphicPath.StrokeDashes; }
public void MatrixUtilities_Test() { var arr = MatrixTestsGenerator.GetTestArray(); var result = MatrixUtilities.ToString(arr); Assert.AreEqual(result, @"1, 2, 3, 4, 5, 6, 7, 8, 9, 10, 11, 12, 13, 14, 15, 16, 17, 18, 19, 20, 21, 22, 23, 24, 25, "); }
public override void Apply() { var f = Mathf.SmoothStep(0, 1, DurationCurrent / Duration); //var f = (float)_step / _steps; ValueCurrent = MatrixUtilities.CreateRotationMatrix(Quaternion.Slerp(startRotation, endRotation, f)) * MatrixUtilities.CreateTranslationMatrix(Vector3.Lerp(startTranstion, endTranslation, f)); transform.SetPosition(ValueCurrent.GetPosition(), SetGlobal); transform.SetRotation(ValueCurrent.GetRotation(), SetGlobal); }
/// <summary> /// Set all colors of the graphic path /// </summary> private void SetStroke(XElement path, GraphicPath graphicPath, Matrix currentTransformationMatrix, double parentOpacity) { graphicPath.StrokeBrush = CreateBrush(path, "stroke", false, graphicPath, currentTransformationMatrix, parentOpacity); if (graphicPath.StrokeBrush != null) { graphicPath.StrokeThickness = MatrixUtilities.TransformScale(GetLengthPercentFromCascade("stroke-width", 1), currentTransformationMatrix); graphicPath.StrokeMiterLimit = MatrixUtilities.TransformScale(cssStyleCascade.GetNumber("stroke-miterlimit", 4), currentTransformationMatrix); graphicPath.StrokeLineCap = GetLineCap(); graphicPath.StrokeLineJoin = GetLineJoin(); graphicPath.StrokeDashOffset = MatrixUtilities.TransformScale(GetLengthPercentFromCascade("stroke-dashoffset", 0), currentTransformationMatrix) / graphicPath.StrokeThickness; graphicPath.StrokeDashes = GetDashes(graphicPath.StrokeThickness, currentTransformationMatrix); } }
public void DrawGrid() { for (float x = 0; x < matrixSize; x += matrixSpacing) { for (float z = 0; z < matrixSize; z += matrixSpacing) { for (float y = 0; y < matrixHeight; y += matrixSpacing) { var point = MatrixUtilities.SnapPlacement(new Vector3(x, y, z)); var newTile = Instantiate(tilePrefab, transform.position + point, Quaternion.identity, this.transform); newTile.RemoveUnusableTiles(_layerMask); } } } }
public void GoldmineMatrixPath_Test() { var goldmineMatrixPath = new GoldmineMatrixPath(); var arr = MatrixTestsGenerator.GetZeroedArray(5); // we have a 5x5 array of 0s // assume start is arr[1][0] and end is [4][2] var start = new MatrixPoint(1, 0); var end = new MatrixPoint(4, 2); var shortedPathLength = goldmineMatrixPath.GetShortestPath(arr, start, end); MatrixUtilities.Print(arr); }
/// <summary> /// Set all colors of the graphic path /// </summary> private void SetFillAndStroke(XElement path, GraphicPath graphicPath) { // fill graphicPath.FillBrush = CreateBrush(path, "fill", true, graphicPath); // stroke graphicPath.StrokeBrush = CreateBrush(path, "stroke", false, graphicPath); if (graphicPath.StrokeBrush != null) { graphicPath.StrokeThickness = MatrixUtilities.TransformScale(cssStyleCascade.GetDouble("stroke-width", 1), currentTransformationMatrix); graphicPath.StrokeMiterLimit = MatrixUtilities.TransformScale(cssStyleCascade.GetDouble("stroke-miterlimit", 4), currentTransformationMatrix); graphicPath.StrokeLineCap = GetLineCap(); graphicPath.StrokeLineJoin = GetLineJoin(); graphicPath.StrokeDashOffset = MatrixUtilities.TransformScale(cssStyleCascade.GetDouble("stroke-dashoffset", 0), currentTransformationMatrix) / graphicPath.StrokeThickness; graphicPath.StrokeDashes = GetDashes(graphicPath.StrokeThickness); } }
public override void Apply() { //Notifier.AddMessage(StepCountTotal.ToString()); var f = Mathf.SmoothStep(0, 1, DurationCurrent / Duration); //var f = (float)_step / _steps; var l = Mathf.Lerp(beginLength, endLength, f); var d = Vector3.Lerp(valueBegin.GetPosition(), valueEnd.GetPosition(), f); d.Normalize(); d *= l; ValueCurrent = MatrixUtilities.CreateRotationMatrix(Quaternion.Slerp(ValueOriginal.GetRotation(), ValueTarget.GetRotation(), f)) * MatrixUtilities.CreateTranslationMatrix(d); transform.position = d; transform.rotation = Quaternion.Slerp(ValueOriginal.GetRotation(), ValueTarget.GetRotation(), f); }
public void testQRDecomposition() { // Testing QR decomposition... setup(); double tol = 1.0e-12; Matrix[] testMatrices = { M1, M2, I, M3, Matrix.transpose(M3), M4,Matrix.transpose(M4), M5 }; for (int j = 0; j < testMatrices.Length; j++) { Matrix Q = new Matrix(), R = new Matrix(); bool pivot = true; Matrix A = testMatrices[j]; List <int> ipvt = MatrixUtilities.qrDecomposition(A, ref Q, ref R, pivot); Matrix P = new Matrix(A.columns(), A.columns(), 0.0); // reverse column pivoting for (int i = 0; i < P.columns(); ++i) { P[ipvt[i], i] = 1.0; } if (norm(Q * R - A * P) > tol) { QAssert.Fail("Q*R does not match matrix A*P (norm = " + norm(Q * R - A * P) + ")"); } pivot = false; MatrixUtilities.qrDecomposition(A, ref Q, ref R, pivot); if (norm(Q * R - A) > tol) { QAssert.Fail("Q*R does not match matrix A (norm = " + norm(Q * R - A) + ")"); } } }
public static void CreateArc(EpsInterpreter interpreter, bool sweepDirection) { var operandStack = interpreter.OperandStack; GraphicsState graphicState = interpreter.GraphicState; var angle2 = operandStack.PopRealValue(); var angle1 = operandStack.PopRealValue(); var r = operandStack.PopRealValue(); var y = operandStack.PopRealValue(); var x = operandStack.PopRealValue(); // be aware the segment converter returns coordinates in user space var(segments, startPoint, currentPoint) = ArcToPathSegmentConverter.ArcToPathSegments(new Point(x, y), r, angle1, angle2, sweepDirection); if (graphicState.CurrentGeometry == null) { graphicState.CurrentGeometry = new GraphicPathGeometry(); var point = MatrixUtilities.TransformPoint(startPoint, graphicState.CurrentTransformationMatrix); var move = new GraphicMoveSegment { StartPoint = point }; graphicState.CurrentGeometry.Segments.Add(move); graphicState.LastMove = move; } else { var point = MatrixUtilities.TransformPoint(startPoint, graphicState.CurrentTransformationMatrix); var lineSegment = new GraphicLineSegment { To = point }; graphicState.CurrentGeometry.Segments.Add(lineSegment); } var transformVisual = new TransformVisual(); var transformedSegments = transformVisual.TransformSegments(segments, graphicState.CurrentTransformationMatrix); graphicState.CurrentGeometry.Segments.AddRange(transformedSegments); graphicState.CurrentPoint = currentPoint; }
public override void Execute(EpsInterpreter interpreter) { var operandStack = interpreter.OperandStack; var y = operandStack.PopRealValue(); var x = operandStack.PopRealValue(); GraphicsState graphicState = interpreter.GraphicState; var ctm = graphicState.CurrentTransformationMatrix; var point = MatrixUtilities.TransformPoint(x, y, ctm); var lineTo = new GraphicLineSegment { To = point }; graphicState.CurrentGeometry.Segments.Add(lineTo); graphicState.CurrentPoint = new Point(x, y); }
/// <summary> /// Sets the dash pattern /// </summary> private void SetDashPattern(GraphicsState graphicState, double dashPhase, ArrayOperand dashArray) { if (dashArray.Values.Count == 0) { graphicState.Dashes = null; graphicState.DashOffset = 0; return; } var dashes = new List <double>(); foreach (var val in dashArray.Values) { var dbl = MatrixUtilities.TransformScale(OperandHelper.GetRealValue(val.Operand), graphicState.CurrentTransformationMatrix); dashes.Add(dbl); } graphicState.Dashes = dashes; graphicState.DashOffset = dashPhase; }
IList <FracturedParticle> fractureSolidWithPositionAndRotation(SpatialVectorDouble objectGlobalPosition, Quaternion objectRotation, SolidCluster.SolidWithPositionAndRotation solidWithPositionAndRotation) { uint roughtlyNumberOfFracturedElements = 64; IList <FracturedParticle> fracturedParticles = SimpleFracturing.fractureSolid(solidWithPositionAndRotation.solid, roughtlyNumberOfFracturedElements); // transform positions from local to global foreach (FracturedParticle iFracturedParticle in fracturedParticles) { Matrix localToGlobalTranslation = MatrixUtilities.calcLocalToGlobalTranslationMatrix(objectGlobalPosition); Matrix localToGlobalRotation = QuaternionUtilities.convToRotationMatrix4(objectRotation); Matrix localToGlobal = (localToGlobalTranslation * localToGlobalRotation) * MatrixUtilities.calcLocalToGlobalRotationAndTranslationMatrix(solidWithPositionAndRotation.localPosition, solidWithPositionAndRotation.localRotation); iFracturedParticle.relativePosition = SpatialVectorUtilities.toVector3(new SpatialVectorDouble(localToGlobal * SpatialVectorUtilities.toVector4(iFracturedParticle.relativePosition).asMatrix)); } return(fracturedParticles); }
/// <summary> /// Creates the dashes list. The dashes are convertered from SVG /// absolute size to size relative to the given thickness /// </summary> private List <double> GetDashes(double thickness, Matrix currentTransformationMatrix) { List <double> dashes = null; var strVal = cssStyleCascade.GetProperty("stroke-dasharray"); if (string.IsNullOrEmpty(strVal) || strVal == "none") { return(dashes); } var dbls = doubleParser.GetLengthPercentList(strVal, PercentBaseSelector.None); dashes = new List <double>(); foreach (var dbl in dbls) { var dash = MatrixUtilities.TransformScale(dbl, currentTransformationMatrix); dashes.Add(dash / thickness); } return(dashes); }
/// <summary> /// Sets the dash pattern /// </summary> private void SetDashPattern(CSequence operands) { var dashArray = (CArray)operands[0]; var dashPhase = PdfUtilities.GetDouble(operands[1]); if (dashArray.Count == 0) { currentGraphicsState.Dashes = null; currentGraphicsState.DashOffset = 0; return; } var dashes = new List <double>(); foreach (var val in dashArray) { var dbl = MatrixUtilities.TransformScale(PdfUtilities.GetDouble(val), currentGraphicsState.CurrentTransformationMatrix); dashes.Add(dbl); } currentGraphicsState.Dashes = dashes; currentGraphicsState.DashOffset = dashPhase; }
/// <summary> /// Creates the dashes list. The dashes are convertered from SVG /// absolute size to size relative to the given thickness /// </summary> private List <double> GetDashes(double thickness) { List <double> dashes = null; var strVal = cssStyleCascade.GetProperty("stroke-dasharray"); if (string.IsNullOrEmpty(strVal) || strVal == "none") { return(dashes); } var parser = new DoubleListParser(); var dbls = parser.ParseDoubleList(strVal); dashes = new List <double>(); foreach (var dbl in dbls) { var dash = MatrixUtilities.TransformScale(dbl, currentTransformationMatrix); dashes.Add(dash / thickness); } return(dashes); }
public static Matrix4UU operator *(Matrix4UU lhs, Matrix4LU rhs) { return(new Matrix4UU(MatrixUtilities.MatrixMultiply((i, j) => lhs[i, j], (i, j) => rhs[i, j], lhs.Size, lhs.Operations))); }
public static Vector4U operator *(Vector4OperatorL lhs, Matrix4UU rhs) { return(new Vector4U(MatrixUtilities.VectorMatrixMultiply(i => lhs[i], (i, j) => rhs[i, j], lhs.Size))); }
public static Vector4OperatorU operator *(Matrix4UU lhs, Vector4OperatorL rhs) { return(new Vector4OperatorU(MatrixUtilities.MatrixVectorMultiply((i, j) => lhs[i, j], i => rhs[i], lhs.Size))); }
public Matrix4UU(Symbol diagonal0, Symbol diagonal1, Symbol diagonal2, Symbol diagonal3) : this(MatrixUtilities.DiagonalInitializer(Symbol.Zero, diagonal0, diagonal1, diagonal2, diagonal3)) { }
static EuclideanMatrix4() { EuclideanMatrix4.One = new EuclideanMatrix4(MatrixUtilities.CreateIdentityMatrix(Symbol.Zero, Symbol.One)); }
// after equation [QuaternionFeedbackRegulator] (22) static Matrix calcP(Matrix a) { return(MatrixUtilities.identity(2) + calcAPlus(a) * a.transpose); }