{"id":1125983,"date":"2025-01-08T19:56:48","date_gmt":"2025-01-08T11:56:48","guid":{"rendered":""},"modified":"2025-01-08T19:56:50","modified_gmt":"2025-01-08T11:56:50","slug":"%e5%a6%82%e4%bd%95%e5%88%a9%e7%94%a8python%e8%a7%a3%e4%b8%89%e8%a7%92%e5%bd%a2","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1125983.html","title":{"rendered":"\u5982\u4f55\u5229\u7528python\u89e3\u4e09\u89d2\u5f62"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25090450\/1290654d-ba28-4e8c-958b-095e82294441.webp\" alt=\"\u5982\u4f55\u5229\u7528python\u89e3\u4e09\u89d2\u5f62\" \/><\/p>\n<p><p> <strong>\u5229\u7528Python\u89e3\u4e09\u89d2\u5f62\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u6570\u5b66\u516c\u5f0f\u3001\u5185\u7f6e\u51fd\u6570\u548c\u5916\u90e8\u5e93\u7b49\u3002\u6838\u5fc3\u89c2\u70b9\u5305\u62ec\uff1a\u4f7f\u7528\u4e09\u89d2\u5f62\u57fa\u672c\u516c\u5f0f\u3001\u5229\u7528\u4e09\u89d2\u51fd\u6570\u3001\u4f7f\u7528Python\u7684SymPy\u5e93\u3002\u672c\u6587\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5982\u4f55\u901a\u8fc7\u8fd9\u4e9b\u65b9\u6cd5\u89e3\u4e09\u89d2\u5f62\uff0c\u91cd\u70b9\u8bb2\u89e3\u4f7f\u7528Python\u7684SymPy\u5e93\u3002<\/strong><\/p>\n<\/p>\n<p><h2>\u4e00\u3001\u4f7f\u7528\u4e09\u89d2\u5f62\u57fa\u672c\u516c\u5f0f<\/h2>\n<\/p>\n<p><p>\u5728\u89e3\u4e09\u89d2\u5f62\u95ee\u9898\u65f6\uff0c\u6700\u5e38\u7528\u7684\u57fa\u672c\u516c\u5f0f\u5305\u62ec\u4f59\u5f26\u5b9a\u7406\u548c\u6b63\u5f26\u5b9a\u7406\u3002\u4f59\u5f26\u5b9a\u7406\u9002\u7528\u4e8e\u5df2\u77e5\u4e09\u8fb9\u6c42\u89d2\u5ea6\u6216\u5df2\u77e5\u4e24\u8fb9\u53ca\u5176\u5939\u89d2\u6c42\u7b2c\u4e09\u8fb9\uff0c\u800c\u6b63\u5f26\u5b9a\u7406\u9002\u7528\u4e8e\u5df2\u77e5\u4e24\u89d2\u53ca\u5176\u4e00\u8fb9\u6c42\u7b2c\u4e09\u89d2\u6216\u5df2\u77e5\u4e24\u8fb9\u53ca\u5176\u5bf9\u89d2\u6c42\u7b2c\u4e09\u8fb9\u3002<\/p>\n<\/p>\n<p><h3>1. \u4f59\u5f26\u5b9a\u7406<\/h3>\n<\/p>\n<p><p>\u4f59\u5f26\u5b9a\u7406\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ c^2 = a^2 + b^2 &#8211; 2ab \\cdot \\cos(C) ]<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528math\u5e93\u6765\u5b9e\u73b0\u4f59\u5f26\u5b9a\u7406\u8ba1\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u5df2\u77e5\u4e09\u8fb9a, b, c\uff0c\u6c42\u89d2\u5ea6C<\/strong><\/h2>\n<p>def cos_rule_angle(a, b, c):<\/p>\n<p>    cos_C = (a&lt;strong&gt;2 + b&lt;\/strong&gt;2 - c2) \/ (2 * a * b)<\/p>\n<p>    angle_C = math.acos(cos_C)<\/p>\n<p>    return math.degrees(angle_C)<\/p>\n<h2><strong>\u5df2\u77e5\u4e24\u8fb9\u53ca\u5176\u5939\u89d2\uff0c\u6c42\u7b2c\u4e09\u8fb9<\/strong><\/h2>\n<p>def cos_rule_side(a, b, angle_C):<\/p>\n<p>    angle_C = math.radians(angle_C)<\/p>\n<p>    c = math.sqrt(a&lt;strong&gt;2 + b&lt;\/strong&gt;2 - 2 * a * b * math.cos(angle_C))<\/p>\n<p>    return c<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u6b63\u5f26\u5b9a\u7406<\/h3>\n<\/p>\n<p><p>\u6b63\u5f26\u5b9a\u7406\u516c\u5f0f\u4e3a\uff1a<\/p>\n<p>[ \\frac{a}{\\sin(A)} = \\frac{b}{\\sin(B)} = \\frac{c}{\\sin(C)} ]<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528math\u5e93\u6765\u5b9e\u73b0\u6b63\u5f26\u5b9a\u7406\u8ba1\u7b97\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u5df2\u77e5\u4e24\u8fb9\u53ca\u5176\u5bf9\u89d2\uff0c\u6c42\u7b2c\u4e09\u8fb9<\/strong><\/h2>\n<p>def sin_rule_side(a, angle_A, angle_B):<\/p>\n<p>    angle_A = math.radians(angle_A)<\/p>\n<p>    angle_B = math.radians(angle_B)<\/p>\n<p>    b = a * (math.sin(angle_B) \/ math.sin(angle_A))<\/p>\n<p>    return b<\/p>\n<h2><strong>\u5df2\u77e5\u4e00\u8fb9\u53ca\u5176\u5bf9\u89d2\uff0c\u6c42\u53e6\u5916\u4e00\u4e2a\u89d2<\/strong><\/h2>\n<p>def sin_rule_angle(a, b, angle_A):<\/p>\n<p>    angle_A = math.radians(angle_A)<\/p>\n<p>    sin_B = (b * math.sin(angle_A)) \/ a<\/p>\n<p>    angle_B = math.asin(sin_B)<\/p>\n<p>    return math.degrees(angle_B)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e8c\u3001\u5229\u7528\u4e09\u89d2\u51fd\u6570<\/h2>\n<\/p>\n<p><p>\u5229\u7528Python\u7684math\u5e93\uff0c\u53ef\u4ee5\u8f7b\u677e\u8ba1\u7b97\u4e09\u89d2\u51fd\u6570\u503c\uff0c\u4ece\u800c\u89e3\u5404\u79cd\u4e09\u89d2\u5f62\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>1. \u4f7f\u7528math\u5e93<\/h3>\n<\/p>\n<p><p>math\u5e93\u63d0\u4f9b\u4e86\u4e30\u5bcc\u7684\u4e09\u89d2\u51fd\u6570\uff0c\u5305\u62ecsin\u3001cos\u3001tan\u7b49\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u8ba1\u7b97\u89d2\u5ea6\u7684\u6b63\u5f26\u503c<\/strong><\/h2>\n<p>def calculate_sine(angle):<\/p>\n<p>    angle = math.radians(angle)<\/p>\n<p>    return math.sin(angle)<\/p>\n<h2><strong>\u8ba1\u7b97\u89d2\u5ea6\u7684\u4f59\u5f26\u503c<\/strong><\/h2>\n<p>def calculate_cosine(angle):<\/p>\n<p>    angle = math.radians(angle)<\/p>\n<p>    return math.cos(angle)<\/p>\n<h2><strong>\u8ba1\u7b97\u89d2\u5ea6\u7684\u6b63\u5207\u503c<\/strong><\/h2>\n<p>def calculate_tangent(angle):<\/p>\n<p>    angle = math.radians(angle)<\/p>\n<p>    return math.tan(angle)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u89d2\u5ea6\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>\u5728\u4e09\u89d2\u5f62\u8ba1\u7b97\u4e2d\uff0c\u89d2\u5ea6\u8f6c\u6362\u662f\u5e38\u89c1\u64cd\u4f5c\uff0c\u53ef\u4ee5\u4f7f\u7528math\u5e93\u63d0\u4f9b\u7684\u51fd\u6570\u8fdb\u884c\u8f6c\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<h2><strong>\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6<\/strong><\/h2>\n<p>def degrees_to_radians(angle):<\/p>\n<p>    return math.radians(angle)<\/p>\n<h2><strong>\u5f27\u5ea6\u8f6c\u6362\u4e3a\u89d2\u5ea6<\/strong><\/h2>\n<p>def radians_to_degrees(radian):<\/p>\n<p>    return math.degrees(radian)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e09\u3001\u4f7f\u7528Python\u7684SymPy\u5e93<\/h2>\n<\/p>\n<p><p>SymPy\u662fPython\u7684\u4e00\u4e2a\u7b26\u53f7\u6570\u5b66\u5e93\uff0c\u9002\u7528\u4e8e\u9700\u8981\u7b26\u53f7\u8fd0\u7b97\u7684\u573a\u666f\u3002SymPy\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u6765\u89e3\u4e09\u89d2\u5f62\u95ee\u9898\uff0c\u5305\u62ec\u81ea\u52a8\u5316\u516c\u5f0f\u63a8\u5bfc\u548c\u6570\u503c\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><h3>1. \u5b89\u88c5SymPy\u5e93<\/h3>\n<\/p>\n<p><p>\u5728\u5f00\u59cb\u4e4b\u524d\uff0c\u9700\u8981\u5b89\u88c5SymPy\u5e93\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-sh\">pip install sympy<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4f7f\u7528SymPy\u89e3\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><p>\u4f7f\u7528SymPy\u53ef\u4ee5\u7b80\u5316\u4e09\u89d2\u5f62\u89e3\u6cd5\uff0c\u5982\u4f7f\u7528\u7b26\u53f7\u8ba1\u7b97\u4f59\u5f26\u5b9a\u7406\u548c\u6b63\u5f26\u5b9a\u7406\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sympy import symbols, cos, sin, acos, Eq, solve, deg<\/p>\n<h2><strong>\u5b9a\u4e49\u7b26\u53f7<\/strong><\/h2>\n<p>a, b, c, A, B, C = symbols(&#39;a b c A B C&#39;)<\/p>\n<h2><strong>\u4f7f\u7528\u4f59\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6<\/strong><\/h2>\n<p>cos_C = (a&lt;strong&gt;2 + b&lt;\/strong&gt;2 - c2) \/ (2 * a * b)<\/p>\n<p>angle_C = acos(cos_C)<\/p>\n<h2><strong>\u4f7f\u7528\u6b63\u5f26\u5b9a\u7406\u6c42\u8fb9\u957f<\/strong><\/h2>\n<p>sin_A = sin(A)<\/p>\n<p>sin_B = sin(B)<\/p>\n<p>eq = Eq(a \/ sin_A, b \/ sin_B)<\/p>\n<p>sol = solve(eq, b)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>3. \u6570\u503c\u8ba1\u7b97<\/h3>\n<\/p>\n<p><p>SymPy\u4e5f\u652f\u6301\u6570\u503c\u8ba1\u7b97\uff0c\u53ef\u4ee5\u7ed3\u5408\u7b26\u53f7\u8fd0\u7b97\u548c\u6570\u503c\u8ba1\u7b97\u89e3\u51b3\u590d\u6742\u95ee\u9898\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">from sympy import N<\/p>\n<h2><strong>\u6c42\u89d2\u5ea6\u7684\u6570\u503c\u89e3<\/strong><\/h2>\n<p>angle_C_val = N(angle_C.subs({a: 5, b: 7, c: 9}))<\/p>\n<h2><strong>\u6c42\u8fb9\u957f\u7684\u6570\u503c\u89e3<\/strong><\/h2>\n<p>sin_A_val = sin(deg(30))<\/p>\n<p>sol_val = N(sol[0].subs({a: 5, A: sin_A_val}))<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u56db\u3001\u7efc\u5408\u5e94\u7528\u793a\u4f8b<\/h2>\n<\/p>\n<p><h3>1. \u89e3\u4e00\u4e2a\u5177\u4f53\u7684\u4e09\u89d2\u5f62\u95ee\u9898<\/h3>\n<\/p>\n<p><p>\u5047\u8bbe\u5df2\u77e5\u4e09\u89d2\u5f62\u7684\u4e09\u8fb9a=5, b=7, c=9\uff0c\u6c42\u6240\u6709\u89d2\u5ea6\u3002<\/p>\n<\/p>\n<p><h4>\u6b65\u9aa41\uff1a\u4f7f\u7528\u4f59\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6C<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>a = 5<\/p>\n<p>b = 7<\/p>\n<p>c = 9<\/p>\n<p>cos_C = (a&lt;strong&gt;2 + b&lt;\/strong&gt;2 - c2) \/ (2 * a * b)<\/p>\n<p>angle_C = math.degrees(math.acos(cos_C))<\/p>\n<p>print(f&quot;Angle C: {angle_C:.2f} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6b65\u9aa42\uff1a\u4f7f\u7528\u6b63\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6A\u548c\u89d2\u5ea6B<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f7f\u7528\u4f59\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6A<\/p>\n<p>cos_A = (b&lt;strong&gt;2 + c&lt;\/strong&gt;2 - a2) \/ (2 * b * c)<\/p>\n<p>angle_A = math.degrees(math.acos(cos_A))<\/p>\n<p>print(f&quot;Angle A: {angle_A:.2f} degrees&quot;)<\/p>\n<h2><strong>\u6700\u540e\u4e00\u4e2a\u89d2\u5ea6B\u53ef\u4ee5\u901a\u8fc7180\u5ea6\u51cf\u53bb\u5176\u4ed6\u4e24\u4e2a\u89d2\u5ea6\u6c42\u5f97<\/strong><\/h2>\n<p>angle_B = 180 - angle_A - angle_C<\/p>\n<p>print(f&quot;Angle B: {angle_B:.2f} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h3>2. \u4f7f\u7528SymPy\u5e93\u89e3\u4e09\u89d2\u5f62<\/h3>\n<\/p>\n<p><h4>\u6b65\u9aa41\uff1a\u4f7f\u7528SymPy\u5e93\u6c42\u89e3\u89d2\u5ea6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\">from sympy import symbols, cos, acos, deg, N<\/p>\n<h2><strong>\u5b9a\u4e49\u7b26\u53f7<\/strong><\/h2>\n<p>a, b, c, A, B, C = symbols(&#39;a b c A B C&#39;)<\/p>\n<h2><strong>\u4f59\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6C<\/strong><\/h2>\n<p>cos_C = (a&lt;strong&gt;2 + b&lt;\/strong&gt;2 - c2) \/ (2 * a * b)<\/p>\n<p>angle_C = acos(cos_C)<\/p>\n<h2><strong>\u6570\u503c\u8ba1\u7b97<\/strong><\/h2>\n<p>angle_C_val = N(angle_C.subs({a: 5, b: 7, c: 9}))<\/p>\n<p>print(f&quot;Angle C: {angle_C_val:.2f} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>\u6b65\u9aa42\uff1a\u4f7f\u7528SymPy\u5e93\u6c42\u89e3\u5176\u4ed6\u89d2\u5ea6<\/h4>\n<\/p>\n<p><pre><code class=\"language-python\"># \u4f59\u5f26\u5b9a\u7406\u6c42\u89d2\u5ea6A<\/p>\n<p>cos_A = (b&lt;strong&gt;2 + c&lt;\/strong&gt;2 - a2) \/ (2 * b * c)<\/p>\n<p>angle_A = acos(cos_A)<\/p>\n<h2><strong>\u6570\u503c\u8ba1\u7b97<\/strong><\/h2>\n<p>angle_A_val = N(angle_A.subs({a: 5, b: 7, c: 9}))<\/p>\n<p>print(f&quot;Angle A: {angle_A_val:.2f} degrees&quot;)<\/p>\n<h2><strong>\u6700\u540e\u4e00\u4e2a\u89d2\u5ea6B\u901a\u8fc7180\u5ea6\u51cf\u53bb\u5176\u4ed6\u4e24\u4e2a\u89d2\u5ea6\u6c42\u5f97<\/strong><\/h2>\n<p>angle_B_val = 180 - angle_A_val - angle_C_val<\/p>\n<p>print(f&quot;Angle B: {angle_B_val:.2f} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h2>\u4e94\u3001\u603b\u7ed3<\/h2>\n<\/p>\n<p><p>\u5229\u7528Python\u89e3\u4e09\u89d2\u5f62\u53ef\u4ee5\u901a\u8fc7\u591a\u79cd\u65b9\u6cd5\u5b9e\u73b0\uff0c\u5305\u62ec\u4f7f\u7528\u57fa\u672c\u6570\u5b66\u516c\u5f0f\u3001\u4e09\u89d2\u51fd\u6570\u4ee5\u53caSymPy\u5e93\u7b49\u3002<strong>\u4f7f\u7528\u4f59\u5f26\u5b9a\u7406\u548c\u6b63\u5f26\u5b9a\u7406\u662f\u89e3\u4e09\u89d2\u5f62\u7684\u57fa\u7840\u65b9\u6cd5<\/strong>\uff0c\u800c<strong>\u7ed3\u5408Python\u7684math\u5e93\u548cSymPy\u5e93\u53ef\u4ee5\u66f4\u9ad8\u6548\u5730\u8fdb\u884c\u8ba1\u7b97<\/strong>\u3002\u901a\u8fc7\u5177\u4f53\u793a\u4f8b\u53ef\u4ee5\u66f4\u597d\u5730\u7406\u89e3\u8fd9\u4e9b\u65b9\u6cd5\u7684\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><p>\u65e0\u8bba\u662f\u7b80\u5355\u7684\u6570\u503c\u8ba1\u7b97\u8fd8\u662f\u590d\u6742\u7684\u7b26\u53f7\u8fd0\u7b97\uff0cPython\u90fd\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u5de5\u5177\u6765\u89e3\u51b3\u5404\u79cd\u4e09\u89d2\u5f62\u95ee\u9898\u3002\u5e0c\u671b\u672c\u6587\u80fd\u591f\u5e2e\u52a9\u4f60\u66f4\u597d\u5730\u7406\u89e3\u548c\u638c\u63e1\u5982\u4f55\u5229\u7528Python\u89e3\u4e09\u89d2\u5f62\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u4f7f\u7528Python\u8ba1\u7b97\u4e09\u89d2\u5f62\u7684\u9762\u79ef\uff1f<\/strong><br \/>\u8981\u8ba1\u7b97\u4e09\u89d2\u5f62\u7684\u9762\u79ef\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d77\u4f26\u516c\u5f0f\u6216\u57fa\u672c\u516c\u5f0f\u3002\u4f7f\u7528\u6d77\u4f26\u516c\u5f0f\uff0c\u9996\u5148\u9700\u8981\u77e5\u9053\u4e09\u89d2\u5f62\u7684\u4e09\u6761\u8fb9\u957f a\u3001b \u548c c\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u6b65\u9aa4\u5b9e\u73b0\uff1a  <\/p>\n<ol>\n<li>\u8ba1\u7b97\u534a\u5468\u957f s = (a + b + c) \/ 2\u3002  <\/li>\n<li>\u4f7f\u7528\u516c\u5f0f\u9762\u79ef = \u221a(s * (s &#8211; a) * (s &#8211; b) * (s &#8211; c)) \u8ba1\u7b97\u9762\u79ef\u3002<br \/>\u53e6\u5916\uff0c\u82e5\u5df2\u77e5\u5e95\u8fb9\u548c\u9ad8\uff0c\u4e5f\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u516c\u5f0f\u9762\u79ef = (\u5e95\u8fb9 * \u9ad8) \/ 2\u3002<\/li>\n<\/ol>\n<p><strong>\u5982\u4f55\u5229\u7528Python\u5224\u65ad\u4e00\u4e2a\u4e09\u89d2\u5f62\u662f\u5426\u6709\u6548\uff1f<\/strong><br \/>\u5224\u65ad\u4e00\u4e2a\u4e09\u89d2\u5f62\u7684\u6709\u6548\u6027\u53ef\u4ee5\u901a\u8fc7\u4e09\u89d2\u5f62\u4e0d\u7b49\u5f0f\u6765\u5b9e\u73b0\uff0c\u5373\u4efb\u610f\u4e24\u8fb9\u4e4b\u548c\u5927\u4e8e\u7b2c\u4e09\u8fb9\u3002\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u4ee3\u7801\u8fdb\u884c\u5224\u65ad\uff1a  <\/p>\n<pre><code class=\"language-python\">def is_valid_triangle(a, b, c):\n    return a + b &gt; c and a + c &gt; b and b + c &gt; a\n<\/code><\/pre>\n<p>\u53ea\u8981\u8f93\u5165\u4e09\u6761\u8fb9\u957f\uff0c\u51fd\u6570\u5c31\u4f1a\u8fd4\u56de\u5e03\u5c14\u503c\uff0c\u6307\u793a\u8be5\u4e09\u89d2\u5f62\u662f\u5426\u6709\u6548\u3002<\/p>\n<p><strong>\u5982\u4f55\u5728Python\u4e2d\u7ed8\u5236\u4e09\u89d2\u5f62\uff1f<\/strong><br \/>\u53ef\u4ee5\u4f7f\u7528Python\u7684\u56fe\u5f62\u5e93\uff0c\u5982Matplotlib\uff0c\u7ed8\u5236\u4e09\u89d2\u5f62\u3002\u901a\u8fc7\u4ee5\u4e0b\u793a\u4f8b\u4ee3\u7801\u5b9e\u73b0\uff1a  <\/p>\n<pre><code class=\"language-python\">import matplotlib.pyplot as plt\n\ndef draw_triangle(vertices):\n    triangle = plt.Polygon(vertices, fill=None, edgecolor=&#39;r&#39;)\n    plt.gca().add_patch(triangle)\n    plt.xlim(-1, 10)\n    plt.ylim(-1, 10)\n    plt.gca().set_aspect(&#39;equal&#39;, adjustable=&#39;box&#39;)\n    plt.grid()\n    plt.show()\n\ndraw_triangle([(1, 1), (5, 1), (3, 4)])\n<\/code><\/pre>\n<p>\u8fd9\u6bb5\u4ee3\u7801\u4f1a\u7ed8\u5236\u4e00\u4e2a\u901a\u8fc7\u7ed9\u5b9a\u9876\u70b9\u5750\u6807\u5b9a\u4e49\u7684\u4e09\u89d2\u5f62\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5229\u7528Python\u89e3\u4e09\u89d2\u5f62\u7684\u65b9\u6cd5\u6709\u591a\u79cd\uff0c\u5305\u62ec\u4f7f\u7528\u6570\u5b66\u516c\u5f0f\u3001\u5185\u7f6e\u51fd\u6570\u548c\u5916\u90e8\u5e93\u7b49\u3002\u6838\u5fc3\u89c2\u70b9\u5305\u62ec\uff1a\u4f7f\u7528\u4e09\u89d2\u5f62\u57fa\u672c\u516c\u5f0f\u3001 [&hellip;]","protected":false},"author":3,"featured_media":1125992,"comment_status":"closed","ping_status":"","sticky":false,"template":"","format":"standard","meta":{"_acf_changed":false,"footnotes":""},"categories":[37],"tags":[],"acf":[],"_links":{"self":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1125983"}],"collection":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts"}],"about":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/types\/post"}],"author":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/users\/3"}],"replies":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/comments?post=1125983"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1125983\/revisions"}],"predecessor-version":[{"id":1125993,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1125983\/revisions\/1125993"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1125992"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1125983"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1125983"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1125983"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}