/// <summary> /// Normalizes point cloud to range [-1..1]. Ratios will be preserved. /// <para>A bounding rectangle will be determined and then </para> /// <para> 1) points will be translated for (rect center X, rect center Y)</para> /// <para> 2) and then rescaled for (1/scale, 1/scale) where scale is max(width, height).</para> /// </summary> /// <param name="points">Points to normalize.</param> /// <returns>Normalized points.</returns> public static IEnumerable <PointF> Normalize(this IEnumerable <PointF> points) { var rect = points.BoundingRect(); var center = rect.Center(); var scaleFactor = System.Math.Max(rect.Width, rect.Height); var transform = Transforms2D.Combine ( Transforms2D.Translation(-center.X, -center.Y), Transforms2D.Scale(1 / scaleFactor, 1 / scaleFactor) ); points = points.Transform(transform); return(points); }
/// <summary> /// Rotates the point by specified angle in radians. /// </summary> /// <param name="p">Point.</param> /// <param name="angleRad">Angle in radians.</param> /// <returns>Rotated point.</returns> public static PointF Rotate(this PointF p, float angleRad) { return(p.Transform(Transforms2D.Rotation(angleRad))); }