Skip to content

Instantly share code, notes, and snippets.

@dsaint31x
Created July 10, 2023 14:28
Show Gist options
  • Save dsaint31x/39ed6932d46e4a862fe9ac733bff7af8 to your computer and use it in GitHub Desktop.
Save dsaint31x/39ed6932d46e4a862fe9ac733bff7af8 to your computer and use it in GitHub Desktop.
math_atan2.ipynb
Display the source blob
Display the rendered blob
Raw
{
"nbformat": 4,
"nbformat_minor": 0,
"metadata": {
"colab": {
"provenance": [],
"authorship_tag": "ABX9TyPVS038IrB/Wg3YYiD3unVb",
"include_colab_link": true
},
"kernelspec": {
"name": "python3",
"display_name": "Python 3"
},
"language_info": {
"name": "python"
}
},
"cells": [
{
"cell_type": "markdown",
"metadata": {
"id": "view-in-github",
"colab_type": "text"
},
"source": [
"<a href=\"https://colab.research.google.com/gist/dsaint31x/39ed6932d46e4a862fe9ac733bff7af8/math_atan2.ipynb\" target=\"_parent\"><img src=\"https://colab.research.google.com/assets/colab-badge.svg\" alt=\"Open In Colab\"/></a>"
]
},
{
"cell_type": "code",
"execution_count": 1,
"metadata": {
"id": "UmOEuoY_EVo4"
},
"outputs": [],
"source": [
"import math"
]
},
{
"cell_type": "code",
"source": [
"def ds_deg(y,x):\n",
" r = math.atan2(y,x)\n",
" r = math.degrees(r)\n",
" if r<0:\n",
" r = 360+r\n",
" return round(r,4)"
],
"metadata": {
"id": "EhYSFjhPGzyg"
},
"execution_count": 31,
"outputs": []
},
{
"cell_type": "code",
"source": [
"angles = [0, 30, 45, 60, 90, 120, 135, 150, 180, 210, 225, 240, 270, 300, 315, 340, 360]\n",
"radians = map(lambda x: x*math.pi/180., angles)\n",
"\n",
"vectors = [ (math.sin(r),math.cos(r)) for r in radians]\n",
"list(map(lambda x: (round(x[0],4),round(x[1],4)),vectors))"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "1vOGG6jPI02V",
"outputId": "44b67d2a-1f28-42ee-b853-996755fc19bb"
},
"execution_count": 57,
"outputs": [
{
"output_type": "execute_result",
"data": {
"text/plain": [
"[(0.0, 1.0),\n",
" (0.5, 0.866),\n",
" (0.7071, 0.7071),\n",
" (0.866, 0.5),\n",
" (1.0, 0.0),\n",
" (0.866, -0.5),\n",
" (0.7071, -0.7071),\n",
" (0.5, -0.866),\n",
" (0.0, -1.0),\n",
" (-0.5, -0.866),\n",
" (-0.7071, -0.7071),\n",
" (-0.866, -0.5),\n",
" (-1.0, -0.0),\n",
" (-0.866, 0.5),\n",
" (-0.7071, 0.7071),\n",
" (-0.342, 0.9397),\n",
" (-0.0, 1.0)]"
]
},
"metadata": {},
"execution_count": 57
}
]
},
{
"cell_type": "code",
"source": [
"for a, v in zip(angles, vectors):\n",
" r = ds_deg(*v)\n",
" print(f'{a} = {r} degrees')"
],
"metadata": {
"colab": {
"base_uri": "https://localhost:8080/"
},
"id": "H9hhMtWsIYHh",
"outputId": "eb0473dc-0b07-456d-9606-df03ba41e2fe"
},
"execution_count": 51,
"outputs": [
{
"output_type": "stream",
"name": "stdout",
"text": [
"0 = 0.0 degrees\n",
"30 = 30.0 degrees\n",
"45 = 45.0 degrees\n",
"60 = 60.0 degrees\n",
"90 = 90.0 degrees\n",
"120 = 120.0 degrees\n",
"135 = 135.0 degrees\n",
"150 = 150.0 degrees\n",
"180 = 180.0 degrees\n",
"210 = 210.0 degrees\n",
"225 = 225.0 degrees\n",
"240 = 240.0 degrees\n",
"270 = 270.0 degrees\n",
"300 = 300.0 degrees\n",
"315 = 315.0 degrees\n",
"340 = 340.0 degrees\n",
"360 = 360.0 degrees\n"
]
}
]
}
]
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment