Skip to content

Instantly share code, notes, and snippets.

@ChuanyuXue
Last active January 11, 2026 11:46
Show Gist options
  • Select an option

  • Save ChuanyuXue/1f5eff4047acd04b79d09344d2f8b152 to your computer and use it in GitHub Desktop.

Select an option

Save ChuanyuXue/1f5eff4047acd04b79d09344d2f8b152 to your computer and use it in GitHub Desktop.
embedded_md
Display the source blob
Display the rendered blob
Raw
{
"cells": [
{
"cell_type": "markdown",
"id": "b08aa304",
"metadata": {},
"source": [
"Basically given a angle $\\theta \\in [0, 2\\pi)$ we can get the unit vector for direction\n",
" \n",
" $$\n",
" \\begin{aligned}\n",
" & {dir}_x=\\cos (\\theta) \\\\\n",
" & {dir}_y=\\sin (\\theta)\n",
" \\end{aligned}\n",
" $$\n",
" \n",
" And given two points, we can get the direction from $p_1$ to $p_2$ by:\n",
" \n",
" $$\n",
" \\begin{aligned}\n",
" d x & =x_2-x_1 \\\\\n",
" d y & =y_2-y_1 \\\\\n",
" \\text { distance } & =\\sqrt{d x^2+d y^2}\n",
" \\end{aligned}\n",
" $$\n",
" \n",
" To get the direction (unit vector), we divide the difference by the distance:\n",
" \n",
" $$\n",
" \\begin{aligned}\n",
" {dir}_x & =d x / \\text { distance } \\\\\n",
" {dir}_y & =d y / \\text { distance }\n",
" \\end{aligned}\n",
" $$"
]
}
],
"metadata": {
"language_info": {
"name": "python"
}
},
"nbformat": 4,
"nbformat_minor": 5
}
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment