/// <summary> /// Creates a curve of the form of an octagon large enough to inscribe a rectangle /// of width and height around center. /// </summary> /// <param name="width">the inscribed rectangle width</param> /// <param name="height">the inscribed rectangle height</param> /// <param name="center">the inscribed rectangle (and octagon) center</param> /// <returns></returns> public static ICurve CreateOctagon(double width, double height, Point center) { double w = width / 2; double h = height / 2; Point[] ps = new Point[8]; // Pad out horizontally ps[0] = new Point(w + (octagonPad * w), h - (h * octagonPad)); ps[3] = new Point(-ps[0].X, ps[0].Y); ps[4] = new Point(ps[3].X, -ps[3].Y); ps[7] = new Point(ps[0].X, -ps[0].Y); // Pad out vertically ps[1] = new Point(w - (w * octagonPad), h + (h * octagonPad)); ps[2] = new Point(-ps[1].X, ps[1].Y); ps[6] = new Point(ps[1].X, -ps[1].Y); ps[5] = new Point(ps[2].X, -ps[2].Y); for (int i = 0; i < 8; i++) { ps[i] += center; } Curve c = new Curve(8); Curve.AddLineSegment(c, ps[0], ps[1]); for (int i = 2; i < 8; i++) { Curve.ContinueWithLineSegment(c, ps[i]); } Curve.CloseCurve(c); return(c); }
/// <summary> /// Creates curve resembling a house within the rectangle formed by width and height at center /// (if the rectangle is a square, the house has the shape of home plate in baseball). /// </summary> /// <param name="width">the bounding rectangle width</param> /// <param name="height">the bounding rectangle height</param> /// <param name="center">the bounding rectangle center</param> /// <returns></returns> static public ICurve CreateInteriorHouse(double width, double height, Point center) { double w = width / 2; double h = height / 2; double x = center.X; double y = center.Y; Curve c = new Curve(4); Curve.AddLineSegment(c, x - w, y - h, x + w, y - h); Curve.ContinueWithLineSegment(c, x + w, y); Curve.ContinueWithLineSegment(c, x, y + h); Curve.ContinueWithLineSegment(c, x - w, y); Curve.CloseCurve(c); return(c); }
internal Curve ToCurve() { var c = new Curve(); Curve.AddLineSegment(c, StartPoint.Point, StartPoint.Next.Point); PolylinePoint p = StartPoint.Next; while ((p = p.Next) != null) { Curve.ContinueWithLineSegment(c, p.Point); } if (Closed) { Curve.ContinueWithLineSegment(c, StartPoint.Point); } return(c); }
/// <summary> /// testing, don't use /// </summary> /// <param name="width"></param> /// <param name="height"></param> /// <returns></returns> public static ICurve CreateTestShape(double width, double height) { int mult = 1; double w = width * 3; double h = height * 3; Curve curve = new Curve(9); Curve.AddLineSegment(curve, -w, -h, 0, -h / 2); Curve.ContinueWithLineSegment(curve, w / 2, -0.75 * h); Curve.ContinueWithLineSegment(curve, w, -h); Curve.ContinueWithLineSegment(curve, 0.75 * w, -h / 2); Curve.ContinueWithLineSegment(curve, w / 2, 0); Curve.ContinueWithLineSegment(curve, w, h); Curve.ContinueWithLineSegment(curve, 0, h / 2); Curve.ContinueWithLineSegment(curve, -w, mult * h); Curve.ContinueWithLineSegment(curve, -w / 3, 0); Curve.CloseCurve(curve); return(curve); }