AForge.Point.DistanceTo C# (CSharp) Method

DistanceTo() public method

Calculate Euclidean distance between two points.
public DistanceTo ( Point anotherPoint ) : float
anotherPoint Point Point to calculate distance to.
return float
        public float DistanceTo( Point anotherPoint )
        {
            float dx = X - anotherPoint.X;
            float dy = Y - anotherPoint.Y;

            return (float) System.Math.Sqrt( dx * dx + dy * dy );
        }

Usage Example

Ejemplo n.º 1
0
        /// <summary>
        ///   Gets two points defining the axis of the object.
        /// </summary>
        ///
        public LineSegment GetAxis(AxisOrientation axis)
        {
            double x1, y1;
            double x2, y2;

            if (axis == AxisOrientation.Horizontal)
            {
                y1 = Math.Cos(-Angle - Math.PI) * Rectangle.Height / 2.0;
                x1 = Math.Sin(-Angle - Math.PI) * Rectangle.Width / 2.0;

                y2 = Math.Cos(-Angle) * Rectangle.Height / 2.0;
                x2 = Math.Sin(-Angle) * Rectangle.Width / 2.0;
            }
            else
            {
                y1 = Math.Cos(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Height / 2.0;
                x1 = Math.Sin(-(Angle + Math.PI / 2) - Math.PI) * Rectangle.Width / 2.0;

                y2 = Math.Cos(-(Angle + Math.PI / 2)) * Rectangle.Height / 2.0;
                x2 = Math.Sin(-(Angle + Math.PI / 2)) * Rectangle.Width / 2.0;
            }

            Point start = new Point((float)(Center.X + x1), (float)(Center.Y + y1));
            Point end   = new Point((float)(Center.X + x2), (float)(Center.Y + y2));

            if (start.DistanceTo(end) == 0)
            {
                return(null);
            }

            return(new LineSegment(start, end));
        }
All Usage Examples Of AForge.Point::DistanceTo