-
Matrix
-
PowerShell
Matrix math is tedious. This module lets us avoid having to do it.
We can represent changes in space using a matrix.
In CSS, these are called Transform Functions
| Dimension | Transform Function | .NET type |
|---|---|---|
2D |
matrix() |
[Numerics.Matrix3x2] |
3D |
matrix3d() |
[Numerics.Matrix4x4] |
The module allows you to make, modify, and use matrix transforms.
It supports almost identical syntax to the CSS.
We can use Matrix to make CSS transforms, and we can manipulate objects in 2D or 3D the same way a webpage would.
You can install Matrix from the PowerShell gallery
Install-Module Matrix -Scope CurrentUser -Force
Once installed, you can import the module with:
Import-Module Matrix -PassThru
You can also clone the repo and import the module locally:
git clone https://github.com/PoshWeb/Matrix/
cd ./Matrix
Import-Module ./ -PassThru
Matrix has 1 function
Makes and Manipulates Matrix Transformations.
Matrix Transformations move objects in space.
Matrix makes matrixes in PowerShell.
This can transform objects in 2D, 3D, and 4D
We can use matrix to make CSS or transform Vectors.
Matrix math is hard, and this module lets us avoid having to do it.
Instead, we can pipe objects into this module and transform them.
A Matrix in .NET is the same as a Matrix in CSS.
| css function | .NET type |
|---|---|
matrix() |
[Numerics.Matrix3x2] |
matrix3d() |
[Numerics.Matrix4x4] |
This means we can do every transformation that CSS can do.
Any object piped with a Transform static method will be transformed.
Other objects will be passed thru.
Get the identity matrix. This is the object, untransformed, in 2D
Matrix Identity
Gets a 3d identity matrix This is the object, untransformed, in 3d.
Matrix3D Identity
Scale a point in 2d space by directly calling ::CreateScale
[Numerics.Vector2]::new(1,1) |
Matrix 2 -Member CreateScale 1 2
Scale a point in 2d space by using scale
[Numerics.Vector2]::new(1,1) |
Scale 1 2
Skew a point
[Numerics.Vector2]::new(1,1) |
Skew 30deg 10deg
Skew a point along X, then along Y
[Numerics.Vector2]::new(1,1) |
SkewX 30deg |
SkewY 10deg
[Numerics.Vector2]::new(1,1) |
ScaleZ 1
Scale X in 2D
[Numerics.Vector2]::new(1,1) |
ScaleX 2
Scale X in 3D
[Numerics.Vector3]::new(1,1,1) |
ScaleX 2
Scale Y in 3D
[Numerics.Vector2]::new(1,1) |
ScaleY 2
Scale Z in 3D
[Numerics.Vector3]::new(1,1,1) |
ScaleZ 3
Move a point in 3d
[Numerics.Vector3]::new(1,1,1) |
TranslateX 3 |
TranslateY 3 |
TranslateZ 3
Move and scale a point in 3d
[Numerics.Vector3]::new(1,1,1) |
Translate3d 1 2 5 |
Scale3d 3 2 1
[Numerics.Vector3]::new(1,1,1) |
Translate3d 1 2 5 |
Scale3d 3 2 1
Rotate3d
[Numerics.Vector3]::new(1,1,1) |
Rotate3d 1 1 1 30deg
rotate3d as a matrix3d, as CSS
(Rotate3d 1 1 1 30deg).css
Constructing a cube using translation Make a corner point
$corner = [Numerics.Vector3]::new(1,1,1)
# Make a square by translating along X and Y
$square = @(
$corner
$corner | TranslateX 1
$corner | TranslateY 1
$corner | TranslateX 1 | TranslateY 1
)
# Make a cube by translating the square along Z.
$cube = @(
$square
$square |
TranslateZ 1
)
$cube
| Name | Type | Description |
|---|---|---|
| ArgumentList | Object[] | Any arguments for the transform function Arguments can include numbers of CSS units. deg and turn are converted into radians% becomes a value between 0 and 1 |
| InputObject | PSObject[] | Any input objects. If the input object has a Transform static method,it will be transformed. If it does not, it will be passed thru. |
| Member | String | The name of the method or property of a matrix transform. If this is provided, this method will be called instead. Many aliases, such as Skew or Rotate,will use a custom member and will ignore this parameter. |