Arcs
Learn how angles work in an arc and how arcs are connected with lines and curves.
We'll cover the following...
We took a quick look at arcs in one of the previous chapters. This time, we will look more closely at how angles are interpreted and how arcs connect to other lines and curves.
Arc angle rules
The arc function looks like this:
ctx.arc(x, y, r, a1, a2)
It draws an arc of a circle, with center (x, y
), and radius r
. The arc starts at angle a1
and ends at angle a2
. Here is an example:
The red arc was drawn with the following call:
ctx.arc(x, y, r, math.pi/4, math.pi)
There are several things to notice:
- The angle 0 points horizontally to the left, that is in the direction of the x-axis.
- Angles increase as we move clockwise.
- The arc is drawn from the first angle to the second angle, in the direction of increasing angles (that is clockwise).
These points are true to the default coordinate system that we will use in this chapter. If we transform the coordinates, these directions can change. We will assume the selected coordinates to be the same as the default coordinates, for the rest of this chapter.
The arc is drawn as follows:
- The start of the arc a1, that is .
- The length of the arc is a2 – a1, that is , which equals .
- Therefore, the arc starts at and covers an angle of .
Here is another example:
ctx.arc(x, y, r, 7*math.pi/4, math.pi/4)
In this example, a2
is less than a1
. Therefore, Pycairo adds 2*pi to a2
, repeatedly, until the result is greater than a1
. In this case, we only need to add ...