working on it ...

## Filters

Sort by

Found 354 snippets matching: invert

### Invert a hex color

```	invertColor:function(inputColor){
var color = inputColor;
color = color.substring(1);           // remove #
color = parseInt(color, 16);          // convert to integer
color = 0xFFFFFF ^ color;             // invert three bytes
color = color.toString(16);           // convert to hex
color = "#" + color;                  // prepend #
return color;
}```

### Toggle Method for Integer and Boolean Types (Extension Method)

Allow you to use Variable.Toggle() to invert the current value of a Boolean Variable. Also works with Integer type too!
```Public Module Toggles

<Extension()>
Public Sub Toggle(ByRef Bool As Boolean)
Bool = Not Bool
End Sub

<Extension()>
Public Sub Toggle(ByRef Int As Integer)
If Int > 0 Then
Int = 0
Else
Int = 1
End If
End Sub
End Module```

### inv: Inverts a matrix.

Inverts a matrix.
```/// <summary>Inverts a matrix.</summary>
protected static mat inv(double[,] matrix) { return Matrix.Inverse(matrix); }```

### Divide: Divides two matrices by multiplying A by the inverse of B.

Divides two matrices by multiplying A by the inverse of B. The first matrix. The second matrix (which will be inverted). The result from the division AB^-1 of the given matrices.
```#endregion

#region Division

/// <summary>
///   Divides two matrices by multiplying A by the inverse of B.
/// </summary>
///
/// <param name="a">The first matrix.</param>
/// <param name="b">The second matrix (which will be inverted).</param>
///
/// <returns>The result from the division <c>AB^-1</c> of the given matrices.</returns>
///
public static double[,] Divide(this double[,] a, double[,] b)
{
if (b.GetLength(0) == b.GetLength(1) &&
a.GetLength(0) == a.GetLength(1))
{
// Solve by LU Decomposition if matrix is square.
return new LuDecomposition(b, true).SolveTranspose(a);
}
else
{
// Solve by QR Decomposition if not.
return new QrDecomposition(b, true).SolveTranspose(a);
}
}```

### Solve: Returns the solution matrix if the matrix is square or the least squares solution otherwise.

Returns the solution matrix if the matrix is square or the least squares solution otherwise. The matrix for the linear problem. The right side b. True to produce a solution even if the is singular; false otherwise. Default is false. Please note that this does not check if the matrix is non-singular before attempting to solve
```/// <summary>
///   Returns the solution matrix if the matrix is square or the least squares solution otherwise.
/// </summary>
///
/// <param name="matrix">The matrix for the linear problem.</param>
/// <param name="rightSide">The right side <c>b</c>.</param>
/// <param name="leastSquares">True to produce a solution even if the
///   <paramref name="matrix"/> is singular; false otherwise. Default is false.</param>
///
/// <remarks>
///   Please note that this does not check if the matrix is non-singular
///   before attempting to solve. If a least squares solution is desired
///   in case the matrix is singular, pass true to the <paramref name="leastSquares"/>
///   parameter when calling this function.
/// </remarks>
///
/// <example>
/// <code>
/// // Create a matrix. Please note that this matrix
/// // is singular (i.e. not invertible), so only a
/// // least squares solution would be feasible here.
///
/// double[,] matrix =
/// {
///     { 1, 2, 3 },
///     { 4, 5, 6 },
///     { 7, 8, 9 },
/// };
///
/// // Define a right side vector b:
/// double[] rightSide = { 1, 2, 3 };
///
/// // Solve the linear system Ax = b by finding x:
/// double[] x = Matrix.Solve(matrix, rightSide, leastSquares: true);
///
/// // The answer should be { -1/18, 2/18, 5/18 }.
/// </code>
/// </example>
///
public static double[] Solve(this double[,] matrix, double[] rightSide, bool leastSquares = false)
{
if (matrix == null)
throw new ArgumentNullException("matrix");

if (rightSide == null)
throw new ArgumentNullException("rightSide");

int rows = matrix.GetLength(0);
int cols = matrix.GetLength(1);

if (rows != rightSide.Length)
throw new DimensionMismatchException("rightSide",
"The right hand side vector must have the same length"
+ "as there are rows of the problem matrix.");

if (leastSquares)
{
return new SingularValueDecomposition(matrix,
computeLeftSingularVectors: true,
computeRightSingularVectors: true,
autoTranspose: true).Solve(rightSide);
}

if (rows == cols)
{
// Solve by LU Decomposition if matrix is square.
return new LuDecomposition(matrix).Solve(rightSide);
}
else
{
if (cols < rows)
{
// Solve by QR Decomposition if not.
return new QrDecomposition(matrix).Solve(rightSide);
}
else
{
return new SingularValueDecomposition(matrix,
computeLeftSingularVectors: true,
computeRightSingularVectors: true,
autoTranspose: true).Solve(rightSide);
}
}
}```

### Solve: Returns the solution matrix if the matrix is square or the least squares solution otherwise.

Returns the solution matrix if the matrix is square or the least squares solution otherwise. The matrix for the linear problem. The right side b. True to produce a solution even if the is singular; false otherwise. Default is false. Please note that this does not check if the matrix is non-singular before attempting to solve
```/// <summary>
///   Returns the solution matrix if the matrix is square or the least squares solution otherwise.
/// </summary>
///
/// <param name="matrix">The matrix for the linear problem.</param>
/// <param name="rightSide">The right side <c>b</c>.</param>
/// <param name="leastSquares">True to produce a solution even if the
///   <paramref name="matrix"/> is singular; false otherwise. Default is false.</param>
///
/// <remarks>
///   Please note that this does not check if the matrix is non-singular
///   before attempting to solve. If a least squares solution is desired
///   in case the matrix is singular, pass true to the <paramref name="leastSquares"/>
///   parameter when calling this function.
/// </remarks>
///
/// <example>
/// <code>
/// // Create a matrix. Please note that this matrix
/// // is singular (i.e. not invertible), so only a
/// // least squares solution would be feasible here.
///
/// double[,] matrix =
/// {
///     { 1, 2, 3 },
///     { 4, 5, 6 },
///     { 7, 8, 9 },
/// };
///
/// // Define a right side vector b:
/// double[] rightSide = { 1, 2, 3 };
///
/// // Solve the linear system Ax = b by finding x:
/// double[] x = Matrix.Solve(matrix, rightSide, leastSquares: true);
///
/// // The answer should be { -1/18, 2/18, 5/18 }.
/// </code>
/// </example>
///
public static double[] Solve(this double[][] matrix, double[] rightSide, bool leastSquares = false)
{
if (matrix == null)
throw new ArgumentNullException("matrix");

if (rightSide == null)
throw new ArgumentNullException("rightSide");

int rows = matrix.Length;
int cols = matrix[0].Length;

if (rows != rightSide.Length)
throw new DimensionMismatchException("rightSide",
"The right hand side vector must have the same length"
+ "as there are rows of the problem matrix.");

if (leastSquares)
{
return new JaggedSingularValueDecomposition(matrix,
computeLeftSingularVectors: true,
computeRightSingularVectors: true,
autoTranspose: true).Solve(rightSide);
}

if (rows == cols)
{
// Solve by LU Decomposition if matrix is square.
return new JaggedLuDecomposition(matrix).Solve(rightSide);
}
else
{
if (cols < rows)
{
// Solve by QR Decomposition if not.
return new JaggedQrDecomposition(matrix).Solve(rightSide);
}
else
{
return new JaggedSingularValueDecomposition(matrix,
computeLeftSingularVectors: true,
computeRightSingularVectors: true,
autoTranspose: true).Solve(rightSide);
}
}
}```

### Invert

```using System;
using Microsoft.Xna.Framework;

public static Matrix Invert(Matrix matrix)
{
Matrix result = new Matrix();

float L1 = matrix.M11;
float L2 = matrix.M12;
float L3 = matrix.M13;
float L4 = matrix.M14;
float L5 = matrix.M21;
float L6 = matrix.M22;
float L7 = matrix.M23;
float L8 = matrix.M24;
float L9 = matrix.M31;
float L10 = matrix.M32;
float L11 = matrix.M33;
float L12 = matrix.M34;
float L13 = matrix.M41;
float L14 = matrix.M42;
float L15 = matrix.M43;
float L16 = matrix.M44;
float L17 = (L11 * L16) - (L12 * L15);
float L18 = (L10 * L16) - (L12 * L14);
float L19 = (L10 * L15) - (L11 * L14);
float L20 = (L9 * L16) - (L12 * L13);
float L21 = (L9 * L15) - (L11 * L13);
float L22 = (L9 * L14) - (L10 * L13);
float L23 = ((L6 * L17) - (L7 * L18)) + (L8 * L19);
float L24 = -(((L5 * L17) - (L7 * L20)) + (L8 * L21));
float L25 = ((L5 * L18) - (L6 * L20)) + (L8 * L22);
float L26 = -(((L5 * L19) - (L6 * L21)) + (L7 * L22));
float L27 = 1f / ((((L1 * L23) + (L2 * L24)) + (L3 * L25)) + (L4 * L26));
float L28 = (L7 * L16) - (L8 * L15);
float L29 = (L6 * L16) - (L8 * L14);
float L30 = (L6 * L15) - (L7 * L14);
float L31 = (L5 * L16) - (L8 * L13);
float L32 = (L5 * L15) - (L7 * L13);
float L33 = (L5 * L14) - (L6 * L13);
float L34 = (L7 * L12) - (L8 * L11);
float L35 = (L6 * L12) - (L8 * L10);
float L36 = (L6 * L11) - (L7 * L10);
float L37 = (L5 * L12) - (L8 * L9);
float L38 = (L5 * L11) - (L7 * L9);
float L39 = (L5 * L10) - (L6 * L9);

result.M11 = L23 * L27;
result.M21 = L24 * L27;
result.M31 = L25 * L27;
result.M41 = L26 * L27;
result.M12 = -(((L2 * L17) - (L3 * L18)) + (L4 * L19)) * L27;
result.M22 = (((L1 * L17) - (L3 * L20)) + (L4 * L21)) * L27;
result.M32 = -(((L1 * L18) - (L2 * L20)) + (L4 * L22)) * L27;
result.M42 = (((L1 * L19) - (L2 * L21)) + (L3 * L22)) * L27;
result.M13 = (((L2 * L28) - (L3 * L29)) + (L4 * L30)) * L27;
result.M23 = -(((L1 * L28) - (L3 * L31)) + (L4 * L32)) * L27;
result.M33 = (((L1 * L29) - (L2 * L31)) + (L4 * L33)) * L27;
result.M43 = -(((L1 * L30) - (L2 * L32)) + (L3 * L33)) * L27;
result.M14 = -(((L2 * L34) - (L3 * L35)) + (L4 * L36)) * L27;
result.M24 = (((L1 * L34) - (L3 * L37)) + (L4 * L38)) * L27;
result.M34 = -(((L1 * L35) - (L2 * L37)) + (L4 * L39)) * L27;
result.M44 = (((L1 * L36) - (L2 * L38)) + (L3 * L39)) * L27;

return result;
}```

### InvertMatrix: Inverts the input matrix.

Inverts the input matrix. The matrix values that is to be inverted. Returns a value indicating whether the inversion was successful or not.
```/// <summary>
/// Inverts the input matrix.
/// </summary>
/// <param name="matrix">
/// The matrix values that is to be inverted.
/// </param>
/// <returns>
/// Returns a value indicating whether the inversion was successful or not.
/// </returns>
private static bool InvertMatrix(ref Matrix matrix)
{
double determinant = (matrix.M11 * matrix.M22) - (matrix.M12 * matrix.M21);

if (determinant == 0.0)
{
return false;
}

Matrix matCopy = matrix;
matrix.M11 = matCopy.M22 / determinant;
matrix.M12 = -1 * matCopy.M12 / determinant;
matrix.M21 = -1 * matCopy.M21 / determinant;
matrix.M22 = matCopy.M11 / determinant;
matrix.OffsetX = ((matCopy.OffsetY * matCopy.M21) - (matCopy.OffsetX * matCopy.M22)) / determinant;
matrix.OffsetY = ((matCopy.OffsetX * matCopy.M12) - (matCopy.OffsetY * matCopy.M11)) / determinant;

return true;
}```

### TryWorldToViewportTransform: Computes the transform from world space to the Viewport3DVisual's inner 2D space. This method can fail if Camera.Transform is non-invertable in which case the camera cli...

Computes the transform from world space to the Viewport3DVisual's inner 2D space. This method can fail if Camera.Transform is non-invertable in which case the camera clip planes will be coincident and nothing will render. In this case success will be false.
```using System;
using System.Diagnostics;
using System.Windows;
using System.Windows.Media;
using System.Windows.Media.Media3D;

public static readonly Matrix3D ZeroMatrix = new Matrix3D(0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0, 0);

/// <summary>
///     Computes the transform from world space to the Viewport3DVisual's
///     inner 2D space.
///
///     This method can fail if Camera.Transform is non-invertable
///     in which case the camera clip planes will be coincident and
///     nothing will render.  In this case success will be false.
/// </summary>
public static Matrix3D TryWorldToViewportTransform(Viewport3DVisual visual, out bool success)
{
success = false;
Matrix3D result = Matrix3D.Identity;

Camera camera = visual.Camera;

if (camera == null)
{
return ZeroMatrix;
}

Rect viewport = visual.Viewport;

if (viewport == Rect.Empty)
{
return ZeroMatrix;
}

Transform3D cameraTransform = camera.Transform;

if (cameraTransform != null)
{
Matrix3D m = cameraTransform.Value;

if (!m.HasInverse)
{
return ZeroMatrix;
}

m.Invert();
result.Append(m);
}

result.Append(GetViewMatrix(camera));
result.Append(GetProjectionMatrix(camera, MathUtils.GetAspectRatio(viewport.Size)));
result.Append(GetHomogeneousToViewportTransform(viewport));

success = true;
return result;
}```

### IsVisibilityInverted: Determine whether or not visibility is inverted based on a converter parameter. When the parameter is specified as Collapsed, that means that when the boolean value is true, we should return Collapsed, which i...

Determine whether or not visibility is inverted based on a converter parameter. When the parameter is specified as Collapsed, that means that when the boolean value is true, we should return Collapsed, which is inverted.
```using System;
using System.Net;
using System.Windows;
using System.Windows.Controls;
using System.Windows.Documents;
using System.Windows.Ink;
using System.Windows.Input;
using System.Windows.Media;
using System.Windows.Media.Animation;
using System.Windows.Shapes;

/// <summary>
/// Determine whether or not visibility is inverted based on a converter parameter.
/// When the parameter is specified as Collapsed, that means that when the boolean value
/// is true, we should return Collapsed, which is inverted.
/// </summary>
/// <param name="parameter"></param>
/// <returns></returns>
private static bool IsVisibilityInverted(object parameter)
{
return (GetVisibilityMode(parameter) == Visibility.Collapsed);
}```
• Public Snippets
• Channels Snippets