# Find the angle of a point in relation to a 3d basis …

The question is quite hard to explain so I included a diagram, what I'm trying to do is to solve for the two angles indicated by clouds, in the quickest way possible. As for the vectors, they are 3 perpendicular vectors, and they are all unit vectors, they form an orthonormal basis! My first instinct was to solve for a 3x3 linear system using Cramer's rule, such that:

$$(x, y, z) = a * \vec{fwd} + b * \vec{up} + c * \vec{rght}$$ And then just use a, b, c to trigonometrically extract the angles. This works just fine, but it so expensive... Another alternative I am looking at are spherical coordinates, but I have no idea how to make these work ...

I'd favor an approach that is atleast faster than just solving a 3x3 system, as this is a bottleneck in my application, especially when checking thousands vectors per second.

• If you want the actual angles, you’re not going to be able to avoid expensive inverse trig functions. Do you really need them? If you’re just going to turn around and use sines and cosines of those angles, then there are ways to compute those directly relatively inexpensively. – amd Mar 23 '18 at 23:18
• @amd I do not mind inverse trig functions, those are optimised relatively well I'm pretty sure, what I don't want is 96 operations for one point and my current technique certainly involves that :( – Whiteclaws Mar 24 '18 at 0:36

Since your reference direction vectors are an orthonormal basis, you just need to rotate (and perhaps translate) into the “rfu” coordinate system. This is the inverse of the transformation that maps the standard basis to this one and the inverse of a rotation matrix is its transpose, so the required rotation matrix has $\vec r$, $\vec f$ and $\vec u$, in that order, as its rows. Therefore, the transformed coordinates of a point $\vec p$ are $$a = \vec r\cdot\vec p \\ b = \vec f\cdot\vec p \\ c = \vec u\cdot\vec p.$$ (In general, the coordinate of a point is the scalar projection onto a basis vector in a direction parallel to the span of the other basis vectors.) The two angles are then $\arctan\frac if$ and $\arctan\frac rf$. Presumably you’ve got access to an ATAN2-type function that’ll give you the correct quadrant for the computed angle.
{"ft_lang_label":"__label__en","ft_lang_prob":0.9411,"math_prob":0.98961216,"size":828,"snap":"2019-43-2019-47","text_gpt3_token_len":206,"char_repetition_ratio":0.093446605,"word_repetition_ratio":0.0,"special_character_ratio":0.24758454,"punctuation_ratio":0.14450867,"nsfw_num_words":0,"has_unicode_error":false,"math_prob_llama3":0.99756056,"pos_list":[0,1,2],"im_url_duplicate_count":[null,1,null],"WARC_HEADER":"{\"WARC-Type\":\"response\",\"WARC-Date\":\"2019-11-17T09:37:47Z\",\"WARC-Record-ID\":\"<urn:uuid:9571e01b-2bd3-4e4b-8047-72d47303eb4e>\",\"Content-Length\":\"138201\",\"Content-Type\":\"application/http; msgtype=response\",\"WARC-Warcinfo-ID\":\"<urn:uuid:8e0a7e36-0b79-4f43-8c0d-f9484d023c86>\",\"WARC-Concurrent-To\":\"<urn:uuid:92432479-3c5e-43cc-804d-46eccd1027cc>\",\"WARC-IP-Address\":\"151.101.65.69\",\"WARC-Target-URI\":\"https://math.stackexchange.com/questions/2705491/find-the-angle-of-a-point-in-relation-to-a-3d-basis\",\"WARC-Payload-Digest\":\"sha1:TDZHAFWUW7T56DEZQACE4YUNXOJTSVGA\",\"WARC-Block-Digest\":\"sha1:4DWOOARRTDTC4JBWL35XUKQIVA4KIX4G\",\"WARC-Identified-Payload-Type\":\"text/html\",\"warc_filename\":\"/cc_download/warc_2019/CC-MAIN-2019-47/CC-MAIN-2019-47_segments_1573496668910.63_warc_CC-MAIN-20191117091944-20191117115944-00444.warc.gz\"}"}