/// <summary>Creates an arc around the given circle center. Note that nothing will /// be seen until you call a fill or stroke method.</summary> public void arc(float centerX, float centerY, float radius, float sAngle, float eAngle, bool counterClockwise) { VectorPoint previous = Path.LatestPathNode; float x0; float y0; if (previous == null) { x0 = 0f; y0 = 0f; } else { x0 = previous.X; y0 = previous.Y; } // Clockwise eAngle > sAngle; counter clockwise otherwise. if (eAngle > sAngle) { if (counterClockwise) { // Get them both in range: eAngle = eAngle % (Mathf.PI * 2f); sAngle = sAngle % (Mathf.PI * 2f); // Reduce eAngle by a full rotation so it's smaller: eAngle -= (Mathf.PI * 2f); } } else if (!counterClockwise) { // Get them both in range: eAngle = eAngle % (Mathf.PI * 2f); sAngle = sAngle % (Mathf.PI * 2f); // Reduce sAngle by a full rotation so it's smaller: sAngle -= (Mathf.PI * 2f); } // First, figure out where the actual start is. // It's radius units to the right of center, then rotated through radius around center. // Thus we have a triangle with hyp length of 'radius' and an angle of sAngle: float startX = radius * (float)Math.Cos(sAngle); float startY = radius * (float)Math.Sin(sAngle); // Now find the end point, using exactly the same method: float endX = radius * (float)Math.Cos(eAngle); float endY = radius * (float)Math.Sin(eAngle); // We now have an arc from the current position to endX/endY. // The start and exit node angles are usefully just offset from the given ones. // This is because an sAngle of zero should create an arc which starts travelling downwards. // (Or upwards if it's counter clockwise): // Where does the arc start from? float arcStartX = centerX + startX; float arcStartY = centerY + startY; if (Path.FirstPathNode == null) { // This occurs if the arc is the first thing we draw. No line is drawn to it. Path.MoveTo(arcStartX, arcStartY); } else if (arcStartX != x0 || arcStartY != y0) { // Draw a line to this point: Path.LineTo(arcStartX, arcStartY); } // Create the new arc node: ArcLinePoint arcNode = new ArcLinePoint(centerX + endX, centerY + endY); // Apply the radius: arcNode.Radius = radius; // Apply the angles: arcNode.StartAngle = sAngle; arcNode.EndAngle = eAngle; // Apply the center: arcNode.CircleCenterX = centerX; arcNode.CircleCenterY = centerY; // Add the other end: Path.AddPathNode(arcNode); }