Exemple #1
0
 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));
 }
Exemple #2
0
        public void SwapEndPoints()
        {
            var temp = StartPoint;

            StartPoint = EndPoint;
            EndPoint   = temp;
            Line       = new LineFr(StartPoint, EndPoint);
        }
Exemple #3
0
        public PointFr?Intersection(LineFr line)
        {
            var p = Line.Intersection(line);

            if (p == null || !Contains((PointFr)p))
            {
                return(null);
            }
            return(p);
        }
Exemple #4
0
 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));
 }
Exemple #5
0
 public bool isPerpendicularTo(LineFr that)
 {
     if (IsVertical())
     {
         return(that.IsHorizontal());
     }
     if (that.IsVertical())
     {
         return(IsHorizontal());
     }
     return(Slope * that.Slope == -1);
 }
Exemple #6
0
        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);
            }
        }
Exemple #7
0
        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'
        }
Exemple #9
0
        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));
 }
Exemple #11
0
 public bool Intersects(LineFr line)
 {
     return(Intersection(line) != null);
 }
Exemple #12
0
 public bool isParallelTo(LineFr that)
 {
     return(Slope == that.Slope);
 }
Exemple #13
0
 public bool Intersects(LineFr that)
 {
     return(Slope != that.Slope);
 }