2

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.

dev93
  • 337
  • 4
  • 14

1 Answers1

1

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

Ilya Popov
  • 3,765
  • 1
  • 17
  • 30
  • OK. I didn't know about the keyword dynamic. That gets me rid of one problem. Is the way I want calculate the symmetric the good one though ? – dev93 Apr 09 '16 at 20:52