al_calculate_arc(3alleg5)
โจ al_calculate_arc โ bestie edition โจ
okay so this is a page from the Allegro 5 API manual (that's the 3alleg5 manual name, iykyk), and today we're learning about al_calculate_arc ๐ it's literally math but make it cute.
๐ NAME ๐
al_calculate_arc โ the Allegro 5 API function that does the math for you ๐
๐ฆ SYNOPSIS ๐ฆ
#include <allegro5/allegro_primitives.h>
void al_calculate_arc(float* dest, int stride, float cx, float cy,
float rx, float ry, float start_theta, float delta_theta, float thickness,
int num_points)
๐ DESCRIPTION ๐
okay bestie, here's the vibe check. ๐
When thickness <= 0, this function computes the positions of num_points regularly spaced points on an elliptical arc. that's it, that's the whole thing, no drama, no cap. โจ
When thickness > 0, it's giving two sets of points, and here's exactly how they're built: the first set is the points you'd get in the thickness <= 0 case, shifted by thickness / 2 outward, in a direction perpendicular to the arc curve. the second set is the same deal, but shifted thickness / 2 inward relative to the arc. then the two sets get interleaved in the destination buffer โ meaning the first pair of points will be collinear with the arc center, and the first point of the pair will be farther from the center than the second point. the next pair will also be collinear, but at a different angle, and so on and so on. ๐
So the destination buffer dest is interpreted as a set of regularly spaced pairs of floats, each pair holding the coordinates of the corresponding point on the arc. The two floats in the pair are adjacent, and the distance (in bytes) between the addresses of the first float in two successive pairs is stride. For example, if you have a tightly packed array of floats with no spaces between pairs, then stride will be exactly 2 * sizeof(float). ๐งฎ
๐ธ Example with thickness <= 0 ๐ธ
const int num_points = 4;
float points[num_points][2];
al_calculate_arc(&points[0][0], 2 * sizeof(float), 0, 0, 10, 10, 0, ALLEGRO_PI / 2, 0, num_points);
assert((int)points[0][0] == 10);
assert((int)points[0][1] == 0);
assert((int)points[num_points - 1][0] == 0);
assert((int)points[num_points - 1][1] == 10);
๐ Example with thickness > 0 ๐
const int num_points = 4;
float points[num_points * 2][2];
al_calculate_arc(&points[0][0], 2 * sizeof(float), 0, 0, 10, 10, 0, ALLEGRO_PI / 2, 2, num_points);
assert((int)points[0][0] == 11);
assert((int)points[0][1] == 0);
assert((int)points[1][0] == 9);
assert((int)points[1][1] == 0);
assert((int)points[(num_points - 1) * 2][0] == 0);
assert((int)points[(num_points - 1) * 2][1] == 11);
assert((int)points[(num_points - 1) * 2 + 1][0] == 0);
assert((int)points[(num_points - 1) * 2 + 1][1] == 9);
๐ Parameters ๐
destโ The destination buffer ๐ฆstrideโ Distance (in bytes) between starts of successive pairs of points ๐cx,cyโ Center of the arc ๐ฏrx,ryโ Radii of the arc ๐ฉstart_thetaโ The initial angle from which the arc is calculated in radians ๐delta_thetaโ Angular span of the arc in radians (pass a negative number to switch direction โ yes, negative, it flips the whole vibe) ๐thicknessโ Thickness of the arc ๐๏ธnum_pointsโ The number of points to calculate ๐ข
๐ SEE ALSO ๐
and that's the whole page bestie, go forth and draw arcs ๐โจ the Allegro reference manual says bye, and so do we โ this was al_calculate_arc(3alleg5), periodt ๐ซถ๐
๐ฆ where this page comes from
- debian trixie: allegro5-doc 2:5.2.10.1+dfsg-1 ยท Zlib
- ubuntu questing: allegro5-doc 2:5.2.10.1+dfsg-1build1
- ubuntu resolute: allegro5-doc 2:5.2.11.3+dfsg-1 ยท Zlib
- ubuntu stonking: allegro5-doc 2:5.2.11.3+dfsg-1 ยท Zlib
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms