Registered Member
|
Hi,
It's been ages, but I'm trying to finish porting Avogadro to Eigen3. Benoit wrote some nice code to rotate a molecule (basically a 3D point cloud) using the best-fit hyperplane: Vector3d ** atomPositions = new Vector3d*[nAtoms]; // Calculate the center of the molecule too foreach (Atom *atom, m_atomList) { Vector3d *pos = &(*m_atomPos)[atom->id()]; d->center += *pos; atomPositions[i++] = pos; } d->center /= static_cast<double>(nAtoms); Eigen::Hyperplane<double, 3> planeCoeffs; Eigen::fitHyperplane(numAtoms(), atomPositions, &planeCoeffs); delete[] atomPositions; d->normalVector = planeCoeffs.normal(); Is there already some easy migration path for this (i.e., fitting a Hyperplane from a set of points)? Thanks, -Geoff |
Moderator
|
The main problem of the deprecated fitHyperplane function was that its API was not generic enough. Anyway, hyperplane fitting is not complicated:
You can also directly use eig.eigenvectors() as a 3x3 rotation matrix to align your molecule. If the data are too far away from the origin, you also directly compute the covariance matrix as follows:
|
Registered users: bartoloni, Bing [Bot], Google [Bot], Yahoo [Bot]