/// <summary> /// Initializes a new RadMatrix, rotated by the specified angle (in degrees) at the provided origin. /// </summary> /// <param name="angle"></param> /// <param name="origin"></param> public RadMatrix(float angle, PointF origin) { if (angle == 0F || angle == 360F) { this = RadMatrix.Identity; } else { float cos; float sin; RadMatrix.GetCosSin(angle, out cos, out sin); this.M11 = cos; this.M12 = sin; this.M21 = -sin; this.M22 = cos; //calculate DX and DY if (origin != PointF.Empty) { float x = origin.X; float y = origin.Y; this.DX = x - (cos * x) + (sin * y); this.DY = y - (cos * y) - (sin * x); } else { this.DX = 0F; this.DY = 0F; } } }
public void Invert() { if (this.IsIdentity) { return; } float determinant = this.Determinant; if (determinant == 0F) { //nothing to invert, make us empty this = Empty; return; } float m11 = this.M22 / determinant; float m12 = -this.M12 / determinant; float m21 = -this.M21 / determinant; float m22 = this.M11 / determinant; float dx = (this.DX * -m11) - (this.DY * m21); float dy = (this.DX * -m12) - (this.DY * m22); this = new RadMatrix(m11, m12, m21, m22, dx, dy); }
public RadMatrix(float angle, PointF origin) { if ((double)angle == 0.0 || (double)angle == 360.0) { this = RadMatrix.Identity; } else { float cos; float sin; RadMatrix.GetCosSin(angle, out cos, out sin); this.M11 = cos; this.M12 = sin; this.M21 = -sin; this.M22 = cos; if (origin != PointF.Empty) { float x = origin.X; float y = origin.Y; this.DX = (float)((double)x - (double)cos * (double)x + (double)sin * (double)y); this.DY = (float)((double)y - (double)cos * (double)y - (double)sin * (double)x); } else { this.DX = 0.0f; this.DY = 0.0f; } } }
/// <summary> /// Copy constructor. /// </summary> /// <param name="source"></param> public RadMatrix(RadMatrix source) { this.M11 = source.M11; this.M12 = source.M12; this.M21 = source.M21; this.M22 = source.M22; this.DX = source.DX; this.DY = source.DY; }
public void Multiply(RadMatrix m, MatrixOrder order) { if (order == MatrixOrder.Append) { this *= m; } else { this = m * this; } }
public void Invert() { if (this.IsIdentity) { return; } float determinant = this.Determinant; if ((double)determinant == 0.0) { this = RadMatrix.Empty; } else { float m11 = this.M22 / determinant; float m12 = -this.M12 / determinant; float m21 = -this.M21 / determinant; float m22 = this.M11 / determinant; float dx = (float)((double)this.DX * -(double)m11 - (double)this.DY * (double)m21); float dy = (float)((double)this.DX * -(double)m12 - (double)this.DY * (double)m22); this = new RadMatrix(m11, m12, m21, m22, dx, dy); } }
public void Divide(RadMatrix m) { m.Invert(); this.Multiply(m, MatrixOrder.Prepend); }
public void Multiply(RadMatrix m) { this.Multiply(m, MatrixOrder.Prepend); }
public RadMatrix(float angle) { this = new RadMatrix(angle, PointF.Empty); }
public RadMatrix(float scaleX, float scaleY) { this = new RadMatrix(scaleX, scaleY, PointF.Empty); }