Skip to main content

Structural comparison of 3D points

Project description

Kearsley algorithm

This module provides a class to perform the Kearsley algorithm for structural comparisons. The class calculates the rotation and translation that minimizes the root mean squared deviations for two sets of 3D points.

Original paper by Simon K. Kearsley: On the orthogonal transformation used for structural comparisons https://doi.org/10.1107/S0108767388010128.

Install

Install the package with:

user@host:~$ pip install kearsley

Usage

Given two sets of 3D points u and v:

>>> u, v = read_data()
>>> u
array([[0, 0, 0],
       [0, 0, 1],
       [0, 0, 2],
       ...,
       [9, 9, 7],
       [9, 9, 8],
       [9, 9, 9]])
>>> v
array([[ 30.50347534, -20.16089091,  -7.42752623],
       [ 30.77704903, -21.02339348,  -7.27823201],
       [ 31.3215374 , -21.99452332,  -7.15703548],
       ...,
       [ 42.05988643, -23.50924264, -15.59516355],
       [ 42.27217891, -24.36478643, -15.59064995],
       [ 42.66080502, -25.27318759, -15.386241  ]])

It is possible to calculate the rotation and translation that minimize the root mean squared deviation:

>>> from kearsley import Kearsley
>>> k = Kearsley()
>>> rmsd = k.fit(u, v)
>>> rmsd
0.10003430497284149

The rotation and translation are the attributes of the class:

>>> k.rot.as_matrix()
array([[ 0.05552838, -0.04405506, -0.99748471],
       [ 0.91956342,  0.39147652,  0.03390061],
       [ 0.38899835, -0.9191329 ,  0.06224948]])
>>> k.trans
array([ 30.46560753, -20.15086287,  -7.34422276])

Once fitted you can apply the transformation to v or to other set of points:

>>> v_transform = k.transform(v)
>>> v_transform
array([[ 0.08563846,  0.02807207,  0.01876202],
       [-0.01009153, -0.0529479 ,  0.92722971],
       [-0.05796549,  0.07167779,  2.03917659],
       ...,
       [ 9.0219524 ,  9.067236  ,  7.08333594],
       [ 9.06692944,  8.9276801 ,  7.95255679],
       [ 8.92463409,  8.93635832,  8.95139744]])

It is also possible to fit and transform with one command, in this case the transformation is applied to the second set of points:

>>> v_transform, rmsd = k.fit_transform(u, v)
>>> rmsd
0.10003430497284149
>>> v_transform
array([[ 0.08563846,  0.02807207,  0.01876202],
       [-0.01009153, -0.0529479 ,  0.92722971],
       [-0.05796549,  0.07167779,  2.03917659],
       ...,
       [ 9.0219524 ,  9.067236  ,  7.08333594],
       [ 9.06692944,  8.9276801 ,  7.95255679],
       [ 8.92463409,  8.93635832,  8.95139744]])

The rmsd is the expected:

>>> np.sqrt(np.sum((u - v_transform)**2)/len(u))
0.10003430497298871

There are two attributes:

  • Kearsley.rot: a scipy Rotation instance.
  • Kearsley.trans: a ndarray with shape (3,) with the translation.

Applications

  • Compare a set of measured points with their theoretical positions.
  • In robotics compare two sets of points measured in different coordinate systems and get the transformation between both coordinate systems.
  • It is possible to use it in a 2D space fixing the third coordinate to zero.

Notes

Check Scipy Rotation to have all the info about Rotation instance.

Project details


Download files

Download the file for your platform. If you're not sure which to choose, learn more about installing packages.

Source Distribution

kearsley-0.2.0.tar.gz (5.4 kB view details)

Uploaded Source

Built Distribution

If you're not sure about the file name format, learn more about wheel file names.

kearsley-0.2.0-py3-none-any.whl (6.5 kB view details)

Uploaded Python 3

File details

Details for the file kearsley-0.2.0.tar.gz.

File metadata

  • Download URL: kearsley-0.2.0.tar.gz
  • Upload date:
  • Size: 5.4 kB
  • Tags: Source
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.13.0-44-generic

File hashes

Hashes for kearsley-0.2.0.tar.gz
Algorithm Hash digest
SHA256 b84b84a35714cec34e554a454db214bbf6ae557034b33cb78456de1005da5bd2
MD5 5fd58965f5c2b0fe7c7eb427e06102d3
BLAKE2b-256 f5e5cdd233927289edd8d0fafb14a9c311e7aadf8392b943cf64c996afaa0466

See more details on using hashes here.

File details

Details for the file kearsley-0.2.0-py3-none-any.whl.

File metadata

  • Download URL: kearsley-0.2.0-py3-none-any.whl
  • Upload date:
  • Size: 6.5 kB
  • Tags: Python 3
  • Uploaded using Trusted Publishing? No
  • Uploaded via: poetry/1.1.13 CPython/3.8.10 Linux/5.13.0-44-generic

File hashes

Hashes for kearsley-0.2.0-py3-none-any.whl
Algorithm Hash digest
SHA256 08a85070f43f822a9c26ca501a37f4593fc14fa65b4ca8040836859de6f2b804
MD5 dc6a2986e0d466880b30143267f9438b
BLAKE2b-256 8efa4b41504dbfd9626b23bc1e9c6966004be35ef75cf53e4fe53a54f2a16137

See more details on using hashes here.

Supported by

AWS Cloud computing and Security Sponsor Datadog Monitoring Depot Continuous Integration Fastly CDN Google Download Analytics Pingdom Monitoring Sentry Error logging StatusPage Status page