Skip to content

Arc

Arc

Bases: DrawingObject

A class to create arcs in the tikz environment.

The arc class helps create arcs in Tikz. It is analagous to the TikZ code

\draw <center> arc (<start_angle>:<end_angle>:<radius>);

Parameters:

Name Type Description Default
center

Pair of points representing either the center of the arc or the point at which it should begin drawing (see draw_from_start).

required
start_angle float

The angle (relative to the horizontal) of the start of the arc

required
end_angle float

The angle (relative to the horizontal) of the end of the arc

required
radius float

The radius (in cm) of the arc. If this is specified, x_radius and y_radius cannot be specified.

None
radians bool

True if angles are in radians, False otherwise

False
draw_from_start bool

True if position represents the point at which the arc should begin drawing. False if position represents the center of the desired arc.

True

arc_type

arc_type() -> str

Determine the arc type that the user is attempting to create based on their input.

atan2_for_ellipse

atan2_for_ellipse(angle: Angle) -> float

Perform a tangent inverse operation which returns values between 0 and 2pi.

draw_start

draw_start() -> Tuple[float, float]

Return the point at which we should begin drawing the arc.

start_pos_circle

start_pos_circle() -> Tuple[float, float]

Calculates the point at which the circle should begin drawing, given that the user specified what the center, radius, start, and end angles of the desired circular arc.

start_pos_ellipse

start_pos_ellipse() -> Tuple[float, float]

Calculates the point at which the ellipse arc should begin drawing, given that the user specified what the center, x_radius, y_radius, start, and end angles of the desired elliptic arc.

Example

Here we draw and fill a sequence of arcs. We also demonstrate draw_from_start set to True and False. In the code below, it is by default set to True.

from tikzpy import TikzPicture
from tikzpy.utils import rainbow_colors

tikz = TikzPicture()

for i in range(1, 10):
    t = 4 / i
    arc = tikz.arc((0, 0), 0, 180, radius=t, options=f"fill={rainbow_colors(i)}")
This generates the image

If instead we would like these arcs sharing the same center, we can use the same code, but pass in draw_from_start=False to achieve

Without this option, if we were forced to specify the point at which each arc should begin drawing, we would have to calculate the x-shift for every arc and apply such a shift to keep the centers aligned. That sounds inefficient and like a waste of time to achieve something so simple, right?

Methods

Arc has access to methods .shift(), .scale(), .rotate(), which behave as one would expect and takes in parameters as described before.

A few comments...

This class not only provides a wrapper to draw arcs, but it also fixes a few things that Tikz's \draw arc command simply gets wrong and confuses users with.

  1. With Tikz in TeX, to draw a circular arc one must specify start_angle and end_angle. These make sense: they are the start and end angles of the arc relative to the horizontal. To draw an elliptic arc, one must again specify start_angle and end_angle, but these actually do not represent the starting and end angles of the elliptic arc. They are the parameters t which parameterize the ellipse (a*cos(t), b*sin(t)). This makes drawing elliptic arcs inconvenient.

  2. With Tikz in TeX, the position of the arc is specified by where the arc should start drawing. However, it is sometimes easier to specify the center of the arc.

With Tikz-Python, start_angle and end_angle will always coincide with the starting and end angles, so the user will not get weird unexpected behavior. Additionally, the user can specify the arc position via its center by setting draw_from_start=False, but they can also fall back on the default behavior.