{
"cells": [
{
"cell_type": "markdown",
"metadata": {},
"source": [
"# Basic usage of geo3d"
]
},
{
"cell_type": "code",
"execution_count": 2,
"metadata": {},
"outputs": [],
"source": [
"from geo3d import frame_wizard, Vector, Point, RotationMatrix, Frame, transformation_between_frames"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Frame creation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Manual Frame cration\n",
"Manually create frame from given rotation Euler angles and translation vector."
]
},
{
"cell_type": "code",
"execution_count": 4,
"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.19245009 | 0.41147560 | -0.89087081 | 0.19245009 | 0.87438565 | 0.44543540 | 0.96225045 | -0.25717225 | 0.08908708 |
| θx | -70.89339 | θy | -74.20683 | θz | 45.00000 |
| θx | -78.69007 | θy | -62.98288 | θz | -64.93417 |
| |
"
],
"text/plain": [
""
]
},
"execution_count": 4,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"rot = RotationMatrix.from_euler_angles('xyz', [-70.89339465, -74.20683095, 45], degrees=True)\n",
"vec = Vector([3,4,6])\n",
"Frame(rot,vec)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### The Frame Wizard\n",
"Create two frames using a Frame Wizard (comparable to the one in Spatial Analyzer).\n",
"Frames are defined as transformations starting from a unit frame (no translation and rotation)."
]
},
{
"cell_type": "code",
"execution_count": 5,
"metadata": {},
"outputs": [],
"source": [
"# rotation only from UnitFrame\n",
"fa = frame_wizard(Vector([1, 1, 0]), Vector([1, -1, 0]), \"x\", \"y\", origin=[0, 0, 0])\n",
"# translation only from UnitFrame\n",
"fb = frame_wizard(Vector([1, 0, 0]), Vector([0, 1, 0]), \"x\", \"y\", origin=[1, 1, 4])\n",
"# rotation and translation from UnitFrame\n",
"fc = frame_wizard(Vector([1, 1, 0]), Vector([1, -1, 0]), \"x\", \"y\", origin=[1, 1, 4])"
]
},
{
"cell_type": "code",
"execution_count": 6,
"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.70710678 | 0.70710678 | 0.00000000 | 0.70710678 | -0.70710678 | 0.00000000 | 0.00000000 | -0.00000000 | -1.00000000 |
| θx | 180.00000 | θy | 0.00000 | θz | 45.00000 |
| θx | 180.00000 | θy | 0.00000 | θz | -45.00000 |
| |
"
],
"text/plain": [
""
]
},
"execution_count": 6,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fa"
]
},
{
"cell_type": "code",
"execution_count": 7,
"metadata": {
"tags": []
},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"\n",
"rotation\n",
"[[ 1. -0. 0.]\n",
" [ 0. 1. 0.]\n",
" [ 0. -0. 1.]]\n",
"Fixed angles (xyz, extrinsic, deg.)\n",
"[0. 0. 0.]\n",
"Euler angles (XYZ, intrinsic, deg.)\n",
"[0. 0. 0.]\n",
"translation\n",
"[1 1 4]\n"
]
}
],
"source": [
"print(fb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"They have a rotation and translation component:"
]
},
{
"cell_type": "code",
"execution_count": 8,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
""
],
"text/plain": [
" [1 1 4]"
]
},
"execution_count": 8,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc.translation"
]
},
{
"cell_type": "code",
"execution_count": 9,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"0.70710678 | 0.70710678 | 0.00000000 |
0.70710678 | -0.70710678 | 0.00000000 |
0.00000000 | -0.00000000 | -1.00000000 |
"
],
"text/plain": [
""
]
},
"execution_count": 9,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc.rotation"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The rotation can be expressed as Euler angles."
]
},
{
"cell_type": "code",
"execution_count": 10,
"metadata": {},
"outputs": [
{
"data": {
"text/plain": [
"array([180., 0., 45.])"
]
},
"execution_count": 10,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fc.euler_angles('xyz', degrees='True')"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"### Frame from 4x4 matrix string"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Construct Frame from 4x4 matrix (SA style) "
]
},
{
"cell_type": "code",
"execution_count": 11,
"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.00000003 | 0.00000026 | -1.00000000 | -0.13057024 | -0.99143906 | -0.00000026 | -0.99143906 | 0.13057024 | 0.00000000 |
| θx | 90.00000 | θy | 82.49745 | θz | -89.99998 |
| θx | 89.99689 | θy | -89.99998 | θz | -82.50056 |
| x | 634.99979 | y | 784.03196 | z | 747.50609 |
|
"
],
"text/plain": [
""
]
},
"execution_count": 11,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"frame_from_SA = Frame.from_SA_pastable_string(\n",
" \"0.0000000344 0.0000002614 -1.0000000000 634.9997932029 -0.1305702435 -0.9914390609 -0.0000002637 784.0319609308 -0.9914390609 0.1305702435 0.0000000000 747.5060850385 0.0000000000 0.0000000000 0.0000000000 1.0000000000 \"\n",
")\n",
"frame_from_SA"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Convert Frame back to 4x4 matrix string"
]
},
{
"cell_type": "code",
"execution_count": 12,
"metadata": {},
"outputs": [
{
"name": "stdout",
"output_type": "stream",
"text": [
"0.000000034400 0.000000261400 -1.000000000000 634.999793202900\n",
"-0.130570243500 -0.991439060900 -0.000000263700 784.031960930800\n",
"-0.991439060900 0.130570243500 0.000000000000 747.506085038500\n",
"0.000000000000 0.000000000000 0.000000000000 1.000000000000\n"
]
}
],
"source": [
"print(frame_from_SA.SA_pastable_string())"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Frame to frame transformations "
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"A frame can be expressed in a different frame. "
]
},
{
"cell_type": "code",
"execution_count": 13,
"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.70710678 | 0.70710678 | 0.00000000 | 0.70710678 | -0.70710678 | 0.00000000 | 0.00000000 | 0.00000000 | -1.00000000 |
| θx | 180.00000 | θy | 0.00000 | θz | 45.00000 |
| θx | 180.00000 | θy | 0.00000 | θz | -45.00000 |
| x | 1.41421 | y | 0.00000 | z | -4.00000 |
|
"
],
"text/plain": [
""
]
},
"execution_count": 13,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"fb.express_in_frame(fa)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"This yields the frame-to-frame transformation from fA to fB, represented in fA."
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"The same frame-to-frame transformation matrix, but given in the original (unit) frame is "
]
},
{
"cell_type": "code",
"execution_count": 14,
"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.70710678 | 0.70710678 | 0.00000000 | 0.70710678 | -0.70710678 | 0.00000000 | 0.00000000 | 0.00000000 | -1.00000000 |
| θx | 180.00000 | θy | 0.00000 | θz | 45.00000 |
| θx | 180.00000 | θy | 0.00000 | θz | -45.00000 |
| |
"
],
"text/plain": [
""
]
},
"execution_count": 14,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"transformation_between_frames(fa, fb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"## Expression of vectors and points in frames"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Express a vector given in `original_frame` in a new frame."
]
},
{
"cell_type": "code",
"execution_count": 15,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"x | 2.82843 |
y | -1.41421 |
z | 0.00000 |
"
],
"text/plain": [
" [ 2.82842712 -1.41421356 0. ]"
]
},
"execution_count": 15,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Vector([1,3,0]).express_in_frame(fa, original_frame=fb)"
]
},
{
"cell_type": "markdown",
"metadata": {},
"source": [
"Express a point given in `original_frame` in a new frame."
]
},
{
"cell_type": "code",
"execution_count": 16,
"metadata": {},
"outputs": [
{
"data": {
"text/html": [
"x | 7.07107 |
y | 1.41421 |
z | -24.00000 |
"
],
"text/plain": [
" [ 7.07106781 1.41421356 -24. ]"
]
},
"execution_count": 16,
"metadata": {},
"output_type": "execute_result"
}
],
"source": [
"Point([5,3,20]).express_in_frame(fa, original_frame=fb)"
]
},
{
"cell_type": "code",
"execution_count": null,
"metadata": {},
"outputs": [],
"source": []
}
],
"metadata": {
"interpreter": {
"hash": "57ea3f27e52dfdc96d9f28755cc63ca66b2f983f2e314b87637c890fea88d3b5"
},
"kernelspec": {
"display_name": "Python 3.8.7 64-bit ('gims')",
"language": "python",
"name": "python3"
},
"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.10.0"
}
},
"nbformat": 4,
"nbformat_minor": 2
}