🌟 Building 3D Frame Element Transformation Matrix [T] — Step-by-Step Tutorial with MATLAB Code
- Adisorn O.
- Apr 27
- 3 min read

In structural engineering, when analyzing 3D frames, it’s critical to correctly transform the local stiffness matrix of each element into the global coordinate system.This transformation accounts for both member direction and section rotation (β).
In this blog, we'll walk through:
✅ How to build the transformation matrix [T]✅ A full numerical example (vertical column, β = 90°)✅ MATLAB code for each step
1. 📚 Problem Setup
We are given:
A column element from (0,0,0) to (0,0,3)⇒ Local x'-axis is along global Z-axis.
Section rotation β = 90°.
Our goal:Build the 12×12 transformation matrix [T] for this element.
2. 🛠 Step-by-Step Guide
Step 1: Define local x' vector (element axis)
The local x'-axis is defined from the start node to the end node:
x′=(x2−x1, y2−y1, z2−z1) /L
For our example:
x′=(0,0,3)/3 =(0,0,1)
Thus:
x' = [0, 0, 1]
Step 2: Choose an auxiliary up vector
We usually pick global Z = [0 0 1].But notice here — x' is parallel to global Z! (vertical member).
In this case, we must choose a different auxiliary vector, usually global X:
v_aux = [1 0 0];
This ensures that cross products will not be zero.
Step 3: Build local z' vector
We compute z' as:
z′=normalize(x′×vaux)
Cross product:
cross([0 0 1], [1 0 0]) = [0 1 0]
Normalize:
z' = [0 1 0]
Step 4: Build local y' vector
Now compute y' as:
y′=normalize(z′×x′)/y'
Cross product:
cross([0 1 0], [0 0 1]) = [1 0 0]
Normalize:
y' = [1 0 0]
✅ Now the initial local axes are:
Axis | Vector |
x' | [0 0 1] |
y' | [1 0 0] |
z' | [0 1 0] |
Right-handed system verified!
Step 5: Rotate y' and z' by β = 90°
Since β = 90°, convert to radians:
beta = 90;
beta_rad = beta * pi/180; % = pi/2
Rotation formulas:
y′′=cos(β) y′+sin(β) z′ z′′=−sin(β) y′+cos(β) z′
Since:
cos(90°) = 0
sin(90°) = 1
Thus:
y'' = (0)*y' + (1)*z' = z'
z'' = -(1)*y' + (0)*z' = -y'
Therefore:
✅ New rotated local axes:
Axis | Vector |
x'' | [0 0 1] (same as x') |
y'' | [0 1 0] (was z') |
z'' | [-1 0 0] (negative of y') |
Step 6: Build Λ (Lambda) matrix
Assemble rows:
[Λ]=[0 0 1 0 1 0 −1 0 0] ✅ Λ is 3×3.
Step 7: Build full 12×12 [T] matrix
Expand Λ into block-diagonal:
[T]=blkdiag(Λ,Λ,Λ,Λ) [T] = [Λ 0 0 0 0 Λ 0 0 0 0 Λ 0 0 0 0 Λ ] Λ is 3x3
Thus T is 12×12.
3. 📜 MATLAB Code
Here’s the full MATLAB code for this example:
% Node coordinates
x1 = 0; y1 = 0; z1 = 0;
x2 = 0; y2 = 0; z2 = 3;
beta_deg = 90;
% Step 1: Compute local x'
dx = x2 - x1;
dy = y2 - y1;
dz = z2 - z1;
L = sqrt(dx^2 + dy^2 + dz^2);
x_local = [dx dy dz]/L;
% Step 2: Choose auxiliary vector
if abs(x_local(3)) > 0.99
v_aux = [1 0 0]; % If vertical, use global X
else
v_aux = [0 0 1]; % Otherwise use global Z
end
% Step 3: Compute z'
z_local = cross(x_local, v_aux);
z_local = z_local / norm(z_local);
% Step 4: Compute y'
y_local = cross(z_local, x_local);
y_local = y_local / norm(y_local);
% Step 5: Rotate y' and z' by beta
beta_rad = beta_deg * pi/180;
cosb = cos(beta_rad);
sinb = sin(beta_rad);
y_rot = cosb * y_local + sinb * z_local;
z_rot = -sinb * y_local + cosb * z_local;
% Step 6: Build Lambda
Lambda = [x_local;
y_rot;
z_rot];
% Step 7: Build full T
T = blkdiag(Lambda, Lambda, Lambda, Lambda);
% Display
disp('Lambda =')
disp(Lambda)
disp('T =')
disp(T)
✅ This gives you Lambda and T exactly.
4. 🎯 Conclusion
Building [T] for a 3D frame element correctly requires:
Handling vertical elements properly (special auxiliary vector)
Applying β rotation carefully
Expanding Λ into T correctly
Once [T] is ready, you can transform stiffness, displacements, and forces between local and global coordinates.
✨ Final Tip
Always check orthogonality:
dot(x_local, y_rot)
dot(x_local, z_rot)
dot(y_rot, z_rot)
All of these should be near zero to confirm that your local axes are orthogonal.
🔥 Now You Can Build Any [T] Matrix!
You now fully understand how structural software like SAP2000, ETABS, and ANSYS internally build the transformation matrices for frame elements.