# Eclipse SUMO, Simulation of Urban MObility; see https://eclipse.dev/sumo1# Copyright (C) 2008-2025 German Aerospace Center (DLR) and others.2# This program and the accompanying materials are made available under the3# terms of the Eclipse Public License 2.0 which is available at4# https://www.eclipse.org/legal/epl-2.0/5# This Source Code may also be made available under the following Secondary6# Licenses when the conditions for such availability set forth in the Eclipse7# Public License 2.0 are satisfied: GNU General Public License, version 28# or later which is available at9# https://www.gnu.org/licenses/old-licenses/gpl-2.0-standalone.html10# SPDX-License-Identifier: EPL-2.0 OR GPL-2.0-or-later1112# @file rmsd.py13# @author Daniel Krajzewicz14# @author Michael Behrisch15# @date 2008-03-311617from __future__ import absolute_import18from __future__ import print_function1920from numpy import array, dot, shape, transpose21from numpy.linalg import det, svd222324def superpose(nodes1, nodes2, select1, select2):25vecs1 = array(nodes1)[array(select1)]26vecs2 = array(nodes2)[array(select2)]27print(vecs1, vecs2)2829n_vec, vec_size = shape(vecs1)30center1 = sum(vecs1, 0) / float(n_vec)31center2 = sum(vecs2, 0) / float(n_vec)32vecs1 -= center133vecs2 -= center23435V, S, W_trans = svd(dot(transpose(vecs2), vecs1))3637is_reflection = (det(V) * det(W_trans)) < 0.038if is_reflection:39V[-1, :] = V[-1, :] * (-1.0)4041optimal_rotation = dot(V, W_trans)42return dot(array(nodes2) - center2, optimal_rotation) + center14344# a = [ (1,1), (4,4), (1,4) ]45# b = [ (0,3), (3,0), (3,3), (5,5) ]4647# print superpose(a, b, (0,1,2), (0,1,2))484950