public PointD IntersectionWith(Line line)
{
if (this.Slope == line.Slope) return null;
else if (this.Slope == null) {
return new PointD(Point.X, line.Y(Point.X).Value);
}
else if (line.Slope == null) {
return line.IntersectionWith(this);
}
else {
double x = (this.Point.Y + (double)line.Slope * line.Point.X - (double)this.Slope * this.Point.X - line.Point.Y) / ((double)line.Slope - (double)this.Slope);
double y = (double)this.Slope * (x - this.Point.X) + this.Point.Y; //Basically just Y(x)
return new PointD(x, y);
}
}