public Fraction Tangent(LineFr that) // tan(theta) = (m1 - m2)/(1 + (m1*m2)) { if (isParallelTo(that)) { return(Fraction.Zero); } if (IsVertical()) { if (that.IsHorizontal()) { return(-1); } return(Slope.Inverse()); } if (that.IsVertical()) { if (that.IsHorizontal()) { return(-1); } return(Slope); } if (isPerpendicularTo(that)) { return(-1); } return((Slope - that.Slope) / (1 + Slope * that.Slope)); }
private Fraction XIntercept(LineFr that) // y = slope* x + constant: (b2 - b1) / (m1 - m2) { if (IsVertical()) { return(Constant); } if (that.IsVertical()) { return(that.Constant); } return((that.Constant - Constant) / (Slope - that.Slope)); }
public bool isPerpendicularTo(LineFr that) { if (IsVertical()) { return(that.IsHorizontal()); } if (that.IsVertical()) { return(IsHorizontal()); } return(Slope * that.Slope == -1); }
public bool IsRightOf(LineFr line) { if (line.Contains(this)) { return(false); } if (line.IsHorizontal()) { return(Y < line.YIntercept()); } if (line.IsVertical()) { return(X > line.XIntercept()); } var linePointNullable = line.Intersection(LineFr.Vertical(Fraction.Zero)); if (linePointNullable == null) { throw new ArgumentException("Wartość linePoint nie może wynosić null"); } var linePoint = (PointFr)linePointNullable; var temp = new LineFr(this, linePoint); if (Y < linePoint.Y) { if (line.Slope < 0) // a { return(temp.Slope < 0 && temp.Slope > line.Slope); } return(temp.Slope < 0 || temp.Slope > line.Slope); // b } if (Y > linePoint.Y) { if (line.Slope < 0) // c { return(temp.Slope >= 0 || temp.Slope < line.Slope); } return(temp.Slope >= 0 && temp.Slope < line.Slope); // d } return(IsRightOf(linePoint)); // 'this' ma taką samą współrzędną y jak 'linePoint' }