vectororthogonal

How do I know if two vectors are near parallel


I am having some trouble finding parallel vectors because of floating point precision. How can I determine if the vectors are parallel with some tolerance?

I also need a check for orthogonality with tolerance.


Solution

  • For vectors v1 and v2 check if they are orthogonal by

    abs(scalar_product(v1,v2)/(length(v1)*length(v2))) < epsilon
    

    where epsilon is small enough. Analoguously you can use

    scalar_product(v1,v2)/(length(v1)*length(v2)) > 1 - epsilon
    

    for parallelity test and

    scalar_product(v1,v2)/(length(v1)*length(v2)) < -1 + epsilon
    

    for anti-parallelity.