{"id":24926839,"url":"https://github.com/jaytwolab/rotating-2d","last_synced_at":"2025-03-28T12:26:28.731Z","repository":{"id":272245559,"uuid":"913060440","full_name":"JayTwoLab/rotating-2d","owner":"JayTwoLab","description":"2D Rotation Algorithm and Example Code. :kr: 2차원 회전 알고리즘과 예제 코드","archived":false,"fork":false,"pushed_at":"2025-01-07T01:07:10.000Z","size":6,"stargazers_count":0,"open_issues_count":0,"forks_count":0,"subscribers_count":1,"default_branch":"main","last_synced_at":"2025-03-28T03:07:34.290Z","etag":null,"topics":[],"latest_commit_sha":null,"homepage":"","language":"Python","has_issues":true,"has_wiki":null,"has_pages":null,"mirror_url":null,"source_name":null,"license":"mit","status":null,"scm":"git","pull_requests_enabled":true,"icon_url":"https://github.com/JayTwoLab.png","metadata":{"files":{"readme":"README.ko.md","changelog":null,"contributing":null,"funding":null,"license":"LICENSE","code_of_conduct":null,"threat_model":null,"audit":null,"citation":null,"codeowners":null,"security":null,"support":null,"governance":null,"roadmap":null,"authors":null,"dei":null,"publiccode":null,"codemeta":null}},"created_at":"2025-01-07T00:32:10.000Z","updated_at":"2025-01-22T01:43:58.000Z","dependencies_parsed_at":"2025-01-13T07:42:02.552Z","dependency_job_id":"52f0e58a-1444-4682-9662-3f41e236a674","html_url":"https://github.com/JayTwoLab/rotating-2d","commit_stats":null,"previous_names":["j2doll/rotating-2d","jaytwolab/rotating-2d"],"tags_count":0,"template":false,"template_full_name":null,"repository_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayTwoLab%2Frotating-2d","tags_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayTwoLab%2Frotating-2d/tags","releases_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayTwoLab%2Frotating-2d/releases","manifests_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories/JayTwoLab%2Frotating-2d/manifests","owner_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners/JayTwoLab","download_url":"https://codeload.github.com/JayTwoLab/rotating-2d/tar.gz/refs/heads/main","host":{"name":"GitHub","url":"https://github.com","kind":"github","repositories_count":246028528,"owners_count":20712038,"icon_url":"https://github.com/github.png","version":null,"created_at":"2022-05-30T11:31:42.601Z","updated_at":"2022-07-04T15:15:14.044Z","host_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub","repositories_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repositories","repository_names_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/repository_names","owners_url":"https://repos.ecosyste.ms/api/v1/hosts/GitHub/owners"}},"keywords":[],"created_at":"2025-02-02T12:53:28.190Z","updated_at":"2025-03-28T12:26:28.708Z","avatar_url":"https://github.com/JayTwoLab.png","language":"Python","funding_links":[],"categories":[],"sub_categories":[],"readme":"# rotating-2d : 2차원(2D) 회전 알고리즘과 예제 코드\n\n\u003e [English](README.md) , [Korean](README.ko.md) \n\n## 회전 공식\n\n- **회전 전 좌표**: (x, y)\n- **회전 후 좌표**: (x', y')\n- **회전 중심점**: (cx, cy)\n- **회전 각도**: θ (라디안 단위)\n\n### 회전 후 좌표 계산\n```\nx' = cos(θ) * (x - cx) - sin(θ) * (y - cy) + cx\ny' = sin(θ) * (x - cx) + cos(θ) * (y - cy) + cy\n```\n\n---\n\n## 예제 코드\n\n```python\nimport math\nimport matplotlib.pyplot as plt\n\ndef rotate_point(x, y, cx, cy, angle):\n    \"\"\"점 (x, y)를 중심점 (cx, cy)를 기준으로 angle만큼 회전\"\"\"\n    radians = math.radians(angle)\n    cos_theta = math.cos(radians)\n    sin_theta = math.sin(radians)\n    x_new = cos_theta * (x - cx) - sin_theta * (y - cy) + cx\n    y_new = sin_theta * (x - cx) + cos_theta * (y - cy) + cy\n    return x_new, y_new\n\ndef rotate_rectangle(rect, cx, cy, angle):\n    \"\"\"사각형의 모든 점을 회전\"\"\"\n    return [rotate_point(x, y, cx, cy, angle) for x, y in rect]\n\n# 사각형 초기 좌표 (시작점: 좌상단, 시계 방향)\nrectangle = [(1, 3), (4, 3), (4, 1), (1, 1)]\ncenter = (2.5, 2)  # 회전 중심\nangle = 45  # 회전 각도 (도)\n\n# 사각형 회전\nrotated_rectangle = rotate_rectangle(rectangle, *center, angle)\n\n# 시각화\ndef plot_rectangle(rect, label, color):\n    x, y = zip(*rect + [rect[0]])  # 사각형 닫기 위해 첫 점 추가\n    plt.plot(x, y, marker='o', label=label, color=color)\n\nplt.figure()\nplot_rectangle(rectangle, 'Original', 'blue')\nplot_rectangle(rotated_rectangle, 'Rotated', 'red')\n\nplt.scatter(*center, color='green', label='Center', zorder=5)\nplt.legend()\nplt.gca().set_aspect('equal', adjustable='box')\nplt.grid(True)\nplt.title(f\"Rectangle Rotation (Angle: {angle}°)\")\nplt.show()\n```\n\n---\n\n## 코드 설명\n\n1. **`rotate_point` 함수**: 주어진 점을 중심점 기준으로 회전시킵니다.\n2. **`rotate_rectangle` 함수**: 사각형의 네 꼭짓점을 모두 회전시킵니다.\n3. **Matplotlib 시각화**: 원래 사각형(파란색)과 회전된 사각형(빨간색)을 그립니다.\n4. **회전 중심점**: 초록색 점으로 표시됩니다. 위 코드에서 회전 각도의 기준은 0도이며, 반시계 방향으로 회전합니다.\n\n### 참고 사항\n\n- 반시계 방향으로 회전하려면 각도를 양수로 설정합니다.\n- 시계 방향으로 회전하려면 각도를 음수로 설정하거나, `rotate_point` 함수에서 음수 각도를 사용합니다.\n\n---\n\n### 실행 결과\n\n45도 회전된 사각형이 원래 사각형과 함께 그려지며, 회전 변환이 시각적으로 확인됩니다.\n\n\u003cimg width=\"50%\" src=\"https://raw.githubusercontent.com/gist/j2doll/21ef880fa165e1a3f12393c11c333b89/raw/92000f1a3ba555bdda1585c7e74d7b23f0cba2d9/Figure_1.svg\" /\u003e\n","project_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaytwolab%2Frotating-2d","html_url":"https://awesome.ecosyste.ms/projects/github.com%2Fjaytwolab%2Frotating-2d","lists_url":"https://awesome.ecosyste.ms/api/v1/projects/github.com%2Fjaytwolab%2Frotating-2d/lists"}