{
"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",
" rotation matrix | \n",
" Fixed angles (xyz, extr., deg.) | \n",
" Euler angles (xyz, intr., deg.) | \n",
" translation
| \n",
"
\n",
" -0.00000000 | -1.00000000 | 0.00000000 | 1.00000000 | -0.00000000 | -0.00000000 | 0.00000000 | 0.00000000 | 1.00000000 |
| θx | 0.00000 | θy | -0.00000 | θz | 90.00000 |
| θx | 0.00000 | θy | 0.00000 | θz | 90.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
}