Skip to content

Commit a40a287

Browse files
additional axes ctors
1 parent 2222686 commit a40a287

File tree

3 files changed

+144
-2
lines changed

3 files changed

+144
-2
lines changed

src/Definitions/attitude.jl

Lines changed: 57 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,57 @@
1+
2+
"""
3+
add_axes_fixed_quaternion!(frames::FrameSystem, name::Symbol, id::Int, parent, q::Quaternion)
4+
5+
Add axes `name` with id `id` to `frames` with a fixed-offset from `parent`.
6+
Fixed offset axes have a constant orientation with respect to their `parent` axes,
7+
represented by the quaternion `q`.
8+
9+
### See also
10+
See also [`add_axes_fixedoffset!`](@ref).
11+
"""
12+
function add_axes_fixed_quaternion!(
13+
frames::FrameSystem, name::Symbol, id::Int, parent, q::Quaternion
14+
)
15+
add_axes_fixedoffset!(frames, name, id, parent, quat_to_dcm(q))
16+
end
17+
18+
"""
19+
add_axes_fixed_angles!(frames, name::Symbol, id::Int, parent, θ::AbstractVector{N}, seq::Symbol)
20+
21+
Add axes `name` with id `id` to `frames` with a fixed-offset from `parent`.
22+
Fixed offset axes have a constant orientation with respect to their `parent` axes,
23+
represented by Euler angles `θ`.
24+
25+
The rotation sequence is defined by `seq` specifing the rotation axes. The possible
26+
values depends on the number of rotations as follows:
27+
28+
- **1 rotation** (`θ₁`): `:X`, `:Y`, or `:Z`.
29+
- **2 rotations** (`θ₁`, `θ₂`): `:XY`, `:XZ`, `:YX`, `:YZ`, `:ZX`, or `:ZY`.
30+
- **3 rotations** (`θ₁`, `θ₂`, `θ₃`): `:XYX`, `XYZ`, `:XZX`, `:XZY`, `:YXY`, `:YXZ`, `:YZX`,
31+
`:YZY`, `:ZXY`, `:ZXZ`, `:ZYX`, or `:ZYZ`
32+
33+
### See also
34+
See also [`add_axes_fixedoffset!`](@ref).
35+
"""
36+
function add_axes_fixed_angles!(
37+
frames::FrameSystem, name::Symbol, id::Int, parent, θ::AbstractVector{N}, seq::Symbol
38+
) where {N}
39+
add_axes_fixedoffset!(frames, name, id, parent, angle_to_dcm..., seq))
40+
end
41+
42+
"""
43+
add_axes_fixed_angleaxis!(frames, name::Symbol, id::Int, parent, ϕ::Number, v::AbstractVector{N})
44+
45+
Add axes `name` with id `id` to `frames` with a fixed-offset from `parent`.
46+
Fixed offset axes have a constant orientation with respect to their `parent` axes,
47+
represented by Euler angle `ϕ` [rad] and Euler axis `v`.
48+
49+
### See also
50+
See also [`add_axes_fixedoffset!`](@ref).
51+
"""
52+
function add_axes_fixed_angleaxis!(
53+
frames::FrameSystem, name::Symbol, id::Int, parent, ϕ::Number, v::AbstractVector{N}
54+
) where {N}
55+
naxis = unitvec(v)
56+
add_axes_fixedoffset!(frames, name, id, parent, angleaxis_to_dcm(ϕ, naxis))
57+
end

src/Definitions/axesfromdir.jl

Lines changed: 75 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,75 @@
1+
"""
2+
function add_axes_twodir!(frames::FrameSystem{O,T}, name::Symbol, id, parent,
3+
dir1::Symbol, dir2::Symbol, seq::Symbol; project::Bool=false) where {O,T}
4+
5+
Add a set of axes to `frames` based on two directions.
6+
7+
A right-handed coordinate system is generated based on the specified sequence direction (`seq`),
8+
which determines the order in which the vectors are used to define the basis.
9+
The `project` flag specifies whether the resulting axes are inertial or not.
10+
11+
### See also
12+
See also [`add_axes_projected!`](@ref) and [`add_axes_rotating!`](@ref).
13+
"""
14+
function add_axes_twodir!(
15+
frames::FrameSystem{O,T}, name::Symbol, id, parent, dir1::Symbol, dir2::Symbol, seq::Symbol;
16+
project::Bool=false
17+
) where {O,T}
18+
19+
fun = t -> twodir_to_dcm(
20+
direction3(frames, dir1, parent, t), direction3(frames, dir2, parent, t), seq
21+
)
22+
23+
if project
24+
add_axes_projected!(frames, name, id, parent, fun)
25+
else
26+
add_axes_rotating!(frames, name, id, parent, fun)
27+
end
28+
end
29+
30+
function _two_dir_basis(a::AbstractVector, b::AbstractVector,
31+
seq::Symbol, fc::Function)
32+
33+
if seq == :XY
34+
w = fc(a, b)
35+
v = fc(w, a)
36+
u = a
37+
38+
elseif seq == :YX
39+
w = fc(b, a)
40+
u = fc(a, w)
41+
v = a
42+
43+
elseif seq == :XZ
44+
v = fc(b, a)
45+
w = fc(a, v)
46+
u = a
47+
48+
elseif seq == :ZX
49+
v = fc(a, b)
50+
u = fc(v, a)
51+
w = a
52+
53+
elseif seq == :YZ
54+
u = fc(a, b)
55+
w = fc(u, a)
56+
v = a
57+
58+
elseif seq == :ZY
59+
u = fc(b, a)
60+
v = fc(a, u)
61+
w = a
62+
else
63+
throw(ArgumentError("Invalid rotation sequence $seq."))
64+
end
65+
66+
return u, v, w
67+
end
68+
69+
function twodir_to_dcm(a::AbstractVector, b::AbstractVector, seq::Symbol)
70+
ut, vt, wt = _two_dir_basis(a, b, seq, cross3)
71+
u, v, w = unitvec(ut), unitvec(vt), unitvec(wt)
72+
73+
@inbounds dcm = DCM((u[1], v[1], w[1], u[2], v[2], w[2], u[3], v[3], w[3]))
74+
return dcm
75+
end

src/FrameTransformations.jl

Lines changed: 12 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -6,8 +6,10 @@ using ReferenceFrameRotations
66
using FunctionWrappers: FunctionWrapper
77
using FunctionWrappersWrappers: FunctionWrappersWrapper
88

9-
using JSMDUtils.Math: D¹, D², D³, unitvec, cross3, arcsec2rad, angle_to_δdcm, angle_to_δdcm,
10-
angle_to_δ²dcm, angle_to_δ³dcm
9+
using JSMDUtils.Math: D¹, D², D³, arcsec2rad,
10+
unitvec, δunitvec, δ²unitvec, δ³unitvec,
11+
cross3, cross6, cross9, cross12,
12+
angle_to_δdcm, angle_to_δdcm, angle_to_δ²dcm, angle_to_δ³dcm
1113

1214
using JSMDInterfaces.Graph: AbstractJSMDGraphNode,
1315
add_edge!, add_vertex!, get_path, has_vertex
@@ -119,4 +121,12 @@ export add_direction_position!, add_direction_velocity!, add_direction_orthogona
119121

120122
include("Definitions/directions.jl")
121123

124+
export add_axes_twodir!
125+
126+
include("Definitions/axesfromdir.jl")
127+
128+
export add_axes_fixed_quaternion!, add_axes_fixed_angles!, add_axes_fixed_angleaxis!
129+
130+
include("Definitions/attitude.jl")
131+
122132
end

0 commit comments

Comments
 (0)