blob: 8f1528fd2d3ee7c93df926bf0870a7b83ffd510a (
plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
|
#include <stdio.h>
#include <math.h>
double poly_perim(unsigned ndims, double *xcoords, double *ycoords)
{
double retval = 0;
for (unsigned i = 0; i < ndims; i++) {
double left = xcoords[(i + 1) % ndims] - xcoords[i];
double right = ycoords[(i + 1) % ndims] - ycoords[i];
retval += sqrt(left * left + right * right);
}
return retval;
}
int main(void)
{
printf("Perimiter: %f\n", poly_perim(3,
(double []){1, 1, 4},
(double []){2, 5, 5}));
return 0;
}
|