Function Repository Resource:

BasisFromVector

Source Notebook

Generate an orthonormal basis from a given 3D vector

Contributed by: Jan Mangaldan

ResourceFunction["BasisFromVector"][v]

generates an orthonormal basis from the numerical three-dimensional vector v.

Details

The input vector is normalized and given as the first element of the resulting basis.

Examples

Basic Examples (2) 

Generate an orthonormal basis from a real vector:

In[1]:=
v = {0, 1, 2};
basis = ResourceFunction["BasisFromVector"][v]
Out[1]=

Verify orthonormality:

In[2]:=
OrthogonalMatrixQ[basis]
Out[2]=

Generate an orthonormal basis from a complex vector:

In[3]:=
v = {I, -1, 0};
basis = ResourceFunction["BasisFromVector"][v] // Simplify
Out[3]=

Verify orthonormality:

In[4]:=
UnitaryMatrixQ[basis]
Out[4]=

Scope (6) 

A rational-valued vector:

In[5]:=
v = {2/7, 3/7, 6/7};
basis = ResourceFunction["BasisFromVector"][v]
Out[5]=

An exact complex vector:

In[6]:=
v = {(-3 + 7 I)/10, 1/2, 1/10 + 2 I/5};
basis = ResourceFunction["BasisFromVector"][v] // Simplify
Out[6]=

An approximate MachinePrecision real vector:

In[7]:=
v = N[{2/7, 3/7, 6/7}];
basis = ResourceFunction["BasisFromVector"][v]
Out[7]=

An approximate MachinePrecision complex vector:

In[8]:=
v = N[{(-3 + 7 I)/10, 1/2, 1/10 + 2 I/5}];
basis = ResourceFunction["BasisFromVector"][v]
Out[8]=

An approximate arbitrary-precision real vector:

In[9]:=
v = N[{2/7, 3/7, 6/7}, 20];
basis = ResourceFunction["BasisFromVector"][v]
Out[9]=

An approximate arbitrary-precision complex vector:

In[10]:=
v = N[{(-3 + 7 I)/10, 1/2, 1/10 + 2 I/5}, 20];
basis = ResourceFunction["BasisFromVector"][v]
Out[10]=

Applications (3) 

Generate a random point on the sphere:

In[11]:=
v = RandomPoint[Sphere[]]
Out[11]=

Construct the orthonormal basis:

In[12]:=
basis = ResourceFunction["BasisFromVector"][v]
Out[12]=

Visualize the basis vectors:

In[13]:=
Graphics3D[{{Opacity[1/2], Sphere[]}, Arrow[Tube[{{0, 0, 0}, #}]] & /@ basis}]
Out[13]=

Possible Issues (2) 

BasisFromVector only generates one out of many possible orthonormal bases:

In[14]:=
ResourceFunction["BasisFromVector"][{1, 0, 0}]
Out[14]=

BasisFromVector always generates a right-handed basis:

In[15]:=
Det[ResourceFunction["BasisFromVector"][{1/9, 4/9, 8/9}]]
Out[15]=
In[16]:=
Det[ResourceFunction["BasisFromVector"][
  RandomVariate[NormalDistribution[], 3]]]
Out[16]=

Neat Examples (1) 

Generate a set of orthonormal frames along a curve:

In[17]:=
cpts = {{0, 0, 0}, {1, 1, 1}, {2, -1, 1}, {3, 0, 2}, {4, 1, 1}};
bf = BSplineFunction[cpts];
pts = Table[bf[t], {t, 0, 1, 1/5}];
bList = Table[
   TranslationTransform[bf[t]][
    ResourceFunction["BasisFromVector"][bf'[t]]], {t, 0, 1, 1/5}];
Graphics3D[{{Blue, Tube[BSplineCurve[cpts], 1/20]}, {Red, MapThread[
    Map[Function[v, Arrow[Tube[{#1, v}]]], #2] &, {pts, bList}]}}]
Out[17]=

Version History

  • 1.1.0 – 09 February 2021
  • 1.0.0 – 21 October 2019

Source Metadata

Author Notes

Version 1.1.0 added support for complex vectors. BasisFromVector uses the "Pixar method" for real vectors, and Stark's method for complex vectors, to generate a set of orthonormal vectors.

License Information