File:Pi archi approx.svg

From Wikimedia Commons, the free media repository

Jump to: navigation, search

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
Español: Método de aproximación del número π de Arquímedes.
Date

22 March 2009(2009-03-22)

Source

Own work

Author

Guillaume Jacquenot

Permission
(Reusing this image)
See below.
Other versions Archimedes_pi.svg

[edit] Licensing

I, the copyright holder of this work, hereby publish it under the following licenses:
GNU head Permission is granted to copy, distribute and/or modify this document under the terms of the GNU Free Documentation License, Version 1.2 or any later version published by the Free Software Foundation; with no Invariant Sections, no Front-Cover Texts, and no Back-Cover Texts. A copy of the license is included in the section entitled "GNU Free Documentation License".

Afrikaans | Alemannisch | Aragonés | العربية | Asturianu | Беларуская | Беларуская (тарашкевіца) | Български | বাংলা | ইমার ঠার/বিষ্ণুপ্রিয়া মণিপুরী | Brezhoneg | Bosanski | Català | Cebuano | Česky | Dansk | Deutsch | Ελληνικά | English | Esperanto | Español | Eesti | Euskara | فارسی | Suomi | Français | Gaeilge | Galego | עברית | Hrvatski | Magyar | Հայերեն | Bahasa Indonesia | Ido | Íslenska | Italiano | 日本語 | ქართული | ភាសាខ្មែរ | 한국어 | Kurdî / كوردی | Latina | Lëtzebuergesch | Lietuvių | 文言 | Македонски | Bahasa Melayu | Malti | Nnapulitano | Plattdüütsch | Nederlands | ‪Norsk (nynorsk)‬ | ‪Norsk (bokmål)‬ | Occitan | Polski | Português | Română | Русский | Slovenčina | Slovenščina | Shqip | Српски / Srpski | Svenska | Kiswahili | తెలుగు | ไทย | Tagalog | Türkçe | Українська | اردو | Vèneto | Tiếng Việt | Volapük | Yorùbá | 中文 | ‪中文(简体)‬ | ‪中文(繁體)‬ | +/−

Creative Commons license
Creative Commons Attribution iconCreative Commons Share Alike icon
This file is licensed under the Creative Commons Attribution ShareAlike 3.0, Attribution ShareAlike 2.5, Attribution ShareAlike 2.0 and Attribution ShareAlike 1.0 License. In short: you are free to share and make derivative works of the file under the conditions that you appropriately attribute it, and that you distribute it only under a license identical to this one. Official license.

Afrikaans | Беларуская | Български | Català | Česky | Dansk | Deutsch | Ελληνικά | English | Esperanto | Español | Eesti | Euskara | Estremeñu | Suomi | Français | עברית | Hrvatski | Հայերեն | Italiano | 日本語 | 한국어 | Lietuvių | Македонски | Plattdüütsch | Nederlands | ‪Norsk (bokmål)‬ | Occitan | Polski | Piemontèis | Português | Română | Русский | Slovenčina | ไทย | Vèneto | Tiếng Việt | 中文 | ‪中文(简体)‬ | ‪中文(繁體)‬ | +/−

You may select the license of your choice.

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/TimeThumbnailDimensionsUserComment
current12:21, 22 March 2009Thumbnail for version as of 12:21, 22 March 20091,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)

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