Cody

# 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
0```

Example 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

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