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)); }
public void SwapEndPoints() { var temp = StartPoint; StartPoint = EndPoint; EndPoint = temp; Line = new LineFr(StartPoint, EndPoint); }
public PointFr?Intersection(LineFr line) { var p = Line.Intersection(line); if (p == null || !Contains((PointFr)p)) { return(null); } return(p); }
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); }
private void MoveSweepLineTo(EventPoint ep) // Przesuń miotłę do nowego punktu zdarzenia { CurrentSweepPoint = ep.PointValue; if (SweepLineValue == null) { throw new ArgumentException("Wartość SweepLineValue nie może być pusta podczas zmiany stanu miotły"); } SweepLineValue = new LineFr(((LineFr)SweepLineValue).Slope, (PointFr)CurrentSweepPoint); if (!OldSweepLineValues.ContainsKey((PointFr)CurrentSweepPoint)) { OldSweepLineValues.Add((PointFr)CurrentSweepPoint, (LineFr)SweepLineValue); } }
public PointFr?Intersection(LineFr that) { if (Slope == that.Slope) { return(null); } var xInt = XIntercept(that); if (IsVertical()) { return(new PointFr(xInt, that.YIntercept(xInt))); } return(new PointFr(xInt, YIntercept(xInt))); }
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' }
public LineSegmentFr(PointFr start, PointFr end, bool LeftMostPointFirst = false) { if (start.Equals(end)) { throw new ArgumentException("Nie można utworzyć odcinka, o dwóch takich samych punktach"); } StartPoint = start; EndPoint = end; MaxX = start.X > end.X ? start.X : end.X; MaxY = start.Y > end.Y ? start.Y : end.Y; MinX = start.X < end.X ? start.X : end.X; MinY = start.Y < end.Y ? start.Y : end.Y; Line = new LineFr(start, end); if (LeftMostPointFirst) { NormalizeEndPoints(); } }
public bool IsLeftOf(LineFr line) { return(!line.Contains(this) && !IsRightOf(line)); }
public bool Intersects(LineFr line) { return(Intersection(line) != null); }
public bool isParallelTo(LineFr that) { return(Slope == that.Slope); }
public bool Intersects(LineFr that) { return(Slope != that.Slope); }