{ "cells": [ { "cell_type": "markdown", "id": "0cd50cf6", "metadata": {}, "source": [ "# Some Basics" ] }, { "cell_type": "code", "execution_count": 1, "id": "ff42de68", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:39.860650Z", "iopub.status.busy": "2026-08-05T19:41:39.860445Z", "iopub.status.idle": "2026-08-05T19:41:43.596215Z", "shell.execute_reply": "2026-08-05T19:41:43.595350Z" } }, "outputs": [], "source": [ "import os\n", "import sys\n", "\n", "sys.path.insert(0, os.path.abspath(\"..\"))\n", "\n", "import numpy as np\n", "\n", "import geoclide as gc" ] }, { "cell_type": "markdown", "id": "01cc681b", "metadata": {}, "source": [ "## Create a point and a vector" ] }, { "cell_type": "code", "execution_count": 2, "id": "0e2af292", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:43.598239Z", "iopub.status.busy": "2026-08-05T19:41:43.597893Z", "iopub.status.idle": "2026-08-05T19:41:43.603320Z", "shell.execute_reply": "2026-08-05T19:41:43.602485Z" } }, "outputs": [ { "data": { "text/plain": [ "(Point(0.0, 0.0, 0.0),\n", " Vector(0.7001400420140049, 0.7001400420140049, 0.140028008402801))" ] }, "execution_count": 2, "metadata": {}, "output_type": "execute_result" } ], "source": [ "p1 = gc.Point(0., 0., 0.) # create a point\n", "# create a vector and normalize it\n", "v1 = gc.normalize(gc.Vector(0.5, 0.5, 0.1))\n", "p1, v1" ] }, { "cell_type": "code", "execution_count": 3, "id": "0cf0d279", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:43.604743Z", "iopub.status.busy": "2026-08-05T19:41:43.604571Z", "iopub.status.idle": "2026-08-05T19:41:43.607945Z", "shell.execute_reply": "2026-08-05T19:41:43.607320Z" } }, "outputs": [ { "data": { "text/plain": [ "1.0" ] }, "execution_count": 3, "metadata": {}, "output_type": "execute_result" } ], "source": [ "v1.length()" ] }, { "cell_type": "markdown", "id": "e72a051a", "metadata": {}, "source": [ "## Create a ray from the created point and vector" ] }, { "cell_type": "code", "execution_count": 4, "id": "570c70eb", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:43.609688Z", "iopub.status.busy": "2026-08-05T19:41:43.609528Z", "iopub.status.idle": "2026-08-05T19:41:43.612786Z", "shell.execute_reply": "2026-08-05T19:41:43.612102Z" } }, "outputs": [ { "data": { "text/plain": [ "r(t) = (0.0, 0.0, 0.0) + t*(0.7001400420140049, 0.7001400420140049, 0.140028008402801) with t ∈ [0,inf[" ] }, "execution_count": 4, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r1 = gc.Ray(o=p1, d=v1)\n", "r1" ] }, { "cell_type": "code", "execution_count": 5, "id": "2908e3f8", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:43.614273Z", "iopub.status.busy": "2026-08-05T19:41:43.614088Z", "iopub.status.idle": "2026-08-05T19:41:43.617405Z", "shell.execute_reply": "2026-08-05T19:41:43.616698Z" } }, "outputs": [ { "data": { "text/plain": [ "Point(5.601120336112039, 5.601120336112039, 1.120224067222408)" ] }, "execution_count": 5, "metadata": {}, "output_type": "execute_result" } ], "source": [ "r1(8)" ] }, { "cell_type": "markdown", "id": "8b901d23", "metadata": {}, "source": [ "## Create a simple triangle mesh composed of 2 triangles" ] }, { "cell_type": "code", "execution_count": 6, "id": "a02102b5", "metadata": { "execution": { "iopub.execute_input": "2026-08-05T19:41:43.618918Z", "iopub.status.busy": "2026-08-05T19:41:43.618751Z", "iopub.status.idle": "2026-08-05T19:41:43.644598Z", "shell.execute_reply": "2026-08-05T19:41:43.643854Z" } }, "outputs": [ { "data": { "text/html": [ "
<xarray.Dataset> Size: 865B\n",
"Dimensions: (xyz: 3, nvertices: 4, ntriangles: 2, p0p1p2: 3, dim_0: 4,\n",
" dim_1: 4)\n",
"Coordinates:\n",
" * xyz (xyz) int64 24B 0 1 2\n",
"Dimensions without coordinates: nvertices, ntriangles, p0p1p2, dim_0, dim_1\n",
"Data variables: (12/18)\n",
" o (xyz) float64 24B 0.0 0.0 0.0\n",
" d (xyz) float64 24B 0.7001 0.7001 0.14\n",
" mint int64 8B 0\n",
" maxt float64 8B inf\n",
" is_intersection bool 1B True\n",
" thit float64 8B 3.571\n",
" ... ...\n",
" vertices (nvertices, xyz) float64 96B -5.0 -5.0 0.0 ... 5.0 5.0 0.0\n",
" faces (ntriangles, p0p1p2) int64 48B 0 1 2 2 3 1\n",
" wto_m (dim_0, dim_1) float64 128B 6.123e-17 0.0 1.0 ... 0.0 1.0\n",
" wto_m_inv (dim_0, dim_1) float64 128B 6.123e-17 0.0 -1.0 ... 0.0 1.0\n",
" otw_m (dim_0, dim_1) float64 128B 6.123e-17 0.0 -1.0 ... 0.0 1.0\n",
" otw_m_inv (dim_0, dim_1) float64 128B 6.123e-17 0.0 1.0 ... 0.0 1.0\n",
"Attributes:\n",
" shape: TriangleMesh\n",
" date: 2026-08-05\n",
" version: 4.0.0\n",
" ntriangles: 2\n",
" nvertices: 4<xarray.DataArray 'phit' (xyz: 3)> Size: 24B\n",
"array([2.5, 2.5, 0.5])\n",
"Coordinates:\n",
" * xyz (xyz) int64 24B 0 1 2\n",
"Attributes:\n",
" type: Point\n",
" description: the x, y and z components of the intersection point