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')
returns:
0 0 1
Example 2:
align_frame(1:3,'XYZ')
returns
0.9636 -0.1483 -0.2224
Example 3:
align_frame([1;1;0],'xy')
returns
0.7071
-0.7071
0Example 4:
align_frame([0 0 1],'Z')
returns
[]
Note: Solutions wrapped in (f)eval(c), inline, str2func, regexprep (dynamic regular expressions), etc, are not appreciated.
Solution Stats
Solution Comments
Show commentsProblem Recent Solvers2
Suggested Problems
-
2226 Solvers
-
Project Euler: Problem 8, Find largest product in a large string of numbers
1285 Solvers
-
74 Solvers
-
305 Solvers
-
Return a list sorted by number of consecutive occurrences
420 Solvers
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!