internal static float GetRotation(Matrix matrix) { PointFx p1 = new PointFx(0, 0); PointFx p2 = new PointFx(1, 0); PointFx tp1 = MatrixExtensions.Transform(matrix, p1); PointFx tp2 = MatrixExtensions.Transform(matrix, p2); double dy = Math.Abs(tp2.Y - tp1.Y); float l = DistanceBetweenPoints(tp1, tp2); double rotation = Math.Asin(dy / l); // correct for quadrant if (tp2.Y - tp1.Y > 0) { if (tp2.X - tp1.X < 0) { rotation = Math.PI - rotation; } } else { if (tp2.X - tp1.X > 0) { rotation = 2 * Math.PI - rotation; } else { rotation = rotation + Math.PI; } } // convert to degrees return((float)(rotation * (180 / Math.PI))); }
internal static PointFx InverseTransform(Matrix matrix, PointFx point) { if (matrix.Determinant() != 0.0f) { Matrix tempMatrix = Matrix.Identity; tempMatrix = Matrix.Multiply(tempMatrix, matrix); tempMatrix = Matrix.Invert(tempMatrix); point = MatrixExtensions.Transform(tempMatrix, point); } return(point); }
private static Matrix RotateAt(Matrix matrix, float theta, PointFx pointFx) { Matrix tempMatrix = Matrix.Identity; System.Drawing.Drawing2D.Matrix drawMatrix = new System.Drawing.Drawing2D.Matrix( matrix.M11, matrix.M12, matrix.M21, matrix.M22, matrix.M31, matrix.M32); drawMatrix.RotateAt(theta, new System.Drawing.PointF(pointFx.X, pointFx.Y)); tempMatrix = SetElements(drawMatrix); return(tempMatrix); }
internal void DrawString(string p, SpriteFont font, Color brush, PointFx pointF) { //DrawingContext.Begin( // SpriteSortMode.Deferred, // BlendState.AlphaBlend, // SamplerState.LinearClamp, DepthStencilState.None, // RasterizerState.CullCounterClockwise, // null, // Transform); //DrawingContext.Begin(); DrawingContext.DrawText(font, p, new Vector2(pointF.X, pointF.Y), brush); //DrawingContext.End(); }
internal static PointFx Transform(Matrix tempMatrix, PointFx point) { System.Drawing.PointF[] pts = { new System.Drawing.PointF(point.X, point.Y) }; System.Drawing.PointF[] newPts = TransformPoints(tempMatrix, pts); return(new PointFx(newPts[0].X, newPts[0].Y)); }
/// <summary> /// Returns the geometric distance between the two given points. /// </summary> /// <param name="p1">The first point.</param> /// <param name="p2">The second point.</param> /// <returns>The distance between p1 and p2.</returns> public static float DistanceBetweenPoints(PointFx p1, PointFx p2) { return((float)Math.Sqrt(Math.Pow(p1.X - p2.X, 2) + Math.Pow(p1.Y - p2.Y, 2))); }
void AddPoint(PointFx point, PathPointType type) { pts.Add(point); types.Add(type); }
static PointFx() { PointFx.mEmpty = new PointFx(); }