Problem 961. Robust alignment of coordinate system

We have to create a custom 3-D coordinate system of which one axis is defined by a vector (in the global coordinate system). The other two coordinate axes can be freely chosen. But the most intuitive would be (in this case) to align an axis of the custom coordinate system with the global one, either which one matches best.

Return the 3element normalized column vector P in a 3-D Cartesian space (regular x,y,z axes we use in general), that * is in a plane (through the origin), defined by its normal vector N * N can be a column- or row vector * N is not necessarily normalized * makes the smallest angle with any of the Cartesian axes specified A * A is a character array containing any of the character xyz and XYZ * when the smallest angle of P with multiple axes mentioned in A is equal, the order of the axes in A defines which is preferred * when A contains only one axis-name, and N is parallel to that axis, the functions return empty an empty matrix [].

Example 1:

 align_frame([1 0 0],'zyx')



Example 2:




Example 3:




Example 4:

 align_frame([0 0 1],'Z')



Note: Solutions wrapped in (f)eval(c), inline, str2func, regexprep (dynamic regular expressions), etc, are not appreciated.

Solution Stats

21.43% Correct | 78.57% Incorrect
Last solution submitted on Nov 28, 2015

Solution Comments

Discover MakerZone

MATLAB and Simulink resources for Arduino, LEGO, and Raspberry Pi

Learn more

Discover what MATLAB® can do for your career.

Opportunities for recent engineering grads.

Apply Today

MATLAB Academy

New to MATLAB?

Learn MATLAB today!