{"id":1019303,"date":"2024-12-27T12:56:19","date_gmt":"2024-12-27T04:56:19","guid":{"rendered":"https:\/\/docs.pingcode.com\/ask\/ask-ask\/1019303.html"},"modified":"2024-12-27T12:56:33","modified_gmt":"2024-12-27T04:56:33","slug":"python-%e5%a6%82%e4%bd%95%e8%a1%a8%e7%a4%ba360%e5%ba%a6","status":"publish","type":"post","link":"https:\/\/docs.pingcode.com\/ask\/1019303.html","title":{"rendered":"python \u5982\u4f55\u8868\u793a360\u5ea6"},"content":{"rendered":"<p style=\"text-align:center;\" ><img decoding=\"async\" src=\"https:\/\/cdn-kb.worktile.com\/kb\/wp-content\/uploads\/2024\/04\/25161824\/63efa8cc-9847-4301-ba80-423ff065a6ef.webp\" alt=\"python \u5982\u4f55\u8868\u793a360\u5ea6\" \/><\/p>\n<p><p> <strong>\u5728Python\u4e2d\uff0c360\u5ea6\u53ef\u4ee5\u901a\u8fc7\u6570\u5b57\u3001\u6570\u5b66\u51fd\u6570\u3001numpy\u5e93\u7b49\u591a\u79cd\u65b9\u5f0f\u6765\u8868\u793a\u3001\u5728\u8ba1\u7b97\u4e2d\uff0c360\u5ea6\u901a\u5e38\u8868\u793a\u4e00\u4e2a\u5b8c\u6574\u7684\u5706\u5468\uff0c\u7528\u4e8e\u89d2\u5ea6\u8ba1\u7b97\u3001\u4e09\u89d2\u51fd\u6570\u7b49\u5e94\u7528\u4e2d\u3002\u5728Python\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u4ee5\u4e0b\u51e0\u79cd\u65b9\u5f0f\u6765\u8868\u793a360\u5ea6\uff1a<\/strong><\/p>\n<\/p>\n<p><p>\u9996\u5148\uff0c\u76f4\u63a5\u4f7f\u7528\u6570\u5b57360\u6765\u8868\u793a\u3002\u8fd9\u662f\u6700\u7b80\u5355\u7684\u65b9\u5f0f\uff0c\u9002\u7528\u4e8e\u9700\u8981\u76f4\u63a5\u8868\u793a\u89d2\u5ea6\u7684\u573a\u5408\uff0c\u6bd4\u5982\u5728\u51e0\u4f55\u8ba1\u7b97\u548c\u56fe\u5f62\u7ed8\u5236\u4e2d\u3002\u5176\u6b21\uff0c\u53ef\u4ee5\u4f7f\u7528math\u5e93\u4e2d\u7684\u5e38\u91cf\u548c\u51fd\u6570\u6765\u8f6c\u6362\u548c\u8ba1\u7b97\u89d2\u5ea6\u3002\u6bd4\u5982\uff0c\u901a\u8fc7\u5c06360\u5ea6\u8f6c\u5316\u4e3a\u5f27\u5ea6\u8868\u793a\uff0c\u56e0\u4e3aPython\u7684\u4e09\u89d2\u51fd\u6570\u5982sin\u3001cos\u7b49\u662f\u57fa\u4e8e\u5f27\u5ea6\u5236\u7684\u3002\u5728Python\u4e2d\uff0c1\u5ea6\u7b49\u4e8e\u03c0\/180\u5f27\u5ea6\uff0c\u56e0\u6b64360\u5ea6\u7b49\u4e8e2\u03c0\u5f27\u5ea6\u3002\u6700\u540e\uff0cnumpy\u5e93\u63d0\u4f9b\u4e86\u66f4\u9ad8\u6548\u7684\u6570\u7ec4\u8fd0\u7b97\u529f\u80fd\uff0c\u4e5f\u53ef\u4ee5\u7528\u4e8e\u5904\u7406\u89d2\u5ea6\u76f8\u5173\u7684\u8ba1\u7b97\u3002\u5728numpy\u4e2d\uff0c\u53ef\u4ee5\u901a\u8fc7numpy.deg2rad()\u51fd\u6570\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u4ece\u800c\u65b9\u4fbf\u5730\u8fdb\u884c\u6570\u5b66\u8ba1\u7b97\u3002<\/p>\n<\/p>\n<p><p>\u63a5\u4e0b\u6765\uff0c\u6211\u5c06\u8be6\u7ec6\u4ecb\u7ecd\u5176\u4e2d\u7684\u4e00\u79cd\u65b9\u6cd5\uff1a\u4f7f\u7528math\u5e93\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><h3>\u4e00\u3001\u4f7f\u7528\u6570\u5b66\u5e93\u8fdb\u884c\u89d2\u5ea6\u8f6c\u6362<\/h3>\n<\/p>\n<p><p>Python\u4e2d\u7684math\u5e93\u63d0\u4f9b\u4e86\u4e00\u7cfb\u5217\u6570\u5b66\u51fd\u6570\u548c\u5e38\u91cf\uff0c\u53ef\u4ee5\u7528\u4e8e\u5404\u79cd\u6570\u5b66\u8ba1\u7b97\u3002\u5bf9\u4e8e\u89d2\u5ea6\u8f6c\u6362\uff0cmath\u5e93\u63d0\u4f9b\u4e86\u4e00\u4e2a\u91cd\u8981\u7684\u5e38\u91cf\uff1api\uff08\u03c0\uff09\uff0c\u4ee5\u53ca\u76f8\u5173\u7684\u51fd\u6570\u3002<\/p>\n<\/p>\n<p><h4>1. \u89d2\u5ea6\u4e0e\u5f27\u5ea6\u4e4b\u95f4\u7684\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u79d1\u5b66\u4e2d\uff0c\u89d2\u5ea6\u901a\u5e38\u6709\u4e24\u79cd\u8868\u793a\u65b9\u5f0f\uff1a\u5ea6\u6570\u548c\u5f27\u5ea6\u3002\u5ea6\u6570\u662f\u6211\u4eec\u65e5\u5e38\u751f\u6d3b\u4e2d\u5e38\u7528\u7684\u89d2\u5ea6\u5355\u4f4d\uff0c\u800c\u5f27\u5ea6\u5219\u662f\u6570\u5b66\u548c\u7f16\u7a0b\u4e2d\u66f4\u5e38\u7528\u7684\u5355\u4f4d\u3002Python\u7684\u6570\u5b66\u51fd\u6570\uff08\u4f8b\u5982sin\u3001cos\u3001tan\u7b49\uff09\u9ed8\u8ba4\u4f7f\u7528\u5f27\u5ea6\u4f5c\u4e3a\u89d2\u5ea6\u5355\u4f4d\u3002\u56e0\u6b64\uff0c\u5728\u4f7f\u7528\u8fd9\u4e9b\u51fd\u6570\u65f6\uff0c\u6211\u4eec\u9700\u8981\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\u3002<\/p>\n<\/p>\n<p><p>\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\u7684\u516c\u5f0f\u4e3a\uff1a<\/p>\n<\/p>\n<p><p>[ \\text{\u5f27\u5ea6} = \\text{\u5ea6\u6570} \\times \\frac{\\pi}{180} ]<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528math\u5e93\u4e2d\u7684math.radians()\u51fd\u6570\u6765\u8fdb\u884c\u8f6c\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>degrees = 360<\/p>\n<p>radians = math.radians(degrees)<\/p>\n<p>print(f&quot;{degrees} degrees is {radians} radians&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u5f27\u5ea6\u4e0e\u5ea6\u6570\u4e4b\u95f4\u7684\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>\u5982\u679c\u6211\u4eec\u9700\u8981\u5c06\u5f27\u5ea6\u8f6c\u6362\u4e3a\u5ea6\u6570\uff0c\u53ef\u4ee5\u4f7f\u7528\u4ee5\u4e0b\u516c\u5f0f\uff1a<\/p>\n<\/p>\n<p><p>[ \\text{\u5ea6\u6570} = \\text{\u5f27\u5ea6} \\times \\frac{180}{\\pi} ]<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0cmath\u5e93\u4e5f\u63d0\u4f9b\u4e86math.degrees()\u51fd\u6570\u6765\u8fdb\u884c\u5f27\u5ea6\u5230\u5ea6\u6570\u7684\u8f6c\u6362\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>radians = 2 * math.pi<\/p>\n<p>degrees = math.degrees(radians)<\/p>\n<p>print(f&quot;{radians} radians is {degrees} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528math\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u65b9\u4fbf\u5730\u5728\u5ea6\u6570\u548c\u5f27\u5ea6\u4e4b\u95f4\u8fdb\u884c\u8f6c\u6362\uff0c\u4ece\u800c\u5728\u7f16\u5199\u7a0b\u5e8f\u65f6\u66f4\u52a0\u7075\u6d3b\u5730\u5904\u7406\u89d2\u5ea6\u95ee\u9898\u3002<\/p>\n<\/p>\n<p><h3>\u4e8c\u3001\u4f7f\u7528NumPy\u5e93\u8fdb\u884c\u89d2\u5ea6\u8fd0\u7b97<\/h3>\n<\/p>\n<p><p>NumPy\u662fPython\u4e2d\u975e\u5e38\u6d41\u884c\u7684\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u63d0\u4f9b\u4e86\u5f3a\u5927\u7684\u6570\u7ec4\u548c\u77e9\u9635\u5904\u7406\u529f\u80fd\u3002\u5728\u5904\u7406\u89d2\u5ea6\u8fd0\u7b97\u65f6\uff0cNumPy\u4e5f\u63d0\u4f9b\u4e86\u76f8\u5e94\u7684\u51fd\u6570\u6765\u7b80\u5316\u64cd\u4f5c\u3002<\/p>\n<\/p>\n<p><h4>1. \u4f7f\u7528NumPy\u8fdb\u884c\u89d2\u5ea6\u8f6c\u6362<\/h4>\n<\/p>\n<p><p>NumPy\u63d0\u4f9b\u4e86numpy.deg2rad()\u548cnumpy.rad2deg()\u51fd\u6570\uff0c\u5206\u522b\u7528\u4e8e\u5c06\u5ea6\u6570\u8f6c\u6362\u4e3a\u5f27\u5ea6\u548c\u5c06\u5f27\u5ea6\u8f6c\u6362\u4e3a\u5ea6\u6570\u3002\u8fd9\u4e9b\u51fd\u6570\u53ef\u4ee5\u76f4\u63a5\u4f5c\u7528\u4e8e\u6570\u7ec4\uff0c\u652f\u6301\u6279\u91cf\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>degrees_array = np.array([0, 90, 180, 270, 360])<\/p>\n<p>radians_array = np.deg2rad(degrees_array)<\/p>\n<p>print(f&quot;Degrees: {degrees_array}&quot;)<\/p>\n<p>print(f&quot;Radians: {radians_array}&quot;)<\/p>\n<h2><strong>\u53cd\u5411\u8f6c\u6362<\/strong><\/h2>\n<p>degrees_converted = np.rad2deg(radians_array)<\/p>\n<p>print(f&quot;Converted back to degrees: {degrees_converted}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><h4>2. \u4f7f\u7528NumPy\u8fdb\u884c\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97<\/h4>\n<\/p>\n<p><p>NumPy\u7684\u4e09\u89d2\u51fd\u6570\uff08\u5982numpy.sin(), numpy.cos(), numpy.tan()\u7b49\uff09\u4e5f\u57fa\u4e8e\u5f27\u5ea6\u8fdb\u884c\u8ba1\u7b97\uff0c\u56e0\u6b64\u53ef\u4ee5\u76f4\u63a5\u5c06\u5f27\u5ea6\u6570\u7ec4\u4f20\u5165\u8fdb\u884c\u8fd0\u7b97\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>radians_array = np.array([0, np.pi\/2, np.pi, 3*np.pi\/2, 2*np.pi])<\/p>\n<p>sin_values = np.sin(radians_array)<\/p>\n<p>cos_values = np.cos(radians_array)<\/p>\n<p>print(f&quot;Radians: {radians_array}&quot;)<\/p>\n<p>print(f&quot;Sine values: {sin_values}&quot;)<\/p>\n<p>print(f&quot;Cosine values: {cos_values}&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u901a\u8fc7\u4f7f\u7528NumPy\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u5730\u8fdb\u884c\u6279\u91cf\u89d2\u5ea6\u8f6c\u6362\u548c\u4e09\u89d2\u51fd\u6570\u8fd0\u7b97\uff0c\u975e\u5e38\u9002\u5408\u9700\u8981\u5904\u7406\u5927\u91cf\u6570\u636e\u7684\u79d1\u5b66\u8ba1\u7b97\u548c\u5de5\u7a0b\u5e94\u7528\u3002<\/p>\n<\/p>\n<p><h3>\u4e09\u3001\u5e94\u7528\u573a\u666f\uff1a360\u5ea6\u7684\u8868\u793a\u548c\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u8bb8\u591a\u5b9e\u9645\u5e94\u7528\u4e2d\uff0c360\u5ea6\u7684\u8868\u793a\u548c\u5904\u7406\u5177\u6709\u91cd\u8981\u610f\u4e49\uff0c\u5c24\u5176\u662f\u5728\u56fe\u5f62\u5b66\u3001\u5de5\u7a0b\u8bbe\u8ba1\u3001\u5730\u7406\u4fe1\u606f\u7cfb\u7edf\u7b49\u9886\u57df\u3002<\/p>\n<\/p>\n<p><h4>1. \u56fe\u5f62\u548c\u52a8\u753b\u4e2d\u7684360\u5ea6\u65cb\u8f6c<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u56fe\u5f62\u5b66\u4e2d\uff0c360\u5ea6\u7684\u65cb\u8f6c\u662f\u4e00\u4e2a\u5e38\u89c1\u7684\u64cd\u4f5c\uff0c\u901a\u5e38\u7528\u4e8e\u5bf9\u8c61\u7684\u5168\u65b9\u4f4d\u5c55\u793a\u548c\u52a8\u753b\u6548\u679c\u3002\u5728Python\u4e2d\uff0c\u4f7f\u7528Pygame\u3001OpenGL\u7b49\u5e93\u53ef\u4ee5\u5b9e\u73b0360\u5ea6\u65cb\u8f6c\u6548\u679c\u3002\u4f8b\u5982\uff0c\u5728Pygame\u4e2d\uff0c\u6211\u4eec\u53ef\u4ee5\u901a\u8fc7\u6539\u53d8\u5bf9\u8c61\u7684\u65cb\u8f6c\u89d2\u5ea6\u6765\u5b9e\u73b0\u65cb\u8f6c\u52a8\u753b\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import pygame<\/p>\n<p>import math<\/p>\n<p>pygame.init()<\/p>\n<p>screen = pygame.display.set_mode((400, 300))<\/p>\n<p>clock = pygame.time.Clock()<\/p>\n<h2><strong>\u52a0\u8f7d\u56fe\u50cf<\/strong><\/h2>\n<p>image = pygame.image.load(&#39;your_image.png&#39;)<\/p>\n<p>rect = image.get_rect(center=(200, 150))<\/p>\n<p>angle = 0<\/p>\n<p>running = True<\/p>\n<p>while running:<\/p>\n<p>    for event in pygame.event.get():<\/p>\n<p>        if event.type == pygame.QUIT:<\/p>\n<p>            running = False<\/p>\n<p>    # \u6e05\u5c4f<\/p>\n<p>    screen.fill((0, 0, 0))<\/p>\n<p>    # \u65cb\u8f6c\u56fe\u50cf<\/p>\n<p>    angle += 1<\/p>\n<p>    if angle &gt;= 360:<\/p>\n<p>        angle = 0<\/p>\n<p>    rotated_image = pygame.transform.rotate(image, angle)<\/p>\n<p>    rotated_rect = rotated_image.get_rect(center=rect.center)<\/p>\n<p>    # \u7ed8\u5236\u56fe\u50cf<\/p>\n<p>    screen.blit(rotated_image, rotated_rect.topleft)<\/p>\n<p>    pygame.display.flip()<\/p>\n<p>    clock.tick(60)<\/p>\n<p>pygame.quit()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u8be5\u793a\u4f8b\u5c55\u793a\u4e86\u5982\u4f55\u4f7f\u7528Pygame\u5b9e\u73b0\u56fe\u50cf\u7684360\u5ea6\u65cb\u8f6c\u3002\u901a\u8fc7\u9010\u6e10\u589e\u52a0\u65cb\u8f6c\u89d2\u5ea6\u5e76\u4f7f\u7528Pygame\u7684\u65cb\u8f6c\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5b9e\u73b0\u5e73\u6ed1\u7684\u65cb\u8f6c\u6548\u679c\u3002<\/p>\n<\/p>\n<p><h4>2. \u5730\u7406\u4fe1\u606f\u7cfb\u7edf\u4e2d\u7684\u89d2\u5ea6\u8ba1\u7b97<\/h4>\n<\/p>\n<p><p>\u5728\u5730\u7406\u4fe1\u606f\u7cfb\u7edf\uff08GIS\uff09\u4e2d\uff0c\u89d2\u5ea6\u8ba1\u7b97\u5e38\u7528\u4e8e\u65b9\u5411\u548c\u65b9\u4f4d\u89d2\u7684\u8ba1\u7b97\u3002\u5728\u8fd9\u79cd\u573a\u5408\uff0c360\u5ea6\u901a\u5e38\u7528\u4e8e\u8868\u793a\u4e00\u4e2a\u5b8c\u6574\u7684\u5706\u5468\u3002\u4f8b\u5982\uff0c\u5728\u5bfc\u822a\u7cfb\u7edf\u4e2d\uff0c\u901a\u8fc7\u8ba1\u7b97\u4e24\u4e2a\u5750\u6807\u70b9\u4e4b\u95f4\u7684\u65b9\u4f4d\u89d2\uff0c\u6211\u4eec\u53ef\u4ee5\u786e\u5b9a\u884c\u8fdb\u7684\u65b9\u5411\u3002<\/p>\n<\/p>\n<p><p>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u7ed3\u5408\u5730\u7406\u5750\u6807\u548c\u4e09\u89d2\u51fd\u6570\u8ba1\u7b97\u65b9\u4f4d\u89d2\uff1a<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import math<\/p>\n<p>def calculate_bearing(lat1, lon1, lat2, lon2):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u8ba1\u7b97\u4e24\u4e2a\u5750\u6807\u70b9\u4e4b\u95f4\u7684\u65b9\u4f4d\u89d2<\/p>\n<p>    :param lat1: \u7b2c\u4e00\u4e2a\u70b9\u7684\u7eac\u5ea6<\/p>\n<p>    :param lon1: \u7b2c\u4e00\u4e2a\u70b9\u7684\u7ecf\u5ea6<\/p>\n<p>    :param lat2: \u7b2c\u4e8c\u4e2a\u70b9\u7684\u7eac\u5ea6<\/p>\n<p>    :param lon2: \u7b2c\u4e8c\u4e2a\u70b9\u7684\u7ecf\u5ea6<\/p>\n<p>    :return: \u65b9\u4f4d\u89d2\uff08\u5ea6\u6570\uff09<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    lat1, lon1, lat2, lon2 = map(math.radians, [lat1, lon1, lat2, lon2])<\/p>\n<p>    dlon = lon2 - lon1<\/p>\n<p>    x = math.sin(dlon) * math.cos(lat2)<\/p>\n<p>    y = math.cos(lat1) * math.sin(lat2) - math.sin(lat1) * math.cos(lat2) * math.cos(dlon)<\/p>\n<p>    initial_bearing = math.atan2(x, y)<\/p>\n<p>    initial_bearing = math.degrees(initial_bearing)<\/p>\n<p>    compass_bearing = (initial_bearing + 360) % 360<\/p>\n<p>    return compass_bearing<\/p>\n<p>bearing = calculate_bearing(52.20472, 0.14056, 48.8566, 2.3522)<\/p>\n<p>print(f&quot;Bearing: {bearing} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528\u4e86\u5730\u7406\u5750\u6807\uff08\u7eac\u5ea6\u548c\u7ecf\u5ea6\uff09\u6765\u8ba1\u7b97\u4e24\u4e2a\u70b9\u4e4b\u95f4\u7684\u65b9\u4f4d\u89d2\u3002\u901a\u8fc7\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\u5e76\u5e94\u7528\u4e09\u89d2\u51fd\u6570\uff0c\u6211\u4eec\u53ef\u4ee5\u5f97\u5230\u4ece\u7b2c\u4e00\u4e2a\u70b9\u5230\u7b2c\u4e8c\u4e2a\u70b9\u7684\u65b9\u4f4d\u89d2\u3002<\/p>\n<\/p>\n<p><h3>\u56db\u3001360\u5ea6\u5728\u6570\u5b66\u8ba1\u7b97\u4e2d\u7684\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u6570\u5b66\u8ba1\u7b97\u4e2d\uff0c360\u5ea6\u5e38\u5e38\u7528\u4e8e\u5468\u671f\u6027\u51fd\u6570\u548c\u5bf9\u79f0\u6027\u5206\u6790\u3002\u5b83\u662f\u4e00\u4e2a\u5b8c\u6574\u5468\u671f\u7684\u6807\u5fd7\uff0c\u5c24\u5176\u5728\u6d89\u53ca\u5468\u671f\u6027\u53d8\u5316\u7684\u573a\u5408\u4e2d\u626e\u6f14\u91cd\u8981\u89d2\u8272\u3002<\/p>\n<\/p>\n<p><h4>1. \u5468\u671f\u6027\u51fd\u6570\u4e2d\u7684\u5e94\u7528<\/h4>\n<\/p>\n<p><p>\u5468\u671f\u6027\u51fd\u6570\uff0c\u5982\u6b63\u5f26\u51fd\u6570\u548c\u4f59\u5f26\u51fd\u6570\uff0c\u5176\u5468\u671f\u901a\u5e38\u8868\u793a\u4e3a360\u5ea6\u3002\u8fd9\u610f\u5473\u7740\u51fd\u6570\u7684\u8f93\u51fa\u5728\u6bcf360\u5ea6\u540e\u4f1a\u91cd\u590d\u3002\u8fd9\u79cd\u7279\u6027\u5728\u4fe1\u53f7\u5904\u7406\u548c\u6ce2\u52a8\u5206\u6790\u4e2d\u975e\u5e38\u6709\u7528\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import numpy as np<\/p>\n<p>import matplotlib.pyplot as plt<\/p>\n<h2><strong>\u751f\u6210\u89d2\u5ea6\u6570\u7ec4<\/strong><\/h2>\n<p>angles = np.linspace(0, 2 * np.pi, 100)<\/p>\n<p>sin_values = np.sin(angles)<\/p>\n<p>cos_values = np.cos(angles)<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u5f26\u548c\u4f59\u5f26\u51fd\u6570<\/strong><\/h2>\n<p>plt.plot(np.rad2deg(angles), sin_values, label=&#39;sin&#39;)<\/p>\n<p>plt.plot(np.rad2deg(angles), cos_values, label=&#39;cos&#39;)<\/p>\n<p>plt.xlabel(&#39;Angle (degrees)&#39;)<\/p>\n<p>plt.ylabel(&#39;Function value&#39;)<\/p>\n<p>plt.title(&#39;Sine and Cosine Functions&#39;)<\/p>\n<p>plt.legend()<\/p>\n<p>plt.grid()<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u4f7f\u7528NumPy\u548cMatplotlib\u5e93\u7ed8\u5236\u4e86\u6b63\u5f26\u548c\u4f59\u5f26\u51fd\u6570\u7684\u56fe\u50cf\u3002\u901a\u8fc7\u5c06\u89d2\u5ea6\u4ece0\u52302\u03c0\uff08\u5373360\u5ea6\uff09\uff0c\u53ef\u4ee5\u89c2\u5bdf\u5230\u51fd\u6570\u7684\u5468\u671f\u6027\u53d8\u5316\u3002<\/p>\n<\/p>\n<p><h4>2. \u5bf9\u79f0\u6027\u5206\u6790<\/h4>\n<\/p>\n<p><p>\u5728\u5bf9\u79f0\u6027\u5206\u6790\u4e2d\uff0c360\u5ea6\u901a\u5e38\u7528\u4e8e\u63cf\u8ff0\u65cb\u8f6c\u5bf9\u79f0\u6027\u3002\u4f8b\u5982\uff0c\u6b63\u591a\u8fb9\u5f62\u7684\u65cb\u8f6c\u5bf9\u79f0\u6027\u53ef\u4ee5\u901a\u8fc7360\u5ea6\u6574\u9664\u8fb9\u6570\u6765\u786e\u5b9a\u3002\u4e00\u4e2a\u6b63\u516d\u8fb9\u5f62\u5177\u67096\u9636\u65cb\u8f6c\u5bf9\u79f0\u6027\uff0c\u6bcf60\u5ea6\u65cb\u8f6c\u4e00\u6b21\u4fbf\u4e0e\u539f\u5f62\u72b6\u91cd\u5408\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">import matplotlib.pyplot as plt<\/p>\n<p>import numpy as np<\/p>\n<h2><strong>\u7ed8\u5236\u6b63\u516d\u8fb9\u5f62<\/strong><\/h2>\n<p>def draw_hexagon(ax, center, size, angle):<\/p>\n<p>    for i in range(6):<\/p>\n<p>        theta = np.deg2rad(i * 60 + angle)<\/p>\n<p>        x = center[0] + size * np.cos(theta)<\/p>\n<p>        y = center[1] + size * np.sin(theta)<\/p>\n<p>        ax.plot([center[0], x], [center[1], y], &#39;b-&#39;)<\/p>\n<p>fig, ax = plt.subplots()<\/p>\n<p>ax.set_aspect(&#39;equal&#39;)<\/p>\n<p>ax.set_xlim(-2, 2)<\/p>\n<p>ax.set_ylim(-2, 2)<\/p>\n<h2><strong>\u7ed8\u5236\u521d\u59cb\u516d\u8fb9\u5f62<\/strong><\/h2>\n<p>draw_hexagon(ax, (0, 0), 1, 0)<\/p>\n<h2><strong>\u7ed8\u5236\u65cb\u8f6c\u540e\u7684\u516d\u8fb9\u5f62<\/strong><\/h2>\n<p>for i in range(1, 6):<\/p>\n<p>    draw_hexagon(ax, (0, 0), 1, i * 60)<\/p>\n<p>plt.title(&#39;Rotational Symmetry of a Hexagon&#39;)<\/p>\n<p>plt.show()<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7\u7ed8\u5236\u591a\u4e2a\u65cb\u8f6c\u540e\u7684\u6b63\u516d\u8fb9\u5f62\u5c55\u793a\u4e86\u5176\u65cb\u8f6c\u5bf9\u79f0\u6027\u3002\u6bcf\u6b21\u65cb\u8f6c60\u5ea6\uff0c\u516d\u8fb9\u5f62\u7684\u5f62\u72b6\u4e0e\u539f\u59cb\u5f62\u72b6\u91cd\u5408\uff0c\u4f53\u73b0\u4e86\u5176\u5bf9\u79f0\u6027\u3002<\/p>\n<\/p>\n<p><h3>\u4e94\u3001\u7f16\u7a0b\u4e2d\u7684360\u5ea6\u5e94\u7528<\/h3>\n<\/p>\n<p><p>\u5728\u7f16\u7a0b\u4e2d\uff0c360\u5ea6\u5e38\u7528\u4e8e\u63a7\u5236\u65cb\u8f6c\u3001\u5904\u7406\u5faa\u73af\u5e8f\u5217\u4ee5\u53ca\u6267\u884c\u91cd\u590d\u6027\u64cd\u4f5c\u3002\u5728\u8fd9\u4e9b\u573a\u5408\u4e2d\uff0c\u89d2\u5ea6\u7684\u8868\u793a\u548c\u8f6c\u6362\u901a\u5e38\u662f\u6838\u5fc3\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><h4>1. \u63a7\u5236\u65cb\u8f6c<\/h4>\n<\/p>\n<p><p>\u5728\u8ba1\u7b97\u673a\u89c6\u89c9\u548c\u673a\u5668\u4eba\u63a7\u5236\u4e2d\uff0c360\u5ea6\u7528\u4e8e\u63a7\u5236\u6444\u50cf\u673a\u548c\u673a\u5668\u4eba\u65cb\u8f6c\u3002\u901a\u8fc7\u8c03\u6574\u65cb\u8f6c\u89d2\u5ea6\uff0c\u53ef\u4ee5\u5b9e\u73b0\u5bf9\u73af\u5883\u7684\u5168\u666f\u626b\u63cf\u548c\u7269\u4f53\u7684\u5b8c\u6574\u89c2\u5bdf\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">class Camera:<\/p>\n<p>    def __init__(self):<\/p>\n<p>        self.angle = 0<\/p>\n<p>    def rotate(self, angle):<\/p>\n<p>        self.angle = (self.angle + angle) % 360<\/p>\n<p>        print(f&quot;Camera rotated to {self.angle} degrees&quot;)<\/p>\n<p>camera = Camera()<\/p>\n<p>camera.rotate(90)<\/p>\n<p>camera.rotate(180)<\/p>\n<p>camera.rotate(270)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u5b9a\u4e49\u4e86\u4e00\u4e2a\u7b80\u5355\u7684Camera\u7c7b\uff0c\u901a\u8fc7rotate\u65b9\u6cd5\u63a7\u5236\u6444\u50cf\u673a\u7684\u65cb\u8f6c\u89d2\u5ea6\u3002\u6bcf\u6b21\u65cb\u8f6c\u540e\uff0c\u6444\u50cf\u673a\u7684\u89d2\u5ea6\u90fd\u4f1a\u66f4\u65b0\u5e76\u4fdd\u6301\u57280\u5230360\u5ea6\u4e4b\u95f4\u3002<\/p>\n<\/p>\n<p><h4>2. \u5faa\u73af\u5e8f\u5217\u5904\u7406<\/h4>\n<\/p>\n<p><p>\u5728\u5faa\u73af\u5e8f\u5217\u5904\u7406\u65f6\uff0c360\u5ea6\u53ef\u4ee5\u7528\u4e8e\u8868\u793a\u5b8c\u6574\u5faa\u73af\u3002\u4f8b\u5982\uff0c\u5728\u5904\u7406\u4e00\u5468\u7684\u65e5\u5386\u65f6\uff0c\u6211\u4eec\u53ef\u4ee5\u5c06\u5929\u6570\u8868\u793a\u4e3a\u89d2\u5ea6\uff0c\u4ee5\u4fbf\u8f7b\u677e\u5730\u8fdb\u884c\u8ba1\u7b97\u548c\u8f6c\u6362\u3002<\/p>\n<\/p>\n<p><pre><code class=\"language-python\">def day_to_angle(day):<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    \u5c06\u661f\u671f\u51e0\u8f6c\u6362\u4e3a\u89d2\u5ea6<\/p>\n<p>    :param day: \u661f\u671f\u51e0\uff080\u8868\u793a\u5468\u65e5\uff0c6\u8868\u793a\u5468\u516d\uff09<\/p>\n<p>    :return: \u89d2\u5ea6\uff08\u5ea6\u6570\uff09<\/p>\n<p>    &quot;&quot;&quot;<\/p>\n<p>    return (day \/ 7) * 360<\/p>\n<p>for day in range(7):<\/p>\n<p>    angle = day_to_angle(day)<\/p>\n<p>    print(f&quot;Day {day} corresponds to {angle} degrees&quot;)<\/p>\n<p><\/code><\/pre>\n<\/p>\n<p><p>\u5728\u8fd9\u4e2a\u793a\u4f8b\u4e2d\uff0c\u901a\u8fc7\u5c06\u4e00\u5468\u7684\u5929\u6570\u8f6c\u6362\u4e3a\u89d2\u5ea6\uff0c\u6211\u4eec\u53ef\u4ee5\u8f7b\u677e\u5730\u8fdb\u884c\u5faa\u73af\u5e8f\u5217\u7684\u5904\u7406\u548c\u5206\u6790\u3002<\/p>\n<\/p>\n<p><h3>\u516d\u3001\u603b\u7ed3\u4e0e\u5c55\u671b<\/h3>\n<\/p>\n<p><p>360\u5ea6\u7684\u8868\u793a\u548c\u5e94\u7528\u5728Python\u7f16\u7a0b\u4e2d\u5177\u6709\u5e7f\u6cdb\u7684\u5e94\u7528\u573a\u666f\uff0c\u4ece\u6570\u5b66\u8ba1\u7b97\u3001\u56fe\u5f62\u5904\u7406\u5230\u5de5\u7a0b\u5e94\u7528\uff0c\u5747\u80fd\u770b\u5230\u5176\u8eab\u5f71\u3002\u901a\u8fc7\u7075\u6d3b\u4f7f\u7528Python\u7684\u6570\u5b66\u5e93\u548c\u79d1\u5b66\u8ba1\u7b97\u5e93\uff0c\u6211\u4eec\u53ef\u4ee5\u9ad8\u6548\u5730\u5904\u7406\u4e0e360\u5ea6\u76f8\u5173\u7684\u4efb\u52a1\u3002<\/p>\n<\/p>\n<p><p>\u5728\u672a\u6765\uff0c\u968f\u7740\u8ba1\u7b97\u673a\u79d1\u5b66\u548c\u5de5\u7a0b\u6280\u672f\u7684\u53d1\u5c55\uff0c360\u5ea6\u7684\u5e94\u7528\u5c06\u53d8\u5f97\u66f4\u52a0\u4e30\u5bcc\u3002\u4f8b\u5982\uff0c\u5728\u865a\u62df\u73b0\u5b9e\u548c\u589e\u5f3a\u73b0\u5b9e\u4e2d\uff0c360\u5ea6\u7684\u6c89\u6d78\u5f0f\u4f53\u9a8c\u5c06\u6210\u4e3a\u91cd\u8981\u7684\u7814\u7a76\u65b9\u5411\u3002\u6b64\u5916\uff0c\u5728\u81ea\u52a8\u9a7e\u9a76\u548c\u667a\u80fd\u673a\u5668\u4eba\u4e2d\uff0c360\u5ea6\u7684\u73af\u5883\u611f\u77e5\u548c\u51b3\u7b56\u80fd\u529b\u4e5f\u5c06\u5f97\u5230\u4e0d\u65ad\u63d0\u5347\u3002<\/p>\n<\/p>\n<p><p>\u901a\u8fc7\u4e0d\u65ad\u63a2\u7d22\u548c\u5b9e\u8df5\uff0c\u6211\u4eec\u80fd\u591f\u66f4\u6df1\u5165\u5730\u7406\u89e3\u548c\u5e94\u7528360\u5ea6\u7684\u6982\u5ff5\uff0c\u4ece\u800c\u5728\u5404\u4e2a\u9886\u57df\u4e2d\u5b9e\u73b0\u521b\u65b0\u548c\u7a81\u7834\u3002\u65e0\u8bba\u662f\u5728\u5b66\u672f\u7814\u7a76\u8fd8\u662f\u5b9e\u9645\u9879\u76ee\u4e2d\uff0c360\u5ea6\u7684\u8868\u793a\u548c\u5904\u7406\u90fd\u5c06\u662f\u6211\u4eec\u4e0d\u53ef\u6216\u7f3a\u7684\u5de5\u5177\u3002<\/p>\n<\/p>\n<h2><strong>\u76f8\u5173\u95ee\u7b54FAQs\uff1a<\/strong><\/h2>\n<p> <strong>\u5982\u4f55\u5728Python\u4e2d\u8868\u793a360\u5ea6\u7684\u89d2\u5ea6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u6d6e\u70b9\u6570\u6216\u6574\u6570\u6765\u8868\u793a360\u5ea6\u3002\u4f8b\u5982\uff0c\u53ef\u4ee5\u76f4\u63a5\u4f7f\u7528\u6570\u5b57360\u6765\u8868\u793a\u4e00\u4e2a\u5b8c\u6574\u7684\u5706\u5468\u89d2\u5ea6\u3002\u5728\u8bb8\u591a\u6570\u5b66\u548c\u56fe\u5f62\u5e93\u4e2d\uff0c360\u5ea6\u5e38\u5e38\u7528\u6765\u8868\u793a\u4e00\u4e2a\u5b8c\u6574\u7684\u65cb\u8f6c\u3002<\/p>\n<p><strong>Python\u4e2d\u662f\u5426\u6709\u5e93\u53ef\u4ee5\u5904\u7406\u89d2\u5ea6\u548c\u5f27\u5ea6\u7684\u8f6c\u6362\uff1f<\/strong><br \/>\u662f\u7684\uff0cPython\u7684math\u5e93\u63d0\u4f9b\u4e86\u51fd\u6570\u6765\u5904\u7406\u89d2\u5ea6\u548c\u5f27\u5ea6\u4e4b\u95f4\u7684\u8f6c\u6362\u3002\u4f7f\u7528<code>math.radians()<\/code>\u53ef\u4ee5\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u800c<code>math.degrees()<\/code>\u5219\u53ef\u4ee5\u5c06\u5f27\u5ea6\u8f6c\u6362\u4e3a\u89d2\u5ea6\u3002\u8fd9\u5728\u8fdb\u884c\u4e09\u89d2\u51fd\u6570\u8ba1\u7b97\u65f6\u975e\u5e38\u6709\u7528\u3002<\/p>\n<p><strong>\u5728Python\u4e2d\u5982\u4f55\u7528\u5ea6\u6570\u8868\u793a\u65b9\u5411\u6216\u89d2\u5ea6\uff1f<\/strong><br \/>\u5728Python\u4e2d\uff0c\u53ef\u4ee5\u4f7f\u7528\u5143\u7ec4\u6216\u5217\u8868\u6765\u8868\u793a\u65b9\u5411\uff0c\u4f8b\u5982 <code>(x, y)<\/code> \u7684\u5750\u6807\u5f62\u5f0f\u6765\u8868\u793a\u4e00\u4e2a\u70b9\u7684\u65b9\u5411\u3002\u5bf9\u4e8e\u89d2\u5ea6\uff0c\u53ef\u4ee5\u901a\u8fc7\u4f7f\u7528numpy\u5e93\u7684<code>numpy.deg2rad()<\/code>\u51fd\u6570\u5c06\u89d2\u5ea6\u8f6c\u6362\u4e3a\u5f27\u5ea6\uff0c\u4ee5\u4fbf\u8fdb\u884c\u66f4\u590d\u6742\u7684\u8ba1\u7b97\u548c\u56fe\u5f62\u8868\u793a\u3002<\/p>\n","protected":false},"excerpt":{"rendered":"\u5728Python\u4e2d\uff0c360\u5ea6\u53ef\u4ee5\u901a\u8fc7\u6570\u5b57\u3001\u6570\u5b66\u51fd\u6570\u3001numpy\u5e93\u7b49\u591a\u79cd\u65b9\u5f0f\u6765\u8868\u793a\u3001\u5728\u8ba1\u7b97\u4e2d\uff0c360\u5ea6\u901a\u5e38\u8868\u793a\u4e00\u4e2a [&hellip;]","protected":false},"author":3,"featured_media":1019331,"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\/1019303"}],"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=1019303"}],"version-history":[{"count":"1","href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1019303\/revisions"}],"predecessor-version":[{"id":1019335,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/posts\/1019303\/revisions\/1019335"}],"wp:featuredmedia":[{"embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media\/1019331"}],"wp:attachment":[{"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/media?parent=1019303"}],"wp:term":[{"taxonomy":"category","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/categories?post=1019303"},{"taxonomy":"post_tag","embeddable":true,"href":"https:\/\/docs.pingcode.com\/wp-json\/wp\/v2\/tags?post=1019303"}],"curies":[{"name":"wp","href":"https:\/\/api.w.org\/{rel}","templated":true}]}}