Book a Demo!
CoCalc Logo Icon
StoreFeaturesDocsShareSupportNewsAboutPoliciesSign UpSign In
eclipse
GitHub Repository: eclipse/sumo
Path: blob/main/tools/lib/rmsd.py
169673 views
1
# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo
2
# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.
3
# This program and the accompanying materials are made available under the
4
# terms of the Eclipse Public License 2.0 which is available at
5
# https://www.eclipse.org/legal/epl-2.0/
6
# This Source Code may also be made available under the following Secondary
7
# Licenses when the conditions for such availability set forth in the Eclipse
8
# Public License 2.0 are satisfied: GNU General Public License, version 2
9
# or later which is available at
10
# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html
11
# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later
12
13
# @file rmsd.py
14
# @author Daniel Krajzewicz
15
# @author Michael Behrisch
16
# @date 2008-03-31
17
18
from __future__ import absolute_import
19
from __future__ import print_function
20
21
from numpy import array, dot, shape, transpose
22
from numpy.linalg import det, svd
23
24
25
def superpose(nodes1, nodes2, select1, select2):
26
vecs1 = array(nodes1)[array(select1)]
27
vecs2 = array(nodes2)[array(select2)]
28
print(vecs1, vecs2)
29
30
n_vec, vec_size = shape(vecs1)
31
center1 = sum(vecs1, 0) / float(n_vec)
32
center2 = sum(vecs2, 0) / float(n_vec)
33
vecs1 -= center1
34
vecs2 -= center2
35
36
V, S, W_trans = svd(dot(transpose(vecs2), vecs1))
37
38
is_reflection = (det(V) * det(W_trans)) < 0.0
39
if is_reflection:
40
V[-1, :] = V[-1, :] * (-1.0)
41
42
optimal_rotation = dot(V, W_trans)
43
return dot(array(nodes2) - center2, optimal_rotation) + center1
44
45
# a = [ (1,1), (4,4), (1,4) ]
46
# b = [ (0,3), (3,0), (3,3), (5,5) ]
47
48
# print superpose(a, b, (0,1,2), (0,1,2))
49
50