In the `CanvasItem`

I see there is a `draw_circle(...)`

, but is there a way to draw only a part of a circle, from one angle to another?

+5 votes

Best answer

Ok, actually I have a code ready for you, but the tutorial now needs to be written - and it will, but I'll need some time. Don't worry, it *will* be done.

edit : It's done ! http://docs.godotengine.org/en/latest/tutorials/2d/custom_drawing_in_2d.html

So, here are 2 functions for you to draw arcs. The first one draws only the circle, the second one draws a polygon. Parameters angles are in degrees, not in radians (on purpose, to fit with Godot's way to use angles in GDScript - see Vector2.angle()) . Thus, an angle of 0 is a clock needle pointing at noon.

```
func draw_circle_arc( center, radius, angleFrom, angleTo, color ):
var nbPoints = 32
var pointsArc = Vector2Array()
for i in range(nbPoints+1):
var anglePoint = angleFrom + i*(angleTo-angleFrom)/nbPoints - 90
var point = center + Vector2( cos(deg2rad(anglePoint)), sin(deg2rad(anglePoint)) )* radius
pointsArc.push_back( point )
for indexPoint in range(nbPoints):
printt(indexPoint, pointsArc[indexPoint], pointsArc[indexPoint+1])
draw_line(pointsArc[indexPoint], pointsArc[indexPoint+1], color)
pass
func draw_circle_arc_poly( center, radius, angleFrom, angleTo, color ):
var nbPoints = 32
var pointsArc = Vector2Array()
pointsArc.push_back(center)
var colors = ColorArray([color])
for i in range(nbPoints+1):
var anglePoint = angleFrom + i*(angleTo-angleFrom)/nbPoints - 90
pointsArc.push_back(center + Vector2( cos( deg2rad(anglePoint) ), sin( deg2rad(anglePoint) ) )* radius)
draw_polygon(pointsArc, colors)
pass
```

- All categories
- Engine 32,374