Question

Using CGAL, how to determine the coordinates of a point from one system to another? Suppose we have:

Point p1(1.0, 1.0, 1.0);  

which is expressed in the typical coordinate system determined by the vectors:

Vector vx1(1.0, 0.0, 0.0);  
Vector vy1(0.0, 1.0, 0.0);  
Vector vz1(0.0, 0.0, 1.0);  

representing the coordinate axis. Now taking the vectors of the coordinate axis of another system, how do I determine the coordinates of p1 in that system?

Vector vx2(1.0, -1.0, -1.0);  
Vector vy2(-1.0, 1.0, -1.0);  
Vector vz2(1.0, 1.0, 0.0);  

I think I must determine a matrix for pass it to an object of CGAL::Aff_transformation_3, but I don't know how.

Vector p2 = p1.transform(??);  

Any tips?

Was it helpful?

Solution

Well, after researching a bit, I found here the theory for the solution to my problem. https://en.wikipedia.org/wiki/Change_of_basis

To clarify a bit, these definitions have built with the purpose of making the code more understandable.

typedef CGAL::Cartesian<long double>   KC;

typedef KC::Point_3                    Point;
typedef KC::Vector_3                   Vector;
typedef CGAL::Aff_transformation_3<KC> Transform3;

After considering the above, built the affine transformation as follows:

Transform3 tr3(
    vx2.x(), vx2.y(), vx2.z(),
    vy2.x(), vy2.y(), vy2.z(),
    vz2.x(), vz2.y(), vz2.z());

Then, with this transform object, I can get the coordinates of a point in the desired system:

Point p1_out = p1.transform (tr3);

Thanks!

OTHER TIPS

You have a vector p1 in basis B1 and you are looking for a vector p2 in basis B2 that is a solution of:

M*p2=p1

with M matrix of change of basis from B1 to B2. The rows of M are the coordinates of the vectors of the basis B2 in the basis B1. Hence you have to invert M and multiplicate it for p1 to find p2:

p2=M^-1 * p1

If you want to use CGAL::Aff_transformation_3, you have to use a Class_2<Kernel> geometric objects, for example Point_3 and Vector_3:

typedef CGAL::Cartesian<double> K;

and in the main() function:

K::Vector_3 vx2(1.0, -1.0, -1.0), vy2(-1.0, 1.0, -1.0), vz2(1.0, 1.0, 0.0);
K::Point_3 p1(1.0, 1.0, 1.0);

CGAL::Aff_transformation_3<K> M(vx2.x(),vx2.y(),vx2.z(),vy2.x(), vy2.y(), vy2.z(),vz2.x(), vz2.y(), vz2.z());
K::Point_3 p2=p1.transform(M.inverse());
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top