Example #1
0
        //Helper method that calculates the angles of the first and last points
        //of the curve
        private void calculateAngles(Point p1, Point p2, Point p3, double length)
        {
            this.startangle = Dewlib.RestrictRange(Math.Atan2(p1.y - center.y, p1.x - center.x), 0, 2 * Math.PI);
            double midangle = Dewlib.RestrictRange(Math.Atan2(p2.y - center.y, p2.x - center.x), 0, 2 * Math.PI);
            //NOT the last point of this curve
            //Only used to calculate the direction of the curve
            double lastangle = Dewlib.RestrictRange(Math.Atan2(p3.y - center.y, p3.x - center.x), 0, 2 * Math.PI);

            if (startangle >= midangle && midangle >= lastangle)
            {
                clockwise = false;
            }
            else if (startangle >= lastangle && lastangle >= midangle)
            {
                clockwise = true;
            }
            else if (midangle >= startangle && startangle >= lastangle)
            {
                clockwise = true;
            }
            else if (midangle >= lastangle && lastangle >= startangle)
            {
                clockwise = false;
            }
            else if (lastangle >= startangle && startangle >= midangle)
            {
                clockwise = false;
            }
            else if (lastangle >= midangle && midangle >= startangle)
            {
                clockwise = true;
            }

            //Use the arclength to calculate the final angle since the last control point
            //of the slider is NOT the last point of the curve
            //This is an angle differential since the formula assumes a start from an angle of 0
            double anglediff = length / radius;

            if (clockwise)
            {
                this.endangle = Dewlib.RestrictRange(startangle + anglediff, 0, 2 * Math.PI);
            }
            else
            {
                this.endangle = Dewlib.RestrictRange(startangle - anglediff, 0, 2 * Math.PI);
            }
        }
Example #2
0
        //Gets a point on the approximated curve on the circle
        //Goes from 0 to 1, where 0 is the starting point and 1 is the ending point
        public Point GetPoint(double t)
        {
            //TODO: Make exception more useful
            if (t < 0 || t > 1)
            {
                throw new ArgumentOutOfRangeException();
            }

            double angle;
            double anglediff;

            if (clockwise)
            {
                if (endangle - startangle > 0)
                {
                    anglediff = endangle - startangle;
                }
                else
                {
                    anglediff = endangle + ((2 * Math.PI) - startangle);
                }

                angle = Dewlib.RestrictRange(t * anglediff + startangle, 0, 2 * Math.PI);
            }
            else
            {
                if (startangle - endangle > 0)
                {
                    anglediff = startangle - endangle;
                }
                else
                {
                    anglediff = startangle + ((2 * Math.PI) - endangle);
                }

                angle = Dewlib.RestrictRange(-t * anglediff + startangle, 0, 2 * Math.PI);
            }

            Point accessed = new Point();

            accessed.x = center.x + radius * Math.Cos(angle);
            accessed.y = center.y + radius * Math.Sin(angle);

            return(accessed);
        }