2
votes

I'm using C++ and I want to calculate the symmetric of a point with respect to a hyperplane. I'm in a dimension given at execution time.

I have the points in the hyperplane. So I calculated the normal vector by solving a set of linear equations. Then to get the hyperplane (with the normal and a point), the projection of the first point and finally the symmetric.

I tried using the eigen3 library but it seems it needs the dimension to be given at compile time.

Any idea to solve the problem with this library (or any other one) or a short-cut method are welcome.

Thank you in advance.

1

1 Answers

1
votes

Eigen can work with both compile-time and run-time sizes. To use run-time size, specify Dynamic or use predefined aliases:

Eigen::Matrix<double, Eigen::Dynamic, 1> x(n);

or just

Eigen::VectorXd x(n);

where n is your runtime-specified number of dimensions.

See documentation here


Once you have computed the normal vector and the origin (simply one of your points), you can do this:

#include <Eigen/Core>

using namespace Eigen;

VectorXd mirror(const VectorXd &normal, const VectorXd &origin, const VectorXd &x)
{
    return x - 2.0 * normal * ((x-origin).dot(normal)) / normal.dot(normal);
}

enter image description here