Code covered by the BSD License  

Highlights from
3D Rotation about Shifted Axis

5.0 | 4 ratings Rate this file 58 Downloads (last 30 days) File Size: 2.49 KB File ID: #30864

3D Rotation about Shifted Axis


Matt J


26 Mar 2011 (Updated )

Computes/applies rotation about arbitrary 3D line.

| Watch this File

File Information

Generates the roto-translation matrix for the rotation around an arbitrary line in 3D. The line need not pass through the origin. Optionally, also, applies this transformation to a list of 3D coordinates.
   u, x0: 3D vectors specifying the line in parametric form x(t)=x0+t*u
          Default for x0 is [0,0,0] corresponding to pure rotation (no shift).
          If x0=[] is passed as input, this is also equivalent to passing x0=[0,0,0].
   deg: The counter-clockwise rotation about the line in degrees. Counter-clockwise is defined using the
        right hand rule in reference to the direction of u.
  M: A 4x4 affine transformation matrix representing
     the roto-translation. Namely, M will have the form
                  M=[R,t;0 0 0 1]
      where R is a 3x3 rotation and t is a 3x1 translation vector.
Same as Syntax 1 except that R and t are returned as separate arguments.
This syntax requires 4 input arguments be specified,
    [XYZnew, R, t] = AxelRot(XYZold, deg, u, x0)
where the columns of the 3xN matrix XYZold specify a set of N point coordinates in 3D space. The output XYZnew is the transformation of the columns of XYZold, i.e., the original coordinates rotated appropriately about the axis. All other input/output arguments have the same meanings as before.

MATLAB release MATLAB 7.11 (R2010b)
Tags for This File   Please login to tag files.
Please login to add a comment or rating.
Comments and Ratings (19)
12 Aug 2014 Matt J

Matt J

Not sure I understand your question. You can rototranslate one or more 3D column vectors using SYNTAX 3 of the routine.

Comment only
12 Aug 2014 Michael


How could you modify this code to rotate/translate a 3D velocity vector instead of just a coordinate frame?

Comment only
31 Mar 2014 Sagar


23 Jul 2012 Alan Jennings

Alan Jennings

Good work. I'd recomend adding the copyright restrictions to the source code to keep them together.

13 Jun 2012 Matt J

Matt J

Hi Florian,

I don't/can't know why you're getting a different result from your CAD software, but I'm pretty convinced that P3_CATIA is incorrect.

One check you can do is to find the perpendicular projection of the different points onto the rotation axis, as with the code below. They should all agree, but I get a significant discrepancy for prj_CATIA

axproj=@(z) u*(u\(z-x0))+x0;


Once you've computed the perpendicular projection it's also easy to verify the angular separation between P3_old and P3new_1, as with the code below. I get 5 degrees to very high precision



Comment only
13 Jun 2012 Florian


Hi Matt,

thanks for the code. But I've a little problem.

I tried to use your function with this points

P1 = [33.319 -862.139 420.373]
P2 = [550.303 -721.267 667.915]

P3 = [113 -870.591 483.66]

%% Variablendeklaration
deg = -5;
k = [P1(1,1) P2(1,1)
P1(1,2) P2(1,2)
P1(1,3) P2(1,3) ];
x0 = [P1(1,1);P1(1,2);P1(1,3)];
x1 = [P2(1,1);P2(1,2);P3(1,3)];
u = x1 - x0;

%% test
P3_old = [P3(1,1);P3(1,2);P3(1,3)]


[P3new_1, R, t] = AxelRot(P3_old, deg, u, x0)

the result is

P3new_1 =


I'm making the same rotation in our CAD software (CATIA)-> I'll get this result


Do you have any idea about the differences?

Comment only
12 Jun 2012 Matt J

Matt J

@insa: I don't know what you mean exactly by a "circular node". Do you mean a single point in 3D space? Is each "node" defined simply by an (x,y,z) coordinate triple which you want to rotate to a different location? If so, this is a straightforward application of SYNTAX 3 of the tool and you shouldn't have any problem.

Comment only
12 Jun 2012 insa lyon

insa lyon

Dear Mr.Matt J,
simply, we have a circular nodes lying on xy plane, i want to rotate theses nodes with a specific angle and get the rotated circular points and their coordinates ??what do you think?

Comment only
08 Jun 2012 Matt J

Matt J

Hmmm. No, I guess not. It's sounding less and less like a rigid transformation.

Comment only
08 Jun 2012 insa lyon

insa lyon

Dear Mr.Matt J,Thank you for your answer.
Actually, i have a series of '3D circular' coordinates( Nodes) lying on a straight line , this is the initial form.What i need is to propagate every single point(node)through the curved centerline points.
So, the final form i need will be a series of 3D circular coordinates( Nodes)lying on a curved centerline points , these 3D circular coordinates have to be perpendicular on this curved line ,so you think that i can transform those coordinates using SYNTAX 3?
My kind regards,

Comment only
08 Jun 2012 Matt J

Matt J

@insa: your question is unclear to me, I'm afraid. You mean the data you have is a series of 3D coordinates lying on some kind of spiral space curve? If so, you can transform those coordinates using SYNTAX 3.

Comment only
08 Jun 2012 insa lyon

insa lyon

i have the axis of a Cylinder straight,and the curved axis along-that i want to calculate the new curved cylinder withe roto translation?
Do you thing that i can do it ??

06 Mar 2012 Melissa


27 Feb 2012 Matt J

Matt J

@Melissa - finding the axis of your cylinder, if you don't already know it, is a data fitting problem. You should probably pose that question in the Newsgroup, since it doesn't concern this FEX submission directly.

Comment only
27 Feb 2012 Melissa


How do I find a tilted axis so that I can use this?

Comment only
09 Aug 2011 Matt J

Matt J

@Melissa - You can use SYNTAX 3 to undo the tilt in your cylinder, assuming you already know its tilted z-axis, Ztilt. The cylinder becomes untilted when you rotate it about the rotation axis

u=cross(Ztilt/norm(Ztilt), [0 0 1])

by a rotation angle of deg=asind(u).

Comment only
09 Aug 2011 Melissa


Can I use this to take a set of 3d cylinder cartesian coordinates and make a profile of polar coordinates by each slice of the cylinder?
Check this: for more details of what I need.

Comment only
07 Jun 2011 Matt J

Matt J

@pink, you might want to explain to me what you're trying to do. I can't tell what elaboration of the help documentation you're looking for.

Comment only
07 Jun 2011 pink


how to use?

Comment only
30 Mar 2011

Clarified description and help doc only. No new code.

05 Jul 2011

Added option to transform a set of coordinates.

Contact us