/// <summary>
        /// Returns a DistortedOutlineShape based on the current shape and a RadialWaveDistortion.
        /// The distortion is exactly aligned with the polygon shape.
        /// Only the polygon edges will be bent inwards; the points will not be distorted.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private SmoothOutlineShape RadialWaveDistortedCopy(Random r)
        {
            int n = this.corners;
            int w = this.windings;

            // Note: When slant = 0, our polygons are always oriented so that one edge is in the south.
            double a;

            if (n % 2 == 0)
            {
                // For multiples of 2, there is also an edge in the north.
                // Choose a to be the negative (relative) angle of the eastern corner on that edge.
                a = -(0.25 - 0.5 * w / n);
            }
            else
            {
                // Otherwise, one corner is in the north.
                a = -0.25;
            }
            a += this.slant / (2.0 * Math.PI);

            double bMin = 0.2 + (n + w - 2) * 0.03;         // strongly bent edges
            double bMax = 0.75 + (n - 2) * 0.01;            // slightly bent edges
            double b    = bMin + r.NextDouble() * (bMax - bMin);

            DistortedOutlineShape.Distortion distortion = DistortedOutlineShape.RadialWaveDistortion(this.xc, this.yc, n, a, b);
            return(this.DistortedCopy(distortion));
        }
        /// <summary>
        /// Returns a DistortedOutlineShape based on the current shape and a SpiralDistortion.
        /// A regular polygon with more than six corners is returned unmodified.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private SmoothOutlineShape SpiralDistortedCopy(Random r)
        {
            if (this.windings == 1 && this.corners > 6)
            {
                return(this);
            }

            // d: radial distance between an edge midpoint and a corner
            double d = this.sz - this.xEdge;

            // dr: the same, relative to the shape size
            double dr = d / this.sz;

            // this would wind one corner to the following corner (over the full shape size)
            double maxSpiralWinding = (double)this.windings / (double)this.corners;

            // this would wind a midpoint to a corner (over their radial distance)
            // this is sufficient to make the corner hang over and form a hook
            maxSpiralWinding /= (2.0 * dr);

            // this will produce even stronger overhanging corners
            maxSpiralWinding *= (this.windings == 1 ? 1.5 : 1.2);

            // Choose an actual winding ratio.
            double w = (0.33 + 0.66 * r.NextDouble()) * maxSpiralWinding;

            w = maxSpiralWinding;
            if (r.Next(2) == 0)
            {
                w *= -1;
            }

            DistortedOutlineShape.Distortion distortion = DistortedOutlineShape.SpiralDistortion(this.xc, this.yc, this.sz, w);
            return(this.DistortedCopy(distortion));
        }
Example #3
0
        /// <summary>
        /// Returns a DistortedOutlineShape based on the current shape and a RadialWaveDistortion.
        /// A regular polygon with more than six corners is returned unmodified.
        /// </summary>
        /// <param name="r"></param>
        /// <returns></returns>
        private SmoothOutlineShape RadialWaveDistortedCopy(Random r)
        {
            int    n    = 3 + r.Next(6);                // number of corners
            double a    = r.NextDouble();               // rotation, 0..1
            double bMin = 0.2 + (n - 2) * 0.03;         // strongly indented sides
            double bMax = 0.85 + (n - 2) * 0.0166;      // almost flat sides
            double b    = bMin + r.NextDouble() * (bMax - bMin);

            DistortedOutlineShape.Distortion distortion = DistortedOutlineShape.RadialWaveDistortion(this.xc, this.yc, n, a, b);
            return(this.DistortedCopy(distortion));
        }