Calculates the distance between the current and the target point in pixel - CSharp System

CSharp examples for System:Math Geometry

Description

Calculates the distance between the current and the target point in pixel

Demo Code


using System.Windows;
using System;/*www  .  j a  va 2 s.  c  om*/

public class Main{
        /// <summary>
        /// Calculates the distance between the current and the target point in pixel
        /// </summary>
        /// <param name="currentPoint">The current point.</param>
        /// <param name="targetPoint">The target point.</param>
        /// <returns>The calculated distance</returns>
        public static double DistanceTo(this Point currentPoint, Point targetPoint)
        {
            var a = targetPoint.X - currentPoint.X;
            var b = targetPoint.Y - currentPoint.Y;

            return Math.Sqrt((a * a) + (b * b));
        }
}

Related Tutorials