Status: Reference implementation - Python version is production-ready
This directory contains the MATLAB implementation by Gadi Herzlinger of the Grosman 2008 UZY positioning methodology. These scripts are provided for reference and validation purposes. The Python implementation in positioning.py is complete and recommended for production use.
Main orchestration script that implements the complete positioning workflow.
Inputs:
v- Vertex array (Nx3 matrix of XYZ coordinates)f- Face array (Mx3 matrix of vertex indices forming triangles, 1-indexed)
Outputs:
v- Rotated vertex array
Processing Steps:
- Translates mesh to origin (centers it)
- Applies UZY positioning based on inertia tensor (calls
UzyPosCm_for_GUI) - Tests three 90° rotations to find maximum projected area (planform view)
- Re-centers the mesh
- Applies mirror symmetry rotation about Z-axis (calls
Find_Mirror_Sym)
Implements the core UZY (Uzy Smilansky) positioning method from the Grosman 2008 paper.
Inputs:
f- Face arrayv- Vertex array
Outputs:
vr- Rotated verticesnewTtr- Transformation matrix applied
Process:
- Calculates face normals for all triangles
- Computes unit normals and triangle areas
- Calls
Norm2Posing_for_GUIto get transformation matrix based on surface tensor - Applies transformation and checks if inversion is needed (based on center of mass position)
Calculates the transformation matrix based on surface normal distribution.
Inputs:
vn- Unit normal vectors (Nx3)tra- Triangle areas (Nx1)SA- Total surface area (scalar)
Outputs:
Ttr- Transformation matrix (3x3)
Mathematical Method:
- Constructs the surface tensor T where:
T_st = (1/A) * Σ(s_i * n_s^i * n_t^i) - Computes eigenvalues and eigenvectors of the surface tensor
- Eigenvector with largest eigenvalue → perpendicular to major symmetry plane (X-axis)
- Eigenvector with smallest eigenvalue → Z-axis
- Middle eigenvector → Y-axis
- Returns orthogonal transformation matrix
Finds the optimal rotation angle around Z-axis for mirror symmetry.
Inputs:
X,Y- 2D boundary coordinates (outline of object)
Outputs:
ang- Optimal rotation angle (degrees)
Algorithm:
- Rotates the 2D outline through 360° (1° increments)
- For each angle, splits outline into positive/negative X halves
- Mirrors the negative half and compares to positive half
- Calculates distance metric between mirrored and actual halves
- Returns angle that minimizes this distance (best mirror symmetry)
Utility function to compute face normal vectors for triangulated meshes.
Inputs:
f- Face array (Mx3 matrix of vertex indices, 1-indexed)v- Vertex array (Nx3 matrix of XYZ coordinates)
Outputs:
fn- Face normals (Mx3 matrix, magnitude = 2×triangle area)
Note: This function was implemented based on the standard cross-product calculation.
Required inputs:
v- Vertex matrix: Nx3 array where each row is [x, y, z] coordinatesf- Face matrix: Mx3 array where each row contains 3 vertex indices (1-indexed)
Example:
v = [0, 0, 0; % vertex 1
1, 0, 0; % vertex 2
0, 1, 0; % vertex 3
0, 0, 1]; % vertex 4
f = [1, 2, 3; % triangle 1
1, 2, 4; % triangle 2
2, 3, 4; % triangle 3
1, 3, 4]; % triangle 4
v_rotated = positioning(v, f);-
Load your 3D model (using your preferred method to get vertices and faces)
-
Call positioning function:
% Assuming you have v (vertices) and f (faces) v_positioned = positioning(v, f);
-
The script will:
- Display progress with a waitbar
- Return rotated vertices
- Original face indices remain unchanged
% Load mesh (example using PLY format)
[v, f] = read_ply('artifact.ply');
% Apply positioning
v_rotated = positioning(v, f);
% Save or visualize
trimesh(f, v_rotated(:,1), v_rotated(:,2), v_rotated(:,3));
axis equal;- Base MATLAB - Core functionality
- Statistics and Machine Learning Toolbox - For
boundary()function
-
No Error Handling MATLAB scripts lack error checking for:
- Invalid mesh topology (NaN vertices, degenerate triangles)
- Non-manifold geometry
- Empty meshes
-
Coordinate System Assumptions Scripts assume a specific coordinate system orientation. No validation that input meshes conform to expected conventions.
- Mirror Symmetry Search is Brute Force
Find_Mirror_Sym.mtests 360 rotations at 1° increments. Could be optimized with:- Coarser initial search followed by refinement
- Gradient-based optimization
-
No Command-Line Interface MATLAB scripts require manual function calls from the MATLAB environment.
-
Face Indexing MATLAB uses 1-based indexing. When interfacing with Python/trimesh (0-based), indices need conversion.
Use the Python implementation instead:
- See
../positioning.pyfor complete, production-ready implementation - Includes error handling, type safety, and batch processing support
- Command-line interface and SLURM HPC integration
- No MATLAB license required