{ "cells": [ { "cell_type": "markdown", "metadata": {}, "source": [ "# Multi-Object Queries" ] }, { "cell_type": "code", "execution_count": 13, "metadata": {}, "outputs": [], "source": [ "from geo3d.query import distance_between_points, minimize_points_to_points_distance, distances_plane_to_points\n", "from geo3d import Point, Plane, Vector" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Point-to-Point Distance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The distance between points can be queried as " ] }, { "cell_type": "code", "execution_count": 14, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "3.0" ] }, "execution_count": 14, "metadata": {}, "output_type": "execute_result" } ], "source": [ "pointA = Point([1,2,3])\n", "pointB = Point([1,2,6])\n", "distance_between_points(pointA, pointB)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Plane-to-Points Distance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "The distance from a plane to an array of points, positive along the plane normal vector." ] }, { "cell_type": "code", "execution_count": 29, "metadata": {}, "outputs": [ { "data": { "text/plain": [ "array([-3., -6.])" ] }, "execution_count": 29, "metadata": {}, "output_type": "execute_result" } ], "source": [ "plane = Plane(\n", " normal=Vector([0,0,-1]), \n", " point=Point([1,2,0])\n", ")\n", "points = [[1,2,3], [1,2,6]]\n", "distances_plane_to_points(plane, points)" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "## Transformation minimizing group-to-group distance" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "For two point groups, find the transformation -- applied to the first group -- that minimizes the RMS distance between the corresponding points in the two groups:" ] }, { "cell_type": "markdown", "metadata": {}, "source": [ "Here, we extract a rotation of 90 degrees between the point groups, that is, `groupA` needs to be rotated by 90 degrees to coincide with `groupB`." ] }, { "cell_type": "code", "execution_count": 8, "metadata": {}, "outputs": [ { "data": { "text/html": [ "\n", " \n", " \n", " \n", " \n", " \n", " \n", " \n", "
rotation matrixFixed angles
(xyz, extr., deg.)
Euler angles
(xyz, intr., deg.)
translation
-0.00000000-1.000000000.00000000
1.00000000-0.00000000-0.00000000
0.000000000.000000001.00000000
θx0.00000
θy-0.00000
θz90.00000
θx0.00000
θy0.00000
θz90.00000
x0.00000
y0.00000
z0.00000
" ], "text/plain": [ "" ] }, "execution_count": 8, "metadata": {}, "output_type": "execute_result" } ], "source": [ "groupA = [[1,0,0], [0,1,0], [-1,0,0], [0,-1,0], [0,0,1], [0,0,-1]]\n", "groupB = [[0,1,0], [-1,0,0], [0,-1,0], [1,0,0], [0,0,1], [0,0,-1]]\n", "minimize_points_to_points_distance(groupA, groupB)" ] } ], "metadata": { "kernelspec": { "display_name": "py3", "language": "python", "name": "py3" }, "language_info": { "codemirror_mode": { "name": "ipython", "version": 3 }, "file_extension": ".py", "mimetype": "text/x-python", "name": "python", "nbconvert_exporter": "python", "pygments_lexer": "ipython3", "version": "3.8.5" } }, "nbformat": 4, "nbformat_minor": 4 }