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

20.0% Correct | 80.0% Incorrect
Last Solution submitted on Jul 01, 2017

Solution Comments

Show comments

Problem Recent Solvers2

Suggested Problems

More from this Author31

Problem Tags

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!