// // Return the line passing through the given point which is perpendicular to this segment. // public Point ProjectOnto(Point pt) { // // Special Cases // if (this.IsVertical()) { Point newPoint = Point.GetFigurePoint(new Point("", this.Point1.X, pt.Y)); return(newPoint != null ? newPoint : new Point("", this.Point1.X, pt.Y)); } if (this.IsHorizontal()) { Point newPoint = Point.GetFigurePoint(new Point("", pt.X, this.Point1.Y)); return(newPoint != null ? newPoint : new Point("", pt.X, this.Point1.Y)); } // // General Cases // // Find the line perpendicular; specifically, a point on that line double perpSlope = -1 / Slope; // We will choose a random value for x (to acquire y); we choose 1. double newX = pt.X == 0 ? 1 : 0; double newY = pt.Y + perpSlope * (newX - pt.X); // The new perpendicular segment is defined by (newX, newY) and pt return(new Point("", newX, newY)); }