{"id":207096,"date":"2025-07-08T08:58:53","date_gmt":"2025-07-08T00:58:53","guid":{"rendered":"https:\/\/server.hk\/cnblog\/207096\/"},"modified":"2025-07-08T08:58:53","modified_gmt":"2025-07-08T00:58:53","slug":"%e5%b0%9d%e8%af%95%e5%9c%a8-go-%e4%b8%ad%e8%ae%a1%e7%ae%97-pi%ef%bc%8c%e6%88%91%e5%81%9a%e9%94%99%e4%ba%86%e4%bb%80%e4%b9%88%ef%bc%9f%e5%8f%af%e8%83%bd%e6%98%af%e6%95%b0%e5%ad%a6%e9%97%ae%e9%a2%98","status":"publish","type":"post","link":"https:\/\/server.hk\/cnblog\/207096\/","title":{"rendered":"\u5c1d\u8bd5\u5728 go \u4e2d\u8ba1\u7b97 pi\uff0c\u6211\u505a\u9519\u4e86\u4ec0\u4e48\uff1f\u53ef\u80fd\u662f\u6570\u5b66\u95ee\u9898\uff1fCos\uff1f"},"content":{"rendered":"<p><b><\/b> <\/p>\n<p>\u5f53\u524d\u4f4d\u7f6e\uff1a <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>&gt;<\/span> <span>\u5c1d\u8bd5\u5728 go \u4e2d\u8ba1\u7b97 pi\uff0c\u6211\u505a\u9519\u4e86\u4ec0\u4e48\uff1f\u53ef\u80fd\u662f\u6570\u5b66\u95ee\u9898\uff1fCos\uff1f<\/span><\/p>\n<p><span>\u6765\u6e90\uff1astackoverflow<\/span><br \/>\n<span>2024-04-19 23:33:34<\/span><br \/>\n<span><i><\/i>0\u6d4f\u89c8<\/span><br \/>\n<span style=\"cursor: pointer\"><i><\/i>\u6536\u85cf<\/span> <\/p>\n<p>\u4eca\u5929\u7ed9\u5927\u5bb6\u5e26\u6765\u4e86<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\">\u300a\u5c1d\u8bd5\u5728 go \u4e2d\u8ba1\u7b97 pi\uff0c\u6211\u505a\u9519\u4e86\u4ec0\u4e48\uff1f\u53ef\u80fd\u662f\u6570\u5b66\u95ee\u9898\uff1fCos\uff1f\u300b<\/span>\uff0c\u5176\u4e2d\u6d89\u53ca\u5230\u7684\u77e5\u8bc6\u70b9\u5305\u62ec<span style=\"color: #FF6600;, Helvetica, Arial, sans-serif;font-size: 14px;background-color: #FFFFFF\"><\/span>\u7b49\u7b49\uff0c\u65e0\u8bba\u4f60\u662f\u5c0f\u767d\u8fd8\u662f\u8001\u624b\uff0c\u90fd\u9002\u5408\u770b\u4e00\u770b\u54e6~\u6709\u597d\u7684\u5efa\u8bae\u4e5f\u6b22\u8fce\u5927\u5bb6\u5728\u8bc4\u8bba\u7559\u8a00\uff0c\u82e5\u662f\u770b\u5b8c\u6709\u6240\u6536\u83b7\uff0c\u4e5f\u5e0c\u671b\u5927\u5bb6\u80fd\u591a\u591a\u70b9\u8d5e\u652f\u6301\u5440\uff01\u4e00\u8d77\u52a0\u6cb9\u5b66\u4e60~<\/p>\n<p> \u95ee\u9898\u5185\u5bb9<br \/>\n <\/p>\n<p>\u6211\u5728\u76f4\u5f84\u4e3a1\u7684\u5706\u5185\u753b\u4e00\u4e2a\u6b63\u65b9\u5f62\uff0c\u6b63\u65b9\u5f62\u7684\u5bf9\u89d2\u7ebf\u5c31\u662f\u5706\u7684\u76f4\u5f84\u3002\u7136\u540e\uff0c\u6211\u4f7f\u7528\u4f59\u5f26\u5b9a\u5f8b\u5c06\u8fd9\u4e2a\u6b63\u65b9\u5f62\u5206\u6210 4 \u4e2a\u76f4\u89d2\u4e09\u89d2\u5f62\uff0c\u5e76\u4e14\u77e5\u9053\u4e09\u89d2\u5f62\u4e0a a \u548c b \u7684\u957f\u5ea6\u4e3a 0.5\uff0c\u6211\u521b\u5efa\u4e86 4 \u4e2a\u4e09\u89d2\u5f62\uff0c\u5176\u659c\u8fb9\u52a0\u5728\u4e00\u8d77\u5f62\u6210\u4e86\u6b63\u65b9\u5f62\u7684\u5468\u957f\u3002\u7ed9\u6211\u4eec\u65b9\u7a0b \u5468\u957f = \u8fb9\u6570 * (a^2 + b^2 -2abcos(360 \/ \u8fb9\u6570)) \u901a\u8fc7\u589e\u52a0\u8be5\u5f62\u72b6\u7684\u8fb9\u6570\uff0c\u5468\u957f\u8d8a\u6765\u8d8a\u63a5\u8fd1\u5706\u7684\u5468\u957f\uff08 3.14\uff09\u3002<\/p>\n<p>\u6211\u4e4b\u524d\u5728 python \u4e2d\u505a\u8fc7\u8fd9\u4e2a\uff0c\u5e76\u4e14\u5b83\u6709\u6548\uff0c\u4f46\u662f\u5728\u5ea6\u6570\u4e0a\u4f7f\u7528\u4f59\u5f26\u5b9a\u5f8b\u800c\u4e0d\u662f\u5728 python \u4e2d\u4f7f\u7528 rad \u65f6\u51fa\u73b0\u4e86\u4e00\u4e2a\u95ee\u9898\uff0c\u8fd9\u628a\u5b83\u5f04\u4e71\u4e86\u3002<\/p>\n<pre>package main\n\nimport \"fmt\"\nimport \"math\"\n\nfunc main() {\n\n    for n := float64(4) ; n == n; n *= 2 {\n        fmt.Println(n)\n        c := math.Pow(0.5 - (0.5 * math.Cos(360 \/ n)), 0.5)\n        fmt.Println(c * n)\n    }\n\n}<\/pre>\n<p>\u7b54\u6848\u5e94\u8be5\u4ece 3 \u5de6\u53f3\u5f00\u59cb\uff0c\u7136\u540e\u4e0a\u5347\u5230\u63a5\u8fd1 3.14\uff0c\u4f46\u5b9e\u9645\u4e0a\u7b54\u6848\u5374\u4e0a\u5347\u5230 180\u3002\u6211\u4e00\u904d\u53c8\u4e00\u904d\u5730\u68c0\u67e5\u6211\u7684\u6570\u5b66\uff0c\u4f46\u6211\u8ba4\u4e3a\u8fd9\u662f\u8bed\u8a00\u7684\u95ee\u9898\uff0c\u800c\u4e0d\u662f\u6211\u6b63\u5728\u505a\u7684\u4e8b\u60c5\u3002<\/p>\n<p> <\/p>\n<h2>\u89e3\u51b3\u65b9\u6848<\/h2>\n<p> <\/p>\n<p>\u4e0d\u8981\u4f7f\u7528\u6807\u51c6\u51fd\u6570 <code>cos<\/code> &#8211; \u6b63\u5982\u5f88\u591a\u4eba\u6240\u8bf4\uff0c\u8981\u4f7f\u7528\u5b83\uff0c\u60a8\u9700\u8981\u5df2\u7ecf\u77e5\u9053 pi \u7684\u503c\uff0c\u56e0\u4e3a\u5b83\u4ee5\u5f27\u5ea6\u4e3a\u53c2\u6570\u3002<\/p>\n<p><strong>\u5927\u591a\u6570\u8ba1\u7b97\u673a\u8bed\u8a00\u7684\u4e09\u89d2\u51fd\u6570\u90fd\u4f7f\u7528\u5f27\u5ea6\u4f5c\u4e3a\u53c2\u6570<\/strong>\u3002\u8fd9\u662f\u56e0\u4e3a\u6709\u5f88\u597d\u3001\u7b80\u5355\u7684\u4e09\u89d2\u51fd\u6570\u8fd1\u4f3c\u516c\u5f0f\u3002\u5982\u679c\u60a8\u4f7f\u7528\u5f27\u5ea6\uff0c\u5219\u51fd\u6570\u3002<\/p>\n<p>\u65e0\u8bba\u5982\u4f55\uff0c\u8fd9\u91cc\u4f60\u4e0d\u9700\u8981\u5b83\uff01\u6bcf\u6b21\u5c06 <code>n<\/code> \u7684\u503c\u52a0\u500d\uff0c\u56e0\u6b64\u53ef\u4ee5\u4f7f\u7528\u4f17\u6240\u5468\u77e5\u7684\u4f59\u5f26\u534a\u89d2\u516c\u5f0f\uff1a<\/p>\n<pre>package main\n\nimport \"fmt\"\nimport \"math\"\n\nfunc main() {\n    cosVal := float64(-1) \/\/ Start at cosine of 180 degrees\n    for n := 4 ; n &lt; 5000; n *= 2 {\n        fmt.Println(n)\n        cosVal = math.Sqrt(0.5 * (cosVal + 1.0))\n        c := math.Pow(0.5 - 0.5*cosVal, 0.5)\n        fmt.Println(c * float64(n))\n    }\n\n}<\/pre>\n<p>\u8fd9\u4f1a\u6839\u636e\u9700\u8981\u6536\u655b\u3002<\/p>\n<p>\u987a\u4fbf\u8bf7\u6ce8\u610f\uff0c\u6700\u521d\u60a8\u60f3\u8981\u4ee5\u5f27\u5ea6\u4e3a\u5355\u4f4d\u6536\u655b\u5230\u534a\u5706\uff08\u5373 pi\uff09\u7684\u4e1c\u897f\uff0c\u4f46\u5f97\u5230\u7684\u5374\u662f\u4ee5\u5ea6\u6570\u4e3a\u5355\u4f4d\u6536\u655b\u5230\u534a\u5706\uff08\u5373 180\uff09\u7684\u4e1c\u897f\u3002\u8fd9\u6b63\u662f\u56e0\u4e3a\u60a8\u5728\u5e94\u8be5\u5c06\u5f27\u5ea6\u4f20\u9012\u7ed9 <code>cos<\/code> \u65f6\u5374\u5c06\u5ea6\u6570\u4f20\u9012\u7ed9\u4e86\u5b83\u3002<\/p>\n<p>\u4eca\u5929\u5e26\u5927\u5bb6\u4e86\u89e3\u4e86\u7684\u76f8\u5173\u77e5\u8bc6\uff0c\u5e0c\u671b\u5bf9\u4f60\u6709\u6240\u5e2e\u52a9\uff1b\u5173\u4e8eGolang\u7684\u6280\u672f\u77e5\u8bc6\u6211\u4eec\u4f1a\u4e00\u70b9\u70b9\u6df1\u5165\u4ecb\u7ecd\uff0c\u6b22\u8fce\u5927\u5bb6\u5173\u6ce8\u516c\u4f17\u53f7\uff0c\u4e00\u8d77\u5b66\u4e60\u7f16\u7a0b~<\/p>\n","protected":false},"excerpt":{"rendered":"<p>\u5f53\u524d\u4f4d\u7f6e\uff1a &gt; &gt; &#46;&#46;&#46;<\/p>\n","protected":false},"author":1,"featured_media":0,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"footnotes":""},"categories":[4925],"tags":[],"class_list":["post-207096","post","type-post","status-publish","format-standard","hentry","category-4925"],"_links":{"self":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207096","targetHints":{"allow":["GET"]}}],"collection":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/users\/1"}],"replies":[{"embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/comments?post=207096"}],"version-history":[{"count":0,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/posts\/207096\/revisions"}],"wp:attachment":[{"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/media?parent=207096"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/categories?post=207096"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/server.hk\/cnblog\/wp-json\/wp\/v2\/tags?post=207096"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}