{
 "cells": [
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "# 08. Spatial and Geometric Analysis\n\nMeasure the distance between two points and the overlap between two rooms.\n\n**Goal:** Complete one small workflow. Run the cells from top to bottom in a fresh kernel.\n\n**Extra dependencies:** None beyond the base environment.\n\nAll examples use metres unless stated otherwise.\n",
   "id": "tutorial-08-00"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "import os\nos.environ[\"TOPOLOGICPY_CORE_BACKEND\"] = \"pythonocc\"\n\nimport topologicpy\nfrom topologicpy.Core import Core\n\nassert topologicpy.__version__ == \"0.9.86\", \"Use TopologicPy 0.9.86 for these tutorials.\"\nassert type(Core.Backend()).__name__ == \"PythonOCCBackend\", \"Restart with the pythonocc backend.\"\nprint(\"TopologicPy\", topologicpy.__version__, \"—\", type(Core.Backend()).__name__)\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-08-01"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Measure distance\n\nCoordinates here are in metres. TopologicPy does not infer units from the numbers.\n",
   "id": "tutorial-08-02"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "from topologicpy.Vertex import Vertex\nfrom topologicpy.Cell import Cell\nfrom topologicpy.Topology import Topology\n\nentrance = Vertex.ByCoordinates(0, 0, 0)\ndesk = Vertex.ByCoordinates(3, 4, 0)\ndistance = Vertex.Distance(entrance, desk)\nprint(\"Straight-line distance:\", distance, \"m\")\nassert distance == 5\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-08-03"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Measure overlap\n\nAn intersection returns the shared region. This pair overlaps by 2 × 3 × 2 metres.\n",
   "id": "tutorial-08-04"
  },
  {
   "cell_type": "code",
   "metadata": {},
   "source": "room_a = Cell.Prism(width=4, length=3, height=2)\nroom_b = Topology.Translate(room_a, x=2)\noverlap = Topology.Intersect(room_a, room_b)\nprint(\"Overlap volume:\", Cell.Volume(overlap), \"m³\")\nassert abs(Cell.Volume(overlap) - 12) < 0.0001\n",
   "outputs": [],
   "execution_count": null,
   "id": "tutorial-08-05"
  },
  {
   "cell_type": "markdown",
   "metadata": {},
   "source": "## Try it yourself\n\nMove the second room by 3 metres and predict its overlap volume.\n",
   "id": "tutorial-08-06"
  }
 ],
 "metadata": {
  "kernelspec": {
   "display_name": "Python 3 (TopologicPy tutorials)",
   "language": "python",
   "name": "python3"
  },
  "language_info": {
   "name": "python",
   "version": "3.12"
  }
 },
 "nbformat": 4,
 "nbformat_minor": 5
}
