# Shearing

Shearing is a Deformative Transformation that causes skewing of an object along one or more coordinate axis. Shearing involves adding a scaled version of one or more coordinates to the coordinate along which the shearing has to be done.

The following summerises Shearing when the object is represented by their coordinate points:

 Shearing Type Equation Form Matrix Form Shearing in 2D $$x' = x + (s_x \times y)$$ $$y' = y + (s_y \times x)$$ $$\begin{bmatrix} 1 & s_x \\s_y & 1 \end{bmatrix} \begin{bmatrix} x \\ y \end{bmatrix} = \begin{bmatrix} x' \\ y' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y \end{bmatrix} \begin{bmatrix} 1 & s_y \\s_x & 1\end{bmatrix} = \begin{bmatrix} x' & y' \end{bmatrix}$$ Shearing in 3D $$x' = x + (s_{xy} \times y) + (s_{xz} \times z)$$ $$y' = y + (s_{yx} \times x) + (s_{yz} \times z)$$ $$z' = z + (s_{zx} \times x) + (s_{zy} \times y)$$ $$\begin{bmatrix} 1 & s_{xy} & s_{xz} \\s_{yx} & 1 & s_{yz}\\s_{zx} & s_{zy} & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \end{bmatrix} = \begin{bmatrix} x' \\ y' \\ z' \end{bmatrix}\hspace{.5cm} OR \hspace{.5cm} \begin{bmatrix} x & y & z \end{bmatrix} \begin{bmatrix} 1 & s_{yx} & s_{zx} \\s_{xy} & 1 & s_{zy}\\s_{xz} & s_{yz} & 1\end{bmatrix} = \begin{bmatrix} x' & y' & z' \end{bmatrix}$$

The following details the meaning of Shearing Scale factors:
 Shearing Scale Factor Meaning $$s_x$$ Scale factor for y axis to bring about shearing along x axis in 2D $$s_y$$ Scale factor for x axis to bring about shearing along y axis in 2D $$s_{xy}, s_{xz}$$ Scale factor for y and z axis respectively to bring about shearing along x axis in 3D $$s_{yx}, s_{yz}$$ Scale factor for x and z axis respectively to bring about shearing along y axis in 3D $$s_{zx}, s_{zy}$$ Scale factor for x and y axis respectively to bring about shearing along z axis in 3D

Shrearing transformation may cause unwanted Translation. To prevent it from occurring the object to be sheared must be anchored to a point. Following are the steps involved in shrearing an object anchored to a particular point $$(o_x,o_y)$$ (or $$(o_x,o_y,o_z)$$ in 3D).
1. Shift the origin to point $$(o_x,o_y)$$ (or $$(o_x,o_y,o_z)$$ in 3D)
2. Perform the required Shrearing
3. Undo Shifting the origin i.e shift the origin back to point $$(0,0)$$ (or $$(0,0,0)$$ in 3D)
The following gives the derivation of 2D Anchored Shrearing matrix:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & o_x \\ 0 & 1 & o_y \\0 & 0 & 1\end{bmatrix} \begin{bmatrix} 1 & s_x & 0 \\ s_y & 1 & 0 \\0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & -o_x \\ 0 & 1 & -o_y \\ 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & s_x & -s_x \times o_y\\s_y & 1 & -s_y \times o_x\\0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\-o_x & -o_y & 1 \end{bmatrix} \begin{bmatrix} 1 & s_y & 0\\ s_x & 1 & 0\\ 0 & 0 & 1\end{bmatrix} \begin{bmatrix} 1 & 0 & 0 \\ 0 & 1 & 0 \\ o_x & o_y & 1 \end{bmatrix} = \begin{bmatrix} x & y & 1 \end{bmatrix} \begin{bmatrix} 1 & s_y & 0\\s_x & 1 & 0\\ -s_x \times o_y & -s_y \times o_x & 1\end{bmatrix}$$ Equations $$x' = x + (s_x \times y) - (s_x \times o_y)$$ $$y' = y + (s_y \times x) - (s_y \times o_x)$$

The following gives the derivation of 3D Anchored Shrearing matrix:
 Matrix Type Matrix Post Multiplication $$\begin{bmatrix} 1 & 0 & 0 & o_x \\ 0 & 1 & 0 & o_y \\0 & 0 & 1 & o_z \\0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & s_{xy} & s_{xz} & 0 \\ s_{yx} & 1 & s_{yz} & 0 \\s_{zx} & s_{zy} & 1 & 0 \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & -o_x \\ 0 & 1 & 0 & -o_y \\ 0 & 0 & 1 & -o_z \\ 0 & 0 & 0 & 1 \end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix} = \begin{bmatrix} 1 & s_{xy} & s_{xz} & -s_{xy} \times o_y -s_{xz} \times o_z\\s_{yx} & 1 & s_{yz} & -s_{yx} \times o_x - s_{yz} \times o_z\\s_{zx} & s_{zy} & 1 & -s_{zx} \times o_x -s_{zy} \times o_y\\0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} x \\ y \\ z \\ 1 \end{bmatrix}$$ Pre Multiplication $$\begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\0 & 0 & 1 & 0 \\ -o_x & -o_y & -o_z & 1 \end{bmatrix} \begin{bmatrix} 1 & s_{yx} & s_{zx} & 0 \\ s_{xy} & 1 & s_{zy} & 0 \\s_{xz} & s_{yz} & 1 & 0 \\ 0 & 0 & 0 & 1\end{bmatrix} \begin{bmatrix} 1 & 0 & 0 & 0\\ 0 & 1 & 0 & 0\\ 0 & 0 & 1 & 0\\o_x & o_y & o_z & 1 \end{bmatrix} = \begin{bmatrix} x & y & z & 1 \end{bmatrix} \begin{bmatrix} 1 & s_{yx} & s_{zx} & 0 \\s_{xy} & 1 & s_{zy} & 0 \\s_{xz} & s_{yz} & 1 & 0 \\ -s_{xy} \times o_y -s_{xz} \times o_z & -s_{yx} \times o_x - s_{yz} \times o_z & -s_{zx} \times o_x -s_{zy} \times o_y & 1\end{bmatrix}$$ Equations $$x' = x + (s_{xy} \times y) + (s_{xz} \times z) - (s_{xy} \times o_y) - (s_{xz} \times o_z)$$ $$y' = y + (s_{yx} \times x) + (s_{yz} \times z) - (s_{yx} \times o_x) - (s_{yz} \times o_z)$$ $$z' = z + (s_{zx} \times x) + (s_{zy} \times y) - (s_{zx} \times o_x) - (s_{zy} \times o_y)$$