testing parallelity/perpendicularity of two 3D vectors with lengths close to zero using dot product

310 Views Asked by At

as u know dot product and vector norm(euclidean) definitions are as following:

  • $ \vec v . \vec w = \left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta = (v_x \times w_x+v_y \times w_y+v_z \times w_z) $($\theta$ being the angle between two vectors)
  • $ \left\lVert \vec x \right\rVert = \sqrt{(x_x)^2 + (x_y)^2 + (x_z)^2} $(regarding pythagorean theorem).

So we have two 3D vectors(we have their x,y and z components) $ \vec v $ and $ \vec w $ both of which have a length close to zero and since we're dealing with real numbers obviously data is in floatin-point representation and round-off errors during calculation is possible, we want to test whether vectors are perpendicular or parallel(linearly dependent that is pointing in either the same or opposite direction), normally if $ (\vec v . \vec w)^2 $ is close to 0(we say 'close' because of round-off errors) we can conclude vectors are perpendicular and if $ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 $ is close to 0 then we conclude vectors are parallel, but in our case both results of these expressions will be close to zero, now one way to solve the issue is to multiply each vector by a scalar so that its length increases and expressions will not yield near values anymore, but I also came up with an alternate solution as it follows:

$$ R = \frac{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 }{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 } = \frac{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 }{ (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 - (\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert)^2 \times (\cos\theta) ^2 } $$ if the R is some big value it shows that $ \cos\theta $ has a value close to 1 so we can conclude vectors are parallel and if R is some small value(close to 1) it demonstrates that $ \cos\theta $ is close to 0 so we can conclude vectors are perpendicular, now do you think there is any issue regarding this solution?

1

There are 1 best solutions below

0
On BEST ANSWER

So what we really want to know is the value of $ \cos\theta $ not $ \left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta $ hence I found out that testing closeness of $ \vec v . \vec w $, $ \left\lVert \vec v \right\rVert . \left\lVert \vec w \right\rVert - \vec v . \vec w $, $ (\vec v . \vec w)^2 $ or $ (\left\lVert \vec v \right\rVert . \left\lVert \vec w \right\rVert)^2 - (\vec v . \vec w)^2 $ to zero is not actually the right solution despite it being written in a math book(a book on the math needed for computer graphics), the correct formula that gives us $ \cos\theta $ very simply is: $$ \frac{\vec v . \vec w}{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert}=\frac{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert \times \cos\theta}{\left\lVert \vec v \right\rVert \times \left\lVert \vec w \right\rVert} $$ also normalizing v and w makes it simpler