File:Pi archi approx.svg
From Wikimedia Commons, the free media repository
Pi_archi_approx.svg (SVG file, nominally 1,000 × 180 pixels, file size: 6 KB)
[edit] Summary
| Description |
English: Archimedes' Pi aproximation
Français : Approximation de Pi par la méthode d'Archimède
English: Archimedes' Pi aproximation
Polski: Metoda Archimedesa aproksymacji Pi
|
|---|---|
| Date |
22 March 2009 |
| Source |
Own work |
| Author | |
| Permission (Reusing this image) |
See below. |
| Other versions | Archimedes_pi.svg |
[edit] Licensing
W3C ✓ The source code of this SVG is valid
[edit] Source code (C)
/* Compilation instructions */ /* gcc -Wall -ansi -pedantic -o Pi_archi_approx Pi_archi_approx.c */ /* This program generates an SVG image, showing Archimede's technique to */ /* approximate pi */ /* One argument can be provided, as the maximum number of approximations desired */ #include <stdio.h> #include <stdlib.h> #include <math.h> #define PI 3.14159265358979 int main(int argc, char **argv) { int i,j,n; double id,coeff; FILE *fpt; double *x, *y; double R = 40.0; /* Angle values*/ double alpha, alpha_offset; int fontsize = 10; double strokewidth = 0.8; if (argc == 2) n = (int)atof(argv[1]); else { n = 10; } if (n<3) { fprintf(stdout,"\n"); fflush(stdout); exit(1); } /* Opening result file*/ fpt = fopen("Pi_archi_approx.svg","w"); fprintf(fpt,"<?xml version=\"1.0\" encoding=\"UTF-8\" standalone=\"no\"?>\n"); fprintf(fpt,"<!DOCTYPE svg PUBLIC \"-//W3C//DTD SVG 1.1//EN\" \"http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd \">\n"); fprintf(fpt,"<svg\n"); fprintf(fpt," xmlns:rdf=\"http://www.w3.org/1999/02/22-rdf-syntax-ns#\" \n"); fprintf(fpt," xmlns:svg=\"http://www.w3.org/2000/svg\" \n"); fprintf(fpt," xmlns=\"http://www.w3.org/2000/svg\" \n"); fprintf(fpt," width=\"%dpx\" \n",(int)(((n-2)*3+1)*R)); fprintf(fpt," height=\"%dpx\" \n",(int)(4.5*R)); fprintf(fpt," >\n"); for (i=3;i<=n;i++) { id = (double) i; x = (double *)malloc(i*sizeof(double)); y = (double *)malloc(i*sizeof(double)); fprintf(fpt," <g>\n"); fprintf(fpt," <circle cx=\"%f\" cy=\"%f\" r=\"%f\" ",((id-2)*3-0.75)*R,2.5*R,R); fprintf(fpt,"stroke=\"black\" stroke-width=\"%f\" fill=\"none\"/>\n",strokewidth); fprintf(fpt," <polygon points=\""); alpha_offset = -PI/2 + ((i%2)==0) * PI/id; for (j=0;j<i;j++) { alpha = alpha_offset + 2*j*PI/id; x[j] = cos(alpha); y[j] = sin(alpha); fprintf(fpt,"%f,%f ",R*x[j]+((id-2)*3-0.75)*R,R*(y[j]+2.5)); } fprintf(fpt,"\" fill=\"none\" stroke=\"black\" stroke-width=\"%f\"/>\n",strokewidth); coeff = 2.0/sqrt((x[0]+x[1])*(x[0]+x[1]) + (y[0]+y[1])*(y[0]+y[1])); fprintf(fpt," <polygon points=\""); for (j=0;j<i;j++) { fprintf(fpt,"%f,%f ",R*coeff*x[j]+((id-2)*3-0.75)*R,R*(coeff*y[j]+2.5)); } fprintf(fpt,"\" fill=\"none\" stroke=\"black\" stroke-width=\"%f\"/>\n",strokewidth); free(x); free(y); fprintf(fpt," <text x = \"%f\" y = \"%f\" text-anchor=\"middle\" fill = \"black\" font-size = \"%d\">\n", ((id-2)*3-0.75)*R,4*R,fontsize); fprintf(fpt," n = %d\n",i); fprintf(fpt," </text>\n"); fprintf(fpt," </g>\n"); } fprintf(fpt,"</svg>\n"); fclose(fpt); return (0); }
File history
Click on a date/time to view the file as it appeared at that time.
| Date/Time | Thumbnail | Dimensions | User | Comment | |
|---|---|---|---|---|---|
| current | 12:21, 22 March 2009 | 1,000×180 (6 KB) | Gjacquenot (Talk | contribs) | ({{Information |Description={{en|1=Archimedes' Pi aproximation}} {{fr|1=Approximation de pi par la méthode d'Archimède}} |Source=travail personnel (own work) |Author=Guillaume Jacquenot |Date=2009-03-22 |Permission= |other_versions=fi) |
- Edit this file using an external application (See the setup instructions for more information)
File links
There are no pages on Wikimedia Commons that link to this file. Some pages on other Wikimedia projects may link to it.
Global file usage
The following other wikis use this file:
- Usage of Pi archi approx.svg on frwiki