コード例 #1
0
        //***************************************************************************
        // Static Methods
        //
        /// <summary>Creates a line segment from the given point and slope, using the given x offset as the location of the other end of the segment.</summary>
        /// <param name="p">The coordinate of the start of the segment.</param>
        /// <param name="m">The slope of the line.</param>
        /// <param name="x">The x-coordinate of the end of the segment.  The y-coordinate will be calculated using y=mx.</param>
        /// <returns>A <see cref="T:AllOneSystem.Drawing.LineF"/> value of the new line segment.</returns>
        public static LineF FromSlope(PointF p, float m, float x)
        {
            //LineF nl = new LineF(new PointF(p.X, 0), new PointF(p.X + 10, m * (p.X + 10)));
            float yi = LineF.FindYIntercept(p, m).Y;

            return(new LineF(p, new PointF(p.X + x, (m * (p.X + 10)) + yi)));
        }
コード例 #2
0
        public void Rotate(float degree)
        {
            LineF r = Rotate(this, degree);

            this.PointA = r.PointA;
            this.PointB = r.PointB;
        }
コード例 #3
0
        public static LineF FindPerpendicular(PointF p, LineF l)
        {
            //return LineF.FromSlope(p, -l.Slope, 50);
            float yi = LineF.FindYIntercept(p, (-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y)).Y;

            return(new LineF(p, new PointF(p.X + 20, ((p.X + 20) * ((-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y))) + yi)));
        }
コード例 #4
0
        public static Line Rotate(Line val, float degree)
        {
            LineF r = LineF.Rotate(new LineF(
                                       new PointF(val.PointA.X, val.PointA.Y),
                                       new PointF(val.PointB.X, val.PointB.Y)), degree);

            return(new Line(Point.Round(r.PointA), Point.Round(r.PointB)));
        }
コード例 #5
0
        public static Line Transform(Line val, Matrix mat)
        {
            LineF r = LineF.Transform(new LineF(
                                          new PointF(val.PointA.X, val.PointA.Y),
                                          new PointF(val.PointB.X, val.PointB.Y)), mat);

            return(new Line(Point.Round(r.PointA), Point.Round(r.PointB)));
        }
コード例 #6
0
        public static PointF FindYIntercept(LineF value)
        {
            // First, we have to determine which point on the line is closest to the axis.
            // This will be the only point we use for calculations.
            PointF p = ((value.PointA.X < value.PointB.X) ? value.PointA : value.PointB);

            return(FindYIntercept(p, value.Slope));
        }
コード例 #7
0
 public static Line Truncate(LineF value)
 {
     return(new Line(
                new Point(
                    (int)System.Math.Truncate(value.PointA.X),
                    (int)System.Math.Truncate(value.PointA.Y)),
                new Point(
                    (int)System.Math.Truncate(value.PointB.X),
                    (int)System.Math.Truncate(value.PointB.Y))));
 }
コード例 #8
0
 public static Line Floor(LineF value)
 {
     return(new Line(
                new Point(
                    (int)System.Math.Floor(value.PointA.X),
                    (int)System.Math.Floor(value.PointA.Y)),
                new Point(
                    (int)System.Math.Floor(value.PointB.X),
                    (int)System.Math.Floor(value.PointB.Y))));
 }
コード例 #9
0
 public static Line Ceiling(LineF value)
 {
     return(new Line(
                new Point(
                    (int)System.Math.Ceiling(value.PointA.X),
                    (int)System.Math.Ceiling(value.PointA.Y)),
                new Point(
                    (int)System.Math.Ceiling(value.PointB.X),
                    (int)System.Math.Ceiling(value.PointB.Y))));
 }
コード例 #10
0
 public static LineF Rotate(LineF val, float degree)
 {
     PointF[] p = new PointF[] { new PointF(val.PointA.X, val.PointA.Y), new PointF(val.PointB.X, val.PointB.Y) };
     using (Matrix trans = new Matrix())
     {
         RectangleF b = val.GetBounds();
         trans.RotateAt(degree, new PointF(b.Right - (b.Width / 2), b.Bottom - (b.Height / 2)));
         trans.TransformPoints(p);
     }
     return(new LineF(p[0], p[1]));
 }
コード例 #11
0
        /// <summary>Determines the coordinate of intersection of two lines.  If the given line segments do not actually intersect, this will return the point where they would intersect on an infinite plane.</summary>
        /// <param name="val1">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the first line.</param>
        /// <param name="val2">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the second line.</param>
        /// <returns></returns>
        public static PointF FindIntersect(LineF val1, LineF val2)
        {
            // First, we need the y-intercepts for each line.
            float yi1 = LineF.FindYIntercept(val1).Y;
            float yi2 = LineF.FindYIntercept(val2).Y;

            // Now that we have the slope and y-intercept of each line, the equations
            //   to find the intercept are easy.
            double ix = ((-yi1) + yi2) / (val1.Slope - val2.Slope);
            double iy = (((-val1.Slope) * yi2) + (val2.Slope * yi1)) / (val1.Slope - val2.Slope);

            // And then, we just return our new point, but inverting the y-coordinate,
            //   due to the method used to determine the y-intercept of our lines.
            return(new PointF((float)ix, (float)(-iy)));
        }
コード例 #12
0
        /// <summary>Determines whether the specified point exists within this triangle's sides.</summary>
        /// <param name="p">An object of type System.Drawing.Point to test.</param>
        /// <returns>A bool value indicating true if the specified point is within the triangle.  Otherwise, false.</returns>
        public bool Contains(PointF p)
        {
            LineF ac = new LineF(this.PointA, this.PointC);
            LineF ab = new LineF(this.PointA, this.PointB);
            LineF cb = new LineF(this.PointB, this.PointC);

            float da = LineF.FindDistance(this.PointA, p);
            float db = LineF.FindDistance(this.PointB, p);
            float dc = LineF.FindDistance(this.PointC, p);

            float dai = LineF.FindDistance(this.PointA, LineF.FindIntersect(cb, new LineF(this.PointA, p)));
            float dbi = LineF.FindDistance(this.PointB, LineF.FindIntersect(ac, new LineF(this.PointB, p)));
            float dci = LineF.FindDistance(this.PointC, LineF.FindIntersect(ab, new LineF(this.PointC, p)));

            return((da < dai) && (db < dbi) && (dc < dci));
        }
コード例 #13
0
        public static PointF FindMidPoint(LineF value)
        {
            //double x = ((50 * value.PointA.X) + (100 * value.PointB.X)) / 150;
            //double y = ((50 * value.PointA.Y) + (100 * value.PointB.Y)) / 150;
            double x, y;

            if (double.IsInfinity(value.Slope))
            {
                x = value.PointA.X;
                y = System.Math.Min(value.PointA.Y, value.PointB.Y) + (System.Math.Abs(value.PointB.Y - value.PointA.Y) / 2);
            }
            else if (double.IsNaN(value.Slope))
            {
                x = System.Math.Min(value.PointA.X, value.PointB.X) + (System.Math.Abs(value.PointB.X - value.PointA.X) / 2);
                y = value.PointA.Y;
            }
            else
            {
                x = (System.Math.Abs(value.PointB.X - value.PointA.X) / 2);
                y = (value.Slope * x) + ((value.PointA.X > value.PointB.X) ? value.PointB.Y : value.PointA.Y);
            }
            return(new PointF((float)x + (float)System.Math.Min(value.PointA.X, value.PointB.X), (float)y));
        }
コード例 #14
0
        public static float AreaOfIntersect(CircleF val1, CircleF val2)
        {
            // First, we find the distance between the two circle's centers.
            double c = LineF.FindDistance(val1.Center, val2.Center);
            // Then, we use the Law of Cosines to find the angle of the points
            //   at which the two cirlces touch from the circles' centers.
            //  cos(theta) = (r2^2 + c^2 - r1^2) / (2 * r1 * c)
            double theta = System.Math.Sin((System.Math.Pow(val2.Radius, 2) + System.Math.Pow(c, 2) - System.Math.Pow(val1.Radius, 2)) / (2 * val2.Radius * c));

            // Now we find the distance from the midpoint of the chord (the line
            //   segment drawn between the two intersection points) to the center
            //   of either circle.  This value will always be the same no matter
            //   which circle you calculate to.
            double d = val1.Radius * System.Math.Cos(theta / 2);

            // Now, the each 'segment' can be seen as two triangles back-to-back
            //   with an arched cap.  This arched cap is the area of intersect.
            //  (r1^2 * arccos(d / r1)) - (d * sqrt(r1^2 - d^2))
            double area = (System.Math.Pow(val1.Radius, 2) * System.Math.Acos(d / val1.Radius)) - (d * System.Math.Sqrt(System.Math.Pow(val1.Radius, 2) - System.Math.Pow(d, 2)));

            // Since the area of intersect is two of these arched caps back-to-back,
            //   the total area of intersect is twice "area".
            return((float)(area * 2));
        }
コード例 #15
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static float FindSlope(LineF val)
 {
     return FindSlope(val.PointA, val.PointB);
 }
コード例 #16
0
 public static float FindAngle(LineF line1, LineF line2)
 {
     return(FindAngle(line1.PointA, line1.PointB, line2.PointA, line2.PointB));
 }
コード例 #17
0
 public static float FindDistance(LineF val)
 {
     return(FindDistance(val.PointA, val.PointB));
 }
コード例 #18
0
 public static float AngleOfPoint(CircleF cir, PointF point)
 {
     return(LineF.FindAngle(cir.Center, new PointF(cir.Center.X + cir.Radius, cir.Center.Y), cir.Center, point));
 }
コード例 #19
0
 public static int FindDistance(Point p1, Point p2)
 {
     return((int)LineF.FindDistance(new LineF(
                                        new PointF((float)p1.X, (float)p1.Y),
                                        new PointF((float)p2.X, (float)p2.Y))));
 }
コード例 #20
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public float GetTheta(LineF val)
 {
     return (float)LineF.FindAngle(this, val);
 }
コード例 #21
0
ファイル: Triangle.cs プロジェクト: tenshino/RainstormStudios
        /// <summary>Determines whether the specified point exists within this triangle's sides.</summary>
        /// <param name="p">An object of type System.Drawing.Point to test.</param>
        /// <returns>A bool value indicating true if the specified point is within the triangle.  Otherwise, false.</returns>
        public bool Contains(PointF p)
        {
            LineF ac = new LineF(this.PointA, this.PointC);
            LineF ab = new LineF(this.PointA, this.PointB);
            LineF cb = new LineF(this.PointB, this.PointC);

            float da = LineF.FindDistance(this.PointA, p);
            float db = LineF.FindDistance(this.PointB, p);
            float dc = LineF.FindDistance(this.PointC, p);

            float dai = LineF.FindDistance(this.PointA, LineF.FindIntersect(cb, new LineF(this.PointA, p)));
            float dbi = LineF.FindDistance(this.PointB, LineF.FindIntersect(ac, new LineF(this.PointB, p)));
            float dci = LineF.FindDistance(this.PointC, LineF.FindIntersect(ab, new LineF(this.PointC, p)));

            return (da < dai) && (db < dbi) && (dc < dci);
        }
コード例 #22
0
 public static Point FindMidPoint(Line value)
 {
     return(Point.Round(LineF.FindMidPoint(new LineF(
                                               new PointF((float)value.PointA.X, (float)value.PointA.Y),
                                               new PointF((float)value.PointB.X, (float)value.PointB.Y)))));
 }
コード例 #23
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static LineF Rotate(LineF val, float degree)
 {
     PointF[] p = new PointF[] { new PointF(val.PointA.X, val.PointA.Y), new PointF(val.PointB.X, val.PointB.Y) };
     using (Matrix trans = new Matrix())
     {
         RectangleF b = val.GetBounds();
         trans.RotateAt(degree, new PointF(b.Right - (b.Width / 2), b.Bottom - (b.Height / 2)));
         trans.TransformPoints(p);
     }
     return new LineF(p[0], p[1]);
 }
コード例 #24
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static Line Ceiling(LineF value)
 {
     return new Line(
         new Point(
             (int)System.Math.Ceiling(value.PointA.X),
             (int)System.Math.Ceiling(value.PointA.Y)),
         new Point(
             (int)System.Math.Ceiling(value.PointB.X),
             (int)System.Math.Ceiling(value.PointB.Y)));
 }
コード例 #25
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static LineF Transform(LineF val, Matrix mat)
 {
     PointF[] p = new PointF[] { val.PointA, val.PointB };
     mat.TransformPoints(p);
     return new LineF(p[0], p[1]);
 }
コード例 #26
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static PointF FindMidPoint(LineF value)
 {
     //double x = ((50 * value.PointA.X) + (100 * value.PointB.X)) / 150;
     //double y = ((50 * value.PointA.Y) + (100 * value.PointB.Y)) / 150;
     double x, y;
     if(double.IsInfinity(value.Slope))
     {
         x = value.PointA.X;
         y = System.Math.Min(value.PointA.Y, value.PointB.Y) + (System.Math.Abs(value.PointB.Y - value.PointA.Y) / 2);
     }
     else if (double.IsNaN(value.Slope))
     {
         x = System.Math.Min(value.PointA.X, value.PointB.X) + (System.Math.Abs(value.PointB.X - value.PointA.X) / 2);
         y = value.PointA.Y;
     }
     else
     {
         x = (System.Math.Abs(value.PointB.X - value.PointA.X) / 2);
         y = (value.Slope * x) + ((value.PointA.X > value.PointB.X) ? value.PointB.Y : value.PointA.Y);
     }
     return new PointF((float)x + (float)System.Math.Min(value.PointA.X, value.PointB.X), (float)y);
 }
コード例 #27
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
        /// <summary>Determines the coordinate of intersection of two lines.  If the given line segments do not actually intersect, this will return the point where they would intersect on an infinite plane.</summary>
        /// <param name="val1">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the first line.</param>
        /// <param name="val2">An initialized <see cref="T:RainstormStudios.Drawing.LineF"/> value representing the second line.</param>
        /// <returns></returns>
        public static PointF FindIntersect(LineF val1, LineF val2)
        {
            // First, we need the y-intercepts for each line.
            float yi1 = LineF.FindYIntercept(val1).Y;
            float yi2 = LineF.FindYIntercept(val2).Y;

            // Now that we have the slope and y-intercept of each line, the equations
            //   to find the intercept are easy.
            double ix = ((-yi1) + yi2) / (val1.Slope - val2.Slope);
            double iy = (((-val1.Slope) * yi2) + (val2.Slope * yi1)) / (val1.Slope - val2.Slope);

            // And then, we just return our new point, but inverting the y-coordinate,
            //   due to the method used to determine the y-intercept of our lines.
            return new PointF((float)ix, (float)(-iy));
        }
コード例 #28
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static PointF FindYIntercept(LineF value)
 {
     // First, we have to determine which point on the line is closest to the axis.
     // This will be the only point we use for calculations.
     PointF p = ((value.PointA.X < value.PointB.X) ? value.PointA : value.PointB);
     return FindYIntercept(p, value.Slope);
 }
コード例 #29
0
 public static LineF Transform(LineF val, Matrix mat)
 {
     PointF[] p = new PointF[] { val.PointA, val.PointB };
     mat.TransformPoints(p);
     return(new LineF(p[0], p[1]));
 }
コード例 #30
0
 public float GetTheta(LineF val)
 {
     return((float)LineF.FindAngle(this, val));
 }
コード例 #31
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static LineF FindPerpendicular(PointF p, LineF l)
 {
     //return LineF.FromSlope(p, -l.Slope, 50);
     float yi = LineF.FindYIntercept(p, (-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y)).Y;
     return new LineF(p, new PointF(p.X + 20, ((p.X + 20) * ((-(l.PointB.X - l.PointA.X)) / (l.PointB.Y - l.PointA.Y))) + yi));
 }
コード例 #32
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static float FindDistance(LineF val)
 {
     return FindDistance(val.PointA, val.PointB);
 }
コード例 #33
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static Line Floor(LineF value)
 {
     return new Line(
         new Point(
             (int)System.Math.Floor(value.PointA.X),
             (int)System.Math.Floor(value.PointA.Y)),
         new Point(
             (int)System.Math.Floor(value.PointB.X),
             (int)System.Math.Floor(value.PointB.Y)));
 }
コード例 #34
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static float FindAngle(LineF line1, LineF line2)
 {
     return FindAngle(line1.PointA, line1.PointB, line2.PointA, line2.PointB);
 }
コード例 #35
0
 public CircleF(PointF center, PointF point)
 {
     this.Center = center;
     this.Radius = LineF.FindDistance(center, point);
 }
コード例 #36
0
 public static float FindSlope(LineF val)
 {
     return(FindSlope(val.PointA, val.PointB));
 }
コード例 #37
0
ファイル: Line.cs プロジェクト: tenshino/RainstormStudios
 public static Line Truncate(LineF value)
 {
     return new Line(
         new Point(
             (int)System.Math.Truncate(value.PointA.X),
             (int)System.Math.Truncate(value.PointA.Y)),
         new Point(
             (int)System.Math.Truncate(value.PointB.X),
             (int)System.Math.Truncate(value.PointB.Y)));
 }
コード例 #38
0
 public static float FindSlope(Point val1, Point val2)
 {
     return(LineF.FindSlope(new PointF((float)val1.X, (float)val1.Y), new PointF((float)val2.X, (float)val2.Y)));
 }