How to Modify points and Rotate an point cloud object?

Questions related to plugins development
Post Reply
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

How to Modify points and Rotate an point cloud object?

Post by CCNewbieL6 »

Hello, It is me again.

As the title shown, I want to change the xyz value of a point cloud object.
And I want to rotate the object.

Code: Select all

ccPointCloud pc;
pc.addPoint(CCVector3(x, y, z));
......
// at here, I want to change the xyz value of pc.
I have read a former post(Move mesh in plugin), in which I saw a method that "to apply a 4x4 transformation matrix" to move a mesh.
I guess that the principles to move a mesh and to rotate a point cloud by matrix are same.
But, Now, I am confused that how to create such a matrix. For examlple, if I want to rotate the 'pc' 90 degrees around the x-axis, what should I do?
daniel
Site Admin
Posts: 7382
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to Modify points and Rotate an point cloud object?

Post by daniel »

Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: How to Modify points and Rotate an point cloud object?

Post by CCNewbieL6 »

Thank you, Daniel!
I got it. To rotate a point cloud object or a mesh:

Code: Select all

#include <cmath>

ccPointCloud pc;                              // pc is  a point cloud. 
pc.addPoint(CCVector3(x, y, z));       // add a point
......                                               // here, we can add some more points

CCVector3 axis3dx(1, 0, 0);              // rotate around the x-axis
CCVector3 axis3dy(0, 1, 0);              // rotate around the y-axis
CCVector3 axis3dz(0, 0, 1);              // rotate around the z-axis
CCVector3 t3d(0, 0, 0);                    // translation along the x, y or z axis. here I did not do any translation, so keep the value zero.

// create the matrices
ccGLMatrix matrx;                           // matrix-rotate-x
ccGLMatrix matry;
ccGLMatrix matrz;

// the first parameter is the rotation angle (in radians)
matrx.initFromParameters(M_PI / 3, axis3dx, t3d);  //rotate 60 degrees around the x-axis and no translation
matry.initFromParameters(M_PI / 2, axis3dy, t3d);   //rotate 90 degrees around the y-axis and no translation
matrz.initFromParameters(M_PI     , axis3dz, t3d);   //rotate 180 degrees around the z-axis and no translation
pc.rotateGL(matrx);                        // apply
pc.rotateGL(matry);
pc.rotateGL(matrz);
pc.redrawDisplay();                         //redraw Display
pc.applyGLTransformation_recursive(); //apply
Above is what I understand. If there is something wrong, please point out it.
Last edited by CCNewbieL6 on Thu Apr 22, 2021 2:39 am, edited 1 time in total.
daniel
Site Admin
Posts: 7382
Joined: Wed Oct 13, 2010 7:34 am
Location: Grenoble, France
Contact:

Re: How to Modify points and Rotate an point cloud object?

Post by daniel »

I believe to actually rotate (change) the coordinates, you should call 'applyGLTransformation_recursive' at the end.
Daniel, CloudCompare admin
CCNewbieL6
Posts: 23
Joined: Wed Jan 27, 2021 11:11 am

Re: How to Modify points and Rotate an point cloud object?

Post by CCNewbieL6 »

Yes, it is necessary.
Post Reply