[Math] Angle between different rays (3d line segments) and computing their angular relationships

3dcomputational geometrygeometrysolid anglevector-spaces

I have several positions (say A,B,C,..) and I know their coordinates
(3d). From each point, if a certain ray is passing in a way to
converge them at a given (known) point (say O). This point O is lie on
a known planar surface (dark plane).

.

Now, my problem is to know, mutual locations and inter-relationship
between each point with the plane. For example, I want to know that
ray DO come first and then BO, AO, ..etc. Once I know the mutual
location of them, then I want to know angle between each adjacent rays as it is my main intention.
According to example case, I need to know DOB, BOA, AOC, COE, EOF. Additionally, I need to know angle between first ray and plane and as well as last ray and plane (as these DO & FO are next to plane). (I want to know only adjacent angles and not the all possible angles, therefore, the correct adjacency or point order is needed to avoid unnecessary computations). I guess, you can understand my question.

NOTE: A,B,C,…,O these points are not lie on a single plane.
enter image description here

n is normal vector of the plane

Please, show me a way to do this without computing unnecessary computations as I want to implement this in c++.

Best Answer

You have to use scalar product: $$\vec u\cdot\vec v=|\vec u|\cdot|\vec v|\cdot\cos\angle(\vec u,\vec v)$$ So, the angle can be obtained by: $$\cos\angle(\vec u,\vec v)= \frac{u_1v_1+u_2v_2+u_3v_3}{\sqrt{{u_1}^2+{u_2}^2+{u_3}^2}\cdot \sqrt{{v_1}^2+{v_2}^2+{v_3}^2}}\,,$$ where $|\vec u|=\sqrt{{u_1}^2+{u_2}^2+{u_3}^2}$ by the Pythagorean theorem, and $u_1,u_2,u_3$ are the coordinates of $\vec u$. Also, if points are given by coordinates, the coordinates of vector $\vec{AB}$ can be calculated as $B-A$ (coordinatewise).

If $\vec n$ is a normalvector of the plane, then the angle between the plane and a vector $\vec u$ is $90^\circ-\angle(\vec u,\vec n)$.

For cute angles $\alpha,\beta$ we have $\ \alpha<\beta \iff \cos\alpha>\cos\beta$. So that we can order the angles by their cosinus, and no specific need for $\arccos$.

We also have

  • $\ \vec u\cdot\vec n>0 \ \iff\ \vec u$ is in the same halfspace as $\vec n$,
  • $\ \vec u\cdot\vec n<0 \ \iff\ \vec u$ is in the opposite halfspace as $\vec n$,
  • $\ \vec u\cdot\vec n=0 \ \iff\ \vec u$ is on the plane.