How to use al_calc_elliptical_arc?
maxdev

Hello, I want to calculate the points of an elliptical arc, but I do not really now, how to use

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_segments)

Could you give me an example how to store the values of the arc, if cx, cy, rx, ry, start_theta, delta_theta and thickness are given?

Mark Oates

 removed; posted in the wrong place

maxdev

Nice game, but that doesn't help me

Mark Oates

Woah. , I was wondering where my post went. I was like "I swear I posted it! "

Edgar Reynaldo
```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_segments)
```

The key is 'num_segments'. You need to have room in 'dest' (in an array or dynamically allocated memory) for at least num_segments*2 x and y values, and if it's a packed array then stride should be 2*sizeof(float). It will store the coordinates of the arc in the 'dest' array. If thickness is greater than zero you need twice as many elements in the array.

For a quick code example here :

```#define NUM_PTS 10
float fltarray[2*NUM_PTS];
float* fltarray2 = new float[2*NUM_PTS];
float* fltarray3 = new float[2*2*NUM_PTS];

al_calculate_arc(fltarray , 2*sizeof(float) , 0 , 0 , 100 , 50 , M_PI/2.0f , M_PI/2.0f , 0 , NUM_PTS);
al_calculate_arc(fltarray2 , 2*sizeof(float) , 0 , 0 , 100 , 50 , M_PI/2.0f , M_PI/2.0f , 0 , NUM_PTS);
al_calculate_arc(fltarray3 , 4*sizeof(float) , 0 , 0 , 100 , 50 , M_PI/2.0f , M_PI/2.0f , 10.0f , NUM_PTS);
```

Mark Oates

Here's my example:

{"name":"609792","src":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/4\/24345a9c83882bd68f82b63576d033b6.png","w":1375,"h":893,"tn":"\/\/djungxnpq2nug.cloudfront.net\/image\/cache\/2\/4\/24345a9c83882bd68f82b63576d033b6"}

1#include <allegro5/allegro.h> 2#include <allegro5/allegro_color.h> 3#include <allegro5/allegro_primitives.h> 4#include <iostream> 5 6 7 8struct xy_points 9{ 10 float x; 11 float y; 12}; 13 14void my_draw_calc_arc(float x, float y) 15{ 16 xy_points points[16]; 17 18 al_calculate_arc(&points[0].x, sizeof(xy_points), 19 x, y, 220, 140, 20 20.0 * ALLEGRO_PI / 180.0, 60.0 * ALLEGRO_PI / 180.0, // start theta and delta theta (in radians) 21 20.0, 8); 22 23 for (unsigned i=0; i<16; i++) 24 { 25 al_draw_circle(points[i].x, points[i].y, 5, al_color_name("dodgerblue"), 2.0); 26 std::cout << "(" << points[i].x << ", " << points[i].y << ")" << std::endl; 27 } 28} 29 30 31 32int main(int argc, char* argv[]) 33{ 34 al_init(); 35 al_init_primitives_addon(); 36 37 ALLEGRO_DISPLAY *display = al_create_display(960, 600); 38 39 my_draw_calc_arc(al_get_display_width(display)/2, al_get_display_height(display)/2); 40 41 al_flip_display(); 42 43 al_rest(2); 44}

This example program shows for 2 seconds then closes.