al_calculate_arc(3alleg5)

๐Ÿ“ฆ
version 5.2.11.3 ยท 4 versions
, in debian trixie, ubuntu questing, ubuntu resolute, ubuntu stonking

โœจ 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