Slope Of Line Segment - CSharp System

CSharp examples for System:Math Geometry

Description

Slope Of Line Segment

Demo Code


using System.Windows.Media;
using System.Windows;
using System;/*from  w  w w.j  av a 2 s. c om*/

public class Main{
        public static double SlopeOfLineSegment(Point start, Point end)
        {
            //If line is vertical then the slope is infinite
            if (start.X == end.X)
            {
                return double.MaxValue;
            }

            //If the line is horizontal then slope is 0
            if (start.Y == end.Y)
            {
                return 0;
            }

            return ((end.Y - start.Y) / (end.X - start.X));
        }
}

Related Tutorials