/// <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)); }
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)); }
public CircleF(PointF center, PointF point) { this.Center = center; this.Radius = LineF.FindDistance(center, point); }
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)))); }