Question about 3D point intersection
3 views (last 30 days)
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.
Any advice would be appreciated!
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 ) ;
% - 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' ) ;
xlabel( 'x' ) ; ylabel( 'y' ) ; zlabel( 'z' ) ;
set( gca, 'CameraPosition', [10, 5, 10] ) ;
This code outputs
More Answers (1)
Matt J on 19 May 2014
See also this rotation tool
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.