diff options
| author | Tomasz Kramkowski <tk@the-tk.com> | 2015-04-26 14:54:38 +0100 | 
|---|---|---|
| committer | Tomasz Kramkowski <tk@the-tk.com> | 2015-04-26 14:54:38 +0100 | 
| commit | b6c5b07716105fb4d24a615689b842d5433cd82f (patch) | |
| tree | 711f212ccbf7cd5d4e28ef01e63cce7fbd06bbb3 /poly_perim.c | |
| parent | baa9a0c6a5ecaac3522f64d8e04aa85d6498dd8c (diff) | |
| download | c-stuff-b6c5b07716105fb4d24a615689b842d5433cd82f.tar.gz c-stuff-b6c5b07716105fb4d24a615689b842d5433cd82f.tar.xz c-stuff-b6c5b07716105fb4d24a615689b842d5433cd82f.zip | |
poly_perim.c
Diffstat (limited to 'poly_perim.c')
| -rw-r--r-- | poly_perim.c | 25 | 
1 files changed, 25 insertions, 0 deletions
| diff --git a/poly_perim.c b/poly_perim.c new file mode 100644 index 0000000..8f1528f --- /dev/null +++ b/poly_perim.c @@ -0,0 +1,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; +} | 
