Orthonormal Vector

A set of vectors is orthonormal if the vectors are mutually orthogonal (perpendicular) and all of unit length. Orthonormal vectors are important for building vector spaces.

For v1, v2 to be orthonormal:

  • v1 • v2 = 0 (orthogonal - dot product is 0)
  • ||v1|| = 1 (unit length - norm is 1)
  • ||v2|| = 1

Java example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
boolean isOrthonormal(double[] v1, double[] v2) {
  return Math.abs(dotProduct(v1, v2)) < EPSILON
         && euclideanNorm(v1) - 1 < EPSILON 
         && euclideanNorm(v2) - 1 < EPSILON;
}

double dotProduct(double[] v1, double[] v2) {
  // Calculate dot product
}

double euclideanNorm(double[] v) {
  // Calculate L2 norm
}

C++ example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
bool isOrthonormal(vector<double> v1, vector<double> v2) {

  return abs(dotProduct(v1, v2)) < EPSILON
      && euclideanNorm(v1) - 1 < EPSILON
      && euclideanNorm(v2) - 1 < EPSILON;  

}

double dotProduct(vector<double>& v1, vector<double>& v2) {
  // Dot product 
}

double euclideanNorm(vector<double> v) {
  // Calculate L2 norm
}

Python example:

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
import math

EPSILON = 0.001

def is_orthonormal(v1, v2):
  
  return abs(dot_product(v1, v2)) < EPSILON and \
         math.hypot(*v1) - 1 < EPSILON and \ 
         math.hypot(*v2) - 1 < EPSILON
         
def dot_product(v1, v2):
  # Dot product
  
def euclidean_norm(v):
  # L2 norm 

Orthonormal vectors are important for building orthonormal bases used in linear algebra and signal processing.

In mathematics, particularly in linear algebra, an orthonormal set of vectors consists of vectors that are both orthogonal and unit vectors. Two vectors are orthogonal if their dot product is zero, and a vector is a unit vector if its length is 1. An orthonormal set has the properties of being orthogonal and normalized, making calculations in various fields, such as computer graphics and signal processing, easier.

Orthonormal vectors are vectors that are both orthogonal (perpendicular to each other) and have a magnitude of 1.

Visual Representation:

  1. Imagine two vectors ( \vec{A} ) and ( \vec{B} ) in a 2D plane.
     ^ B
     |  /
     | /  
     |/  
-----+-------> A
  1. When these vectors are orthogonal, the angle between them is 90 degrees.
  2. When these vectors are also normalized (magnitudes are 1), they become orthonormal.

Orthonormal vectors are orthogonal and have unit length. They form the basis of orthonormal coordinate systems, which are extremely useful in simplifying problems in mathematics and physics. For instance, they are commonly used in computer graphics to represent camera orientation and in linear algebra to simplify calculations.

Solution

Below are the code implementations for checking if two vectors are orthonormal and for making a set of vectors orthonormal in Java, C++, and Python.

Java

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
public class OrthonormalVector {
    public static double dotProduct(double[] A, double[] B) {
        double sum = 0;
        for(int i = 0; i < A.length; i++) {
            sum += A[i] * B[i];
        }
        return sum;
    }

    public static boolean isOrthonormal(double[] A, double[] B) {
        return Math.abs(dotProduct(A, B)) < 1e-9 && Math.abs(dotProduct(A, A) - 1) < 1e-9 && Math.abs(dotProduct(B, B) - 1) < 1e-9;
    }

    public static void main(String[] args) {
        double[] A = {1, 0, 0};
        double[] B = {0, 1, 0};
        System.out.println(isOrthonormal(A, B));
    }
}

C++

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
12
13
14
15
16
17
18
19
20
#include <iostream>
#include <cmath>

double dotProduct(double A[], double B[], int size) {
    double sum = 0;
    for(int i = 0; i < size; ++i) {
        sum += A[i] * B[i];
    }
    return sum;
}

bool isOrthonormal(double A[], double B[], int size) {
    return std::abs(dotProduct(A, B, size)) < 1e-9 && std::abs(dotProduct(A, A, size) - 1) < 1e-9 && std::abs(dotProduct(B, B, size) - 1) < 1e-9;
}

int main() {
    double A[] = {1, 0, 0};
    double B[] = {0, 1, 0};
    std::cout << isOrthonormal(A, B, 3) << std::endl;
}

Python

 1
 2
 3
 4
 5
 6
 7
 8
 9
10
11
import math

def dotProduct(A, B):
    return sum(a * b for a, b in zip(A, B))

def isOrthonormal(A, B):
    return math.isclose(dotProduct(A, B), 0, abs_tol=1e-9) and math.isclose(dotProduct(A, A), 1, abs_tol=1e-9) and math.isclose(dotProduct(B, B), 1, abs_tol=1e-9)

A = [1, 0, 0]
B = [0, 1, 0]
print(isOrthonormal(A, B))

Key Takeaways

  • An orthonormal set of vectors is both orthogonal and normalized.
  • The dot product is a useful tool for checking these properties.
  • The implementations in Java, C++, and Python use a small tolerance (1e-9) to account for numerical inaccuracies in floating-point arithmetic.