//*************************************************************************** // Static Methods // public static PointF PointAtAngle(CircleF cir, float degree) { if (degree > 360 || degree < 0) { throw new ArgumentOutOfRangeException("degree", degree, "Valid values for 'degree' are 0 through 360 in floating point increments"); } // For the Law of Cosines to work, we have to convert degrees // into radians. double t = degree / 180 * System.Math.PI; PointF retVal = new PointF( (float)(cir.Center.X + cir.Radius + System.Math.Sin(t)), (float)(cir.Center.Y + cir.Radius + System.Math.Cos(t))); return(retVal); //for (float t = 0; t < degree; t+=0.1) //{ // double a = t * 180 / Math.PI; // retVal.X = (float)(cir.Center.X + cir.Radius + Math.Sin(a)); // retVal.Y = (flaot)(cir.Center.Y + cir.Radius + Math.Cos(a)); //} }
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 static Circle Floor(CircleF val) { return new Circle((int)System.Math.Floor(val.Center.X), (int)System.Math.Floor(val.Center.Y), (int)System.Math.Floor(val.Radius)); }
//*************************************************************************** // Static Methods // public static Circle Truncate(CircleF val) { return new Circle((int)System.Math.Truncate(val.Center.X), (int)System.Math.Truncate(val.Center.Y), (int)System.Math.Truncate(val.Radius)); }
public int AreaOfIntersect(Circle cir) { return((int)System.Math.Truncate(CircleF.AreaOfIntersect(CircleF.FromCircle(this), CircleF.FromCircle(cir)))); }
public static Circle Round(CircleF val) { return(new Circle((int)System.Math.Round(val.Center.X), (int)System.Math.Round(val.Center.Y), (int)System.Math.Round(val.Radius))); }
public static void DrawShape(CircleF cir, Graphics g, Pen p) { using (GraphicsPath path = cir.GetShape(30, PathPointType.Line)) g.DrawPath(p, path); }
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); }
//*************************************************************************** // Static Methods // public static PointF PointAtAngle(CircleF cir, float degree) { if (degree > 360 || degree < 0) throw new ArgumentOutOfRangeException("degree", degree, "Valid values for 'degree' are 0 through 360 in floating point increments"); // For the Law of Cosines to work, we have to convert degrees // into radians. double t = degree / 180 * System.Math.PI; PointF retVal = new PointF( (float)(cir.Center.X + cir.Radius + System.Math.Sin(t)), (float)(cir.Center.Y + cir.Radius + System.Math.Cos(t))); return retVal; //for (float t = 0; t < degree; t+=0.1) //{ // double a = t * 180 / Math.PI; // retVal.X = (float)(cir.Center.X + cir.Radius + Math.Sin(a)); // retVal.Y = (flaot)(cir.Center.Y + cir.Radius + Math.Cos(a)); //} }
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)); }
public static float AngleOfPoint(CircleF cir, float x, float y) { return(AngleOfPoint(cir, new PointF(x, y))); }
public float AreaOfIntersect(CircleF circle) { return(CircleF.AreaOfIntersect(this, circle)); }
public float AngleOfPoint(PointF point) { return(CircleF.AngleOfPoint(this, point)); }
public static Circle Ceiling(CircleF val) { return(new Circle((int)System.Math.Ceiling(val.Center.X), (int)System.Math.Ceiling(val.Center.Y), (int)System.Math.Ceiling(val.Radius))); }
public static Circle Ceiling(CircleF val) { return new Circle((int)System.Math.Ceiling(val.Center.X), (int)System.Math.Ceiling(val.Center.Y), (int)System.Math.Ceiling(val.Radius)); }
public float AreaOfIntersect(CircleF circle) { return CircleF.AreaOfIntersect(this, circle); }
public static void FillShape(CircleF cir, Graphics g, Brush b) { using (GraphicsPath path = cir.GetShape(60, PathPointType.Bezier)) g.FillPath(b, path); }
public static float AngleOfPoint(CircleF cir, float x, float y) { return AngleOfPoint(cir, new PointF(x, y)); }
public Point GetPointAtAngle(float degree) { return(Point.Truncate(CircleF.PointAtAngle(CircleF.FromCircle(this), degree))); }
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 int AngleOfPoint(Point point) { return((int)System.Math.Truncate(CircleF.AngleOfPoint(CircleF.FromCircle(this), new PointF((float)point.X, (float)point.Y)))); }
//*************************************************************************** // Static Methods // public static Circle Truncate(CircleF val) { return(new Circle((int)System.Math.Truncate(val.Center.X), (int)System.Math.Truncate(val.Center.Y), (int)System.Math.Truncate(val.Radius))); }