# Question about 3D point intersection

3 views (last 30 days)
Brian on 16 May 2014
Edited: Matt J on 19 May 2014
Hello, thank you for reading this,
I'm having trouble performing a centroid rotation of a 3D geometry. My data consists of 3D points, and what I want to do is rotate it along its center.
I have the data contained in a Nx3 matrix, where N is my number of points with three column entries for the x, y and z ccordiante respectively. I can rotate it around the origin by multiplying these points by the x, y and z rotation matrices, but the problem is with the rotation comes an extreme translation as well. I want to rotate it along its averaged x, y and z midpoint, so any translation I do doesn't come with a heavy translation of the coordinates.
I looked at some material, but everything I found was for 2D images. I tried applying it to my 3D collection of points, but was unsuccessful. I tried following this as well:
as it was the closest I can find, but I'm using a 3D geometry, and rotate3d doesn't work the same way as far as I could tell.
##### 2 CommentsShowHide 1 older comment
Brian on 19 May 2014
Looking now, blimey it looks complicated at first glance. After watching a few tutorials, it still looks complicated, but manageable.
Thanks!

Cedric Wannaz on 17 May 2014
Edited: Cedric Wannaz on 19 May 2014
As suggested by Image Analyst, I am moving my comment here. A good method for rotating points in the 3D space is to use quaternions [ ref, ref ]. I've not used them in a long, long time, so I couldn't recommend a recent, specific resource for learning. However, it is a pretty popular topic, so we find quite a bit of information online. Basically, one advantage of using quaternions over using Euler angles is that the former eliminate a problem named gimbal lock.
I used quaternions with Sysquake and I am unsure how best to use them in MATLAB; there are a few FEX resources, e.g. by Mark Ticknell which includes two demos or a C/MEX version by Steven Michael, .. yet, I have to admit that I don't understand why there is no built-in support in MATLAB base package.
EDIT: here is a basic example, based on FEX/qrot3d. Note that you have to compile it, which means that you have to install a compiler first if not already done.
>> mex -setup
follow the link, install e.g. Windows SDK, relaunch mex -setup and select the SDK when done. Then compile qrot3d:
>> mex qrot3d.c
When done, you have a working qrot3d!
figure(1) ; clf ; hold on ; grid on ;
set( gcf, 'Color', 0.9*[1, 1, 1] ) ;
% - Define data = profile in the x-z plan.
zp = linspace( -10 , 10, 100 ).' ;
xp = 4 + sin( zp/2 ) ;
yp = zeros( size( xp )) ;
data = [xp, yp, zp] ;
% - Rotate profile around z axis.
nHat = [0, 0, 1] ;
for theta = linspace( 0, 3*pi/2, 10 )
quat = [cos(theta/2), sin(theta/2) * nHat] ;
dataRot = qrot3d( data, quat ) ;
plot3( dataRot(:,1), dataRot(:,2), dataRot(:,3), 'b', 'LineWidth', 3 ) ;
end
% - Just for fun, add levels.
alpha = linspace( 0, 3*pi/2, 100 ) ;
for zId = 1 : 2 : 100
xCircle = xp(zId) * cos( alpha ) ;
yCircle = xp(zId) * sin( alpha ) ;
zCircle = zp(zId) * ones( size( alpha )) ;
plot3( xCircle, yCircle, zCircle, 'b' ) ;
end
xlabel( 'x' ) ; ylabel( 'y' ) ; zlabel( 'z' ) ;
set( gca, 'CameraPosition', [10, 5, 10] ) ;
This code outputs
##### 2 CommentsShowHide 1 older comment
Brian on 19 May 2014
Thanks again for this, this is a really great example. I have a working interim measure, it will probably take a day or so of pushing my nose against MATLAB to fully understand whats going on here.
What I'm doing in the meantime is the following:
([Mesh points]-[avgx avgy avgz]) * rotationx,y,z + [avgx avgy avgz];
By doing this, I'm still using a euclidean rotation, I'm just translating the mesh to the origin such that the centroid is at [0 0 0]. Then I do my rotation, then translate it back to the centroid it was at. This way, I still have to do the translation, but I can avoid my earlier problem.

Matt J on 19 May 2014
No idea, though, what you mean by rotation about a point. That is ill-defined, since there are infinite rotation axes passing through any given point.
##### 2 CommentsShowHide 1 older comment
Matt J on 19 May 2014
The rotation tool at my link allows you to specify a translated axis around which to rotate. No need to translate manually.
Of course, you need to know what axis you want to rotate about and it's still not clear that you do, since you are still speaking of "rotation around a point", which has no clear definition... Rotation in 3D always has to be about an axis, not a point.