Stay Hungry,Stay Foolish!

计算PI -- 采用刘徽的割圆术方法

PI

https://www.mathsisfun.com/numbers/pi.html

 

 

 

Draw a circle with a diameter (all the way across the circle) of 1

Then the circumference (all the way around the circle) is 3.14159265... a number known as Pi

 

Pi (pronounced like "pie") is often written using the greek symbol π

circumference, diameter, radius

The definition of π is:

The Circumference
divided by the Diameter
of a Circle.

The circumference divided by the diameter of a circle is always π, no matter how large or small the circle is!

pi circle diameter

 

To help you remember what π is ... just draw this diagram.

Finding Pi Yourself

Draw a circle, or use something circular like a plate.

Measure around the edge (the circumference):

plate circumference 82
I got 82 cm

Measure across the circle (the diameter):

plate diameter
I got 26 cm

Divide:

82 cm / 26 cm = 3.1538...

That is pretty close to π. Maybe if I measured more accurately?

 

割圆术

https://www.zhihu.com/question/342855331

作者:大的要来了
链接:https://www.zhihu.com/question/342855331/answer/2032705657
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

圆周率(Pi)是圆的周长与直径的比值,一般用希腊字母π表示,是一个在数学及物理学中普遍存在的数学常数。

在古代通常是采用割圆术计算π值。

所谓“割圆术”,是用圆内接正多边形的面积去无限逼近圆面积并以此求取圆周率的方法。“圆,一中同长也”。意思是说:平面内到定点的距离等于定长的点的集合。早在我国先秦时期,《墨经》上就已经给出了圆的这个定义,而公元前11世纪,我国西周时期数学家商高也曾与周公讨论过圆与方的关系。认识了圆,人们也就开始了有关于圆的种种计算,特别是计算圆的面积。我国古代数学经典《九章算术》在第一章“方田”章中写到“半周半径相乘得积步”,也就是我们现在所熟悉的公式。

 

内割法公式推导

 

内割法代码实现

https://github.com/fanqingsong/code_snippet/blob/master/CPP/calc_pi.cpp

#include <iostream>
#include <cmath>

using namespace std;

double getEdgeLen(int cutnum) {
    int halfCutnum = cutnum / 2;
    double edgeLen = 0;
    double halfEdgeLen = 0;

    if (cutnum == 6) {
        return 1;
    }

    halfEdgeLen = getEdgeLen(halfCutnum);
    edgeLen = sqrt(2 - sqrt(4 - pow(halfEdgeLen, 2)));

    return edgeLen;
}

bool checkCutnum(int cutnum) {
    if (cutnum < 6) {
        cout << "cutnum is a positive integer greater than and equal to 6, please correct." << endl;
        return false;
    }

    if (cutnum % 6 != 0) {
        cout << "cutnum must be times 6, please correct." << endl;
        return false;
    }

    while (true) {
        if (cutnum % 2 == 0) {
            cutnum /= 2;
            continue;
        }

        if (cutnum != 3) {
            cout << "cutnum must be 2 power times 6." << endl;
            return false;
        }
    }

    return true;
}

int main() {
    int cutnum = 0;
    double edgeLen = 0;
    double quasiPerimeter = 0;
    double quasiPI = 0;

    //printf("hello world\r\n");

    cout << "please input cutnum for cutting circle, like 6, 12, 24, 48, ..." << endl;

    cin >> cutnum;

    cout << "cutnum is " << cutnum << endl;

    if (!checkCutnum(cutnum)) {
        return 0;
    }

    edgeLen = getEdgeLen(cutnum);

    quasiPerimeter = cutnum * edgeLen;

    quasiPI = quasiPerimeter / 2;

    cout << "the quasi PI is " << quasiPI << endl;

    return 0;
}

 

 

 

 

开方手动计算方法

https://www.zhihu.com/question/347197295/answer/832181439

作者:曹力科
链接:https://www.zhihu.com/question/347197295/answer/832181439
来源:知乎
著作权归作者所有。商业转载请联系作者获得授权,非商业转载请注明出处。

那么如何在没有计算器的时候徒手开平方呢?

现代有一种方法的原理是这样的。

[公式]

以求3的平方根為例子,方法如下:

一时没看懂没关系,可以收藏以后慢慢看。

好了,如果你能看到这里,那么恭喜你,你也可以像祖冲之一样,徒手去算圆周率了。

穿越回到那个时代,别忘了要一个大广场,再加连起来可以绕地球一圈的算筹。

 

posted @ 2021-08-01 22:14  lightsong  阅读(1100)  评论(0编辑  收藏  举报
Life Is Short, We Need Ship To Travel