Beispiel #1
0
        private void CurveTo(bool isRelative)
        {
            var   point1 = NewPoint(NextValue, NextValue, isRelative, false);
            float x      = NextValue;
            float y      = NextValue;

            bool isQuad = char.IsLetter(_commandStack.Peek()[0]);
            var  point2 = NewPoint(x, y, isRelative, isQuad);

            if (isQuad)
            {
                _path.QuadTo(point1, point2);
                _lastCurveControlPoint = point1;
            }
            else
            {
                var point3 = NewPoint(NextValue, NextValue, isRelative, true);
                _path.CurveTo(point1, point2, point3);
                _lastCurveControlPoint = point2;
                //Logger.Debug($"CurveTo({point1.X},{point1.Y},{point2.X},{point2.Y},{point3.X},{point3.Y})");
            }
        }
Beispiel #2
0
        /**
         * Draws an arc of type "open" only. Accepts an optional x axis rotation value
         **/

        public static void DrawArc(float x, float y, float startAngle, float arc, float radius, float yRadius, float xAxisRotation, PathF aPath)
        {
            // Circumvent drawing more than is needed
            if (Math.Abs(arc) > 360)
            {
                arc = 360;
            }

            // Draw in a maximum of 45 degree segments. First we calculate how many
            // segments are needed for our arc.
            float segs = (float)Math.Ceiling(Math.Abs(arc) / 45);

            // Now calculate the sweep of each segment
            float segAngle = arc / segs;

            float theta = Geometry.DegreesToRadians(segAngle);
            float angle = Geometry.DegreesToRadians(startAngle);

            // Draw as 45 degree segments
            if (segs > 0)
            {
                float beta    = Geometry.DegreesToRadians(xAxisRotation);
                float sinbeta = (float)Math.Sin(beta);
                float cosbeta = (float)Math.Cos(beta);

                // Loop for drawing arc segments
                for (int i = 0; i < segs; i++)
                {
                    angle += theta;

                    float sinangle = (float)Math.Sin(angle - theta / 2);
                    float cosangle = (float)Math.Cos(angle - theta / 2);

                    float div = (float)Math.Cos(theta / 2);
                    float cx  = x + (radius * cosangle * cosbeta - yRadius * sinangle * sinbeta) / div;
                    //Why divide by Math.cos(theta/2)? - FIX THIS
                    float cy = y + (radius * cosangle * sinbeta + yRadius * sinangle * cosbeta) / div;
                    //Why divide by Math.cos(theta/2)? - FIX THIS

                    sinangle = (float)Math.Sin(angle);
                    cosangle = (float)Math.Cos(angle);

                    float x1 = x + (radius * cosangle * cosbeta - yRadius * sinangle * sinbeta);
                    float y1 = y + (radius * cosangle * sinbeta + yRadius * sinangle * cosbeta);

                    aPath.QuadTo(cx, cy, x1, y1);
                }
            }
        }