From c1e2c714820b09d9ee748f01489d34ebe68431af Mon Sep 17 00:00:00 2001 From: Jared Miller Date: Sat, 27 Dec 2025 11:41:09 -0500 Subject: [PATCH] Add an example notebook --- .gitignore | 1 + notebook.ipynb | 193 +++++++++++++++++++++++++++++++++++++++++++++++++ 2 files changed, 194 insertions(+) create mode 100644 notebook.ipynb diff --git a/.gitignore b/.gitignore index e69de29..87620ac 100644 --- a/.gitignore +++ b/.gitignore @@ -0,0 +1 @@ +.ipynb_checkpoints/ diff --git a/notebook.ipynb b/notebook.ipynb new file mode 100644 index 0000000..5085e10 --- /dev/null +++ b/notebook.ipynb @@ -0,0 +1,193 @@ +{ + "cells": [ + { + "cell_type": "markdown", + "metadata": {}, + "source": [ + "# perspective projection\n", + "\n", + "```\n", + "x' = x / z\n", + "y' = y / z\n", + "```\n", + "\n", + "divide by distance. that's it." + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# a cube: 8 vertices, 12 edges\n", + "\n", + "vertices = [\n", + " (-1, -1, -1),\n", + " ( 1, -1, -1),\n", + " ( 1, 1, -1),\n", + " (-1, 1, -1),\n", + " (-1, -1, 1),\n", + " ( 1, -1, 1),\n", + " ( 1, 1, 1),\n", + " (-1, 1, 1),\n", + "]\n", + "\n", + "edges = [\n", + " (0, 1), (1, 2), (2, 3), (3, 0), # front\n", + " (4, 5), (5, 6), (6, 7), (7, 4), # back\n", + " (0, 4), (1, 5), (2, 6), (3, 7), # connecting\n", + "]\n", + "\n", + "print(f\"{len(vertices)} vertices, {len(edges)} edges\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# the formula\n", + "\n", + "def project(x, y, z):\n", + " return (x / z, y / z)\n", + "\n", + "# example: a point at (2, 1, 4)\n", + "x, y, z = 2, 1, 4\n", + "x_proj, y_proj = project(x, y, z)\n", + "\n", + "print(f\"3d point: ({x}, {y}, {z})\")\n", + "print(f\"2d projection: ({x_proj}, {y_proj})\")\n", + "print(f\"\\nfarther away = smaller on screen\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# static cube\n", + "\n", + "from IPython.display import HTML\n", + "\n", + "HTML(\"\"\"\n", + "\n", + "\n", + "\"\"\")" + ] + }, + { + "cell_type": "code", + "execution_count": null, + "metadata": {}, + "outputs": [], + "source": [ + "# spinning cube\n", + "\n", + "from IPython.display import HTML\n", + "\n", + "HTML(\"\"\"\n", + "\n", + "\n", + "\"\"\")" + ] + } + ], + "metadata": { + "kernelspec": { + "display_name": "Python 3", + "language": "python", + "name": "python3" + }, + "language_info": { + "name": "python", + "version": "3.11.0" + } + }, + "nbformat": 4, + "nbformat_minor": 4 +}