Skip to content

Special tensors and rotations

Levi-Civita symbol, rotation tensors and predefined unit vectors. Theory: Rotations and Euler angles.

TensND.LeviCivita Function
julia
LeviCivita(T::Type{<:Number} = Sym)

Builds an Array{T,3} of Levi-Civita Symbol ϵᵢⱼₖ = (i-j) (j-k) (k-i) / 2

Examples

julia
julia> ε = LeviCivita(Sym)
3×3×3 Array{Sym, 3}:
[:, :, 1] =
 0   0  0
 0   0  1
 0  -1  0

[:, :, 2] =
 0  0  -1
 0  0   0
 1  0   0

[:, :, 3] =
  0  1  0
 -1  0  0
  0  0  0
TensND.rot2 Function
julia
rot2(θ)

Return a 2D rotation matrix with respect to the angle θ

Examples

julia
julia> rot2(θ)
2×2 Tensor{2, 2, Sym, 4}:
 cos(θ)  -sin(θ)
 sin(θ)   cos(θ)
TensND.rot3 Function
julia
rot3(θ, ϕ = 0, ψ = 0)

Return a rotation matrix with respect to the 3 Euler angles θ, ϕ, ψ

Examples

julia
julia> cθ, cϕ, cψ, sθ, sϕ, sψ = symbols("cθ cϕ cψ sθ sϕ sψ", real = true) ;

julia> d = Dict(cos(θ) => cθ, cos(ϕ) => cϕ, cos(ψ) => cψ, sin(θ) => sθ, sin(ϕ) => sϕ, sin(ψ) => sψ) ;

julia> subs.(rot3(θ, ϕ, ψ),d...)
3×3 StaticArrays.SMatrix{3, 3, Sym, 9} with indices SOneTo(3)×SOneTo(3):
---sϕ  cϕ
+-+cϕ  sθ
           -sθ              sθsψ     cθ
TensND.rot6 Function
julia
rot6(θ, ϕ = 0, ψ = 0)

Return a rotation matrix with respect to the 3 Euler angles θ, ϕ, ψ

Examples

julia
julia> cθ, cϕ, cψ, sθ, sϕ, sψ = symbols("cθ cϕ cψ sθ sϕ sψ", real = true) ;

julia> d = Dict(cos(θ) => cθ, cos(ϕ) => cϕ, cos(ψ) => cψ, sin(θ) => sθ, sin(ϕ) => sϕ, sin(ψ) => sψ) ;

julia> R = Tens(subs.(rot3(θ, ϕ, ψ),d...))
Tens.TensCanonical{2, 3, Sym, Tensor{2, 3, Sym, 9}}
# data: 3×3 Tensor{2, 3, Sym, 9}:
---sϕ  cϕ
+-+cϕ  sθ
           -sθ              sθsψ     cθ
# var: (:cont, :cont)
# basis: 3×3 Tens.LazyIdentity{3, Sym}:
 1  0  0
 0  1  0
 0  0  1

julia> RR = R ˢ R
Tens.TensCanonical{4, 3, Sym, SymmetricTensor{4, 3, Sym, 36}}
# data: 6×6 Matrix{Sym}:
                          (cθ**-*sϕ)^2                            (-**-*sϕ)^2^2*^22(--sϕ)                     2(cθ-sϕ)                                   2(cθ-sϕ)(--sϕ)
                          (cθ**+*sψ)^2                            (-**+*cϕ)^2^2*^22(-+cϕ)                     2(cθ+sψ)                                   2(cθ+sψ)(-+cϕ)
^2*^2^2*^2^22-√2-sqrt(2)**^2*
             -√2(cθ+sψ)                2(-+cϕ)    2sϕ                    cθ*(-**+*cϕ) +^2**sϕ                   cθ*(cθ**+*sψ) -*^2*-(-+cϕ) +(cθ+sψ)
             -√2(cθ-sϕ)                2(--sϕ)    2sθ                    cθ*(-**-*sϕ) +*^2*sψ                   cθ*(cθ**-*sϕ) -**^2                            -(--sϕ) +(cθ-sϕ)
2(cθ-sϕ)(cθ+sψ)  2(--sϕ)(-+cϕ)  sqrt(2)**^2*sϕ  cϕ(-+cϕ) +(--sϕ)  cϕ(cθ+sψ) +(cθ-sϕ)  (cθ**-*sϕ)*(-**+*cϕ) + (cθ**+*sψ)*(-**-*sϕ)
# var: (:cont, :cont, :cont, :cont)
# basis: 3×3 Tens.LazyIdentity{3, Sym}:
 1  0  0
 0  1  0
 0  0  1

julia> R6 = inv_KM(subs.(KM(rot6(θ, ϕ, ψ)),d...))
Tens.TensCanonical{4, 3, Sym, SymmetricTensor{4, 3, Sym, 36}}
# data: 6×6 Matrix{Sym}:
                          (cθ**-*sϕ)^2                            (-**-*sϕ)^2^2*^22(--sϕ)                     2(cθ-sϕ)                                   2(cθ-sϕ)(--sϕ)
                          (cθ**+*sψ)^2                            (-**+*cϕ)^2^2*^22(-+cϕ)                     2(cθ+sψ)                                   2(cθ+sψ)(-+cϕ)
^2*^2^2*^2^22-√2-sqrt(2)**^2*
             -√2(cθ+sψ)                2(-+cϕ)    2sϕ                    cθ*(-**+*cϕ) +^2**sϕ                   cθ*(cθ**+*sψ) -*^2*-(-+cϕ) +(cθ+sψ)
             -√2(cθ-sϕ)                2(--sϕ)    2sθ                    cθ*(-**-*sϕ) +*^2*sψ                   cθ*(cθ**-*sϕ) -**^2                            -(--sϕ) +(cθ-sϕ)
2(cθ-sϕ)(cθ+sψ)  2(--sϕ)(-+cϕ)  sqrt(2)**^2*sϕcϕ(-+cϕ) +(--sϕ)  cϕ(cθ+sψ) +(cθ-sϕ)  (cθ**-*sϕ)*(-**+*cϕ) + (cθ**+*sψ)*(-**-*sϕ)
# var: (:cont, :cont, :cont, :cont)
# basis: 3×3 Tens.LazyIdentity{3, Sym}:
 1  0  0
 0  1  0
 0  0  1

julia> R6 == RR
true
TensND.𝐞 Function
julia
𝐞(i::Integer, dim::Int = 3, T::Type{<:Number} = Sym)

Vector of the canonical basis

Examples

julia
julia> 𝐞(1)
Tens{1, 3, Sym, Sym, Vec{3, Sym}, CanonicalBasis{3, Sym}}
# data: 3-element Vec{3, Sym}:
 1
 0
 0
# var: (:cont,)
# basis: 3×3 Tensor{2, 3, Sym, 9}:
 1  0  0
 0  1  0
 0  0  1
TensND.𝐞ᵖ Function
julia
𝐞ᵖ(i::Integer, θ::T = zero(Sym); canonical = false)

Vector of the polar basis

Examples

julia
julia> θ = symbols("θ", real = true) ;

julia> 𝐞ᵖ(1, θ)
Tens{1, 2, Sym, Sym, Vec{2, Sym}, RotatedBasis{2, Sym}}
# data: 2-element Vec{2, Sym}:
 1
 0
# var: (:cont,)
# basis: 2×2 Tensor{2, 2, Sym, 4}:
 cos(θ)  -sin(θ)
 sin(θ)   cos(θ)
TensND.𝐞ᶜ Function
julia
𝐞ᶜ(i::Integer, θ::T = zero(Sym); canonical = false)

Vector of the cylindrical basis

Examples

julia
julia> θ = symbols("θ", real = true) ;

julia> 𝐞ᶜ(1, θ)
Tens{1, 3, Sym, Sym, Vec{3, Sym}, RotatedBasis{3, Sym}}
# data: 3-element Vec{3, Sym}:
 1
 0
 0
# var: (:cont,)
# basis: 3×3 Tensor{2, 3, Sym, 9}:
 cos(θ)  -sin(θ)  0
 sin(θ)   cos(θ)  0
      0        0  1
TensND.𝐞ˢ Function
julia
𝐞ˢ(i::Integer, θ::T = zero(Sym), ϕ::T = zero(Sym), ψ::T = zero(Sym); canonical = false)

Vector of the basis rotated with the 3 Euler angles θ, ϕ, ψ (spherical if ψ=0)

Examples

julia
julia> θ, ϕ, ψ = symbols("θ, ϕ, ψ", real = true) ;

Tens{1, 3, Sym, Sym, Vec{3, Sym}, RotatedBasis{3, Sym}}
# data: 3-element Vec{3, Sym}:
 1
 0
 0
# var: (:cont,)
# basis: 3×3 Tensor{2, 3, Sym, 9}:
 -sin(ψ)sin(ϕ) + cos(θ)cos(ψ)cos(ϕ)  -sin(ψ)cos(θ)cos(ϕ) - sin(ϕ)cos(ψ)  sin(θ)cos(ϕ)
  sin(ψ)cos(ϕ) + sin(ϕ)cos(θ)cos(ψ)  -sin(ψ)sin(ϕ)cos(θ) + cos(ψ)cos(ϕ)  sin(θ)sin(ϕ)
                        -sin(θ)cos(ψ)                          sin(θ)sin(ψ)         cos(θ)