Vector rotation using CoordinateTransformations.jl

RotZ is a rotation around the Z-axis. The angle between your vector and the rotated vector may not be the angle rotated if your vector has a Z-component.

To make this obvious, note that a rotation around the Z-axis has no effect on a unit vector pointing in the Z-direction.

julia> v = [1., 0., 0]
3-element Vector{Float64}:
 1.0
 0.0
 0.0

julia> v2 = LinearMap(RotZ(0.42))(v)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.9130889403123083
 0.40776045305957015
 0.0

julia> angle(v, Vector(v2))
0.42

julia> v3 = Float64[0,1,0]
3-element Vector{Float64}:
 0.0
 1.0
 0.0

julia> v4 = LinearMap(RotZ(0.42))(v3)
3-element SVector{3, Float64} with indices SOneTo(3):
 -0.40776045305957015
  0.9130889403123083
  0.0

julia> angle(v3, Vector(v4))
0.42

julia> v5 = Float64[0,0,1]
3-element Vector{Float64}:
 0.0
 0.0
 1.0

julia> v6 = LinearMap(RotZ(0.42))(v5)
3-element SVector{3, Float64} with indices SOneTo(3):
 0.0
 0.0
 1.0

julia> angle(v5, Vector(v6))
0.0
4 Likes