11
22"""
3- add_direction!(frames, name::Symbol, funs)
3+ add_direction!(frames, name::Symbol, axesid, funs)
44
55Add a new direction node to `frames`.
66
77### Inputs
88- `frames` -- Target frame system
99- `name` -- Direction name, must be unique within `frames`
10+ - `axesid` -- ID of the axes the direction is expressed in
1011- `funs` -- `DirectionFunctions` object storing the functions to compute the direction and,
1112 eventually, its time derivatives. It must match the type and order of `frames`.
1213"""
1314function add_direction! (
14- frames:: FrameSystem{O, N} , name:: Symbol , funs:: DirectionFunctions{O, N}
15+ frames:: FrameSystem{O, N} , name:: Symbol , axesid :: Int , funs:: DirectionFunctions{O, N}
1516) where {O, N <: Number }
1617 if name in directions (frames)
1718 throw (
@@ -21,13 +22,13 @@ function add_direction!(
2122 )
2223 end
2324
24- dir = Direction {O, N} (name, length (directions (frames))+ 1 , funs)
25+ dir = Direction {O, N} (name, length (directions (frames))+ 1 , axesid, funs)
2526 push! (directions_map (frames), Pair (name, dir))
2627 nothing
2728end
2829
2930"""
30- add_direction!(frames, name::Symbol, fun, δfun=nothing, δ²fun=nothing, δ³fun=nothing)
31+ add_direction!(frames, name::Symbol, axes, fun, δfun=nothing, δ²fun=nothing, δ³fun=nothing)
3132
3233Add a new direction node to `frames`. The orientation of these direction depends only
3334on time and is computed through the custom functions provided by the user.
@@ -46,7 +47,7 @@ If `δfun`, `δ²fun` or `δ³fun` are not provided, they are computed via autom
4647 function does not perform any checks on the output types.
4748"""
4849function add_direction! (
49- frames:: FrameSystem{O, N} , name:: Symbol , fun:: Function ,
50+ frames:: FrameSystem{O, N} , name:: Symbol , ax, fun:: Function ,
5051 δfun = nothing , δ²fun = nothing , δ³fun = nothing
5152) where {O, N}
5253
@@ -98,16 +99,16 @@ function add_direction!(
9899 t -> SVectorNT {3O, N} (δ³fun (t))
99100 end ,
100101 )
101- return add_direction! (frames, name, funs)
102+ return add_direction! (frames, name, axes_id (frames, ax), funs)
102103end
103104
104105"""
105- add_direction_fixed!(frames, name, offset::AbstractVector)
106+ add_direction_fixed!(frames, name, axes, offset::AbstractVector)
106107
107108Add a fixed direction to `frames`.
108109"""
109110function add_direction_fixed! (
110- frames:: FrameSystem{O, N} , name:: Symbol , offset:: AbstractVector{T}
111+ frames:: FrameSystem{O, N} , name:: Symbol , ax, offset:: AbstractVector{T}
111112) where {O, N, T}
112113
113114 if length (offset) != 3
@@ -121,77 +122,75 @@ function add_direction_fixed!(
121122 voffset = SVectorNT {3O, N} (SVector (offset... ))
122123 funs = DirectionFunctions {O, N} (t -> voffset, t -> voffset, t -> voffset, t -> voffset)
123124
124- return add_direction! (frames, name, funs)
125+ return add_direction! (frames, name, ax, funs)
125126end
126127
127128"""
128- add_direction_position!(frames, name::Symbol, origin, target, ax )
129+ add_direction_position!(frames, name::Symbol, origin, target, axes )
129130
130- Add a direction based on the position vector from `origin` to `target` in the specified `ax `.
131+ Add a direction based on the position vector from `origin` to `target` in the specified `axes `.
131132"""
132133function add_direction_position! (
133- frames:: FrameSystem{O, N} , name:: Symbol , from:: Symbol , to:: Symbol , ax:: Symbol
134+ frames:: FrameSystem{O, N} , name:: Symbol , from, to, ax
134135) where {O, N}
135- return add_direction_position! (
136- frames, name, points (frames)[from], points (frames)[to], axes (frames)[ax]
137- )
138- end
139136
140- function add_direction_position! (
141- frames:: FrameSystem{O, N} , name:: Symbol , from:: Int , to:: Int , ax:: Int
142- ) where {O, N}
137+ fromid, toid = point_id (frames, from), point_id (frames, to)
138+ axid = axes_id (frames, ax)
143139
144- for id in (from, to )
140+ for id in (fromid, toid )
145141 ! has_point (frames, id) && throw (
146- ErrorException (
142+ ArgumentError (
147143 " no points with id $id registered in the given frame system."
148144 )
149145 )
150146 end
151147
152- ! has_axes (frames, ax ) && throw (
153- ErrorException (
148+ ! has_axes (frames, axid ) && throw (
149+ ArgumentError (
154150 " no axes with id $ax registered in the given frame system"
155151 )
156152 )
157153
158154 funs = DirectionFunctions {O, N} (
159- t-> SVectorNT {3O, N} (vector3 (frames, from, to, ax , t)),
160- t-> SVectorNT {3O, N} (vector6 (frames, from, to, ax , t)),
161- t-> SVectorNT {3O, N} (vector9 (frames, from, to, ax , t)),
162- t-> SVectorNT {3O, N} (vector12 (frames, from, to, ax , t))
155+ t-> SVectorNT {3O, N} (vector3 (frames, fromid, toid, axid , t)),
156+ t-> SVectorNT {3O, N} (vector6 (frames, fromid, toid, axid , t)),
157+ t-> SVectorNT {3O, N} (vector9 (frames, fromid, toid, axid , t)),
158+ t-> SVectorNT {3O, N} (vector12 (frames, fromid, toid, axid , t))
163159 )
164- return add_direction! (frames, name, funs)
160+ return add_direction! (frames, name, axid, funs)
165161end
166162
167163"""
168- add_direction_velocity!(frames, name::Symbol, origin, target, ax )
164+ add_direction_velocity!(frames, name::Symbol, origin, target, axes )
169165
170- Add a direction based on the velocity vector from `origin` to `target` in the specified `ax `.
166+ Add a direction based on the velocity vector from `origin` to `target` in the specified `axes `.
171167"""
172168function add_direction_velocity! (
173- frames:: FrameSystem{O, N} , name:: Symbol , from:: Int , to:: Int , ax:: Int
169+ frames:: FrameSystem{O, N} , name:: Symbol , from, to, ax
174170) where {O, N}
175171
176- for id in (from, to)
172+ fromid, toid = point_id (frames, from), point_id (frames, to)
173+ axid = axes_id (frames, ax)
174+
175+ for id in (fromid, toid)
177176 ! has_point (frames, id) && throw (
178- ErrorException (
177+ ArgumentError (
179178 " no points with id $id registered in the given frame system."
180179 )
181180 )
182181 end
183182
184- ! has_axes (frames, ax ) && throw (
185- ErrorException (
183+ ! has_axes (frames, axid ) && throw (
184+ ArgumentError (
186185 " no axes with id $ax registered in the given frame system"
187186 )
188187 )
189188
190- fun = t-> SVectorNT {3O, N} (@views (vector6 (frames, from, to, ax , t)[4 : end ]))
191- dfun = t-> SVectorNT {3O, N} (@views (vector9 (frames, from, to, ax , t)[4 : end ]))
192- ddfun= t-> SVectorNT {3O, N} (@views (vector12 (frames, from, to, ax , t)[4 : end ]))
189+ fun = t-> SVectorNT {3O, N} (@views (vector6 (frames, fromid, toid, axid , t)[4 : end ]))
190+ dfun = t-> SVectorNT {3O, N} (@views (vector9 (frames, fromid, toid, axid , t)[4 : end ]))
191+ ddfun= t-> SVectorNT {3O, N} (@views (vector12 (frames, fromid, toid, axid , t)[4 : end ]))
193192
194- return add_direction! (frames, name, fun, dfun , ddfun)
193+ return add_direction! (frames, name, axid, fun, dfun , ddfun)
195194end
196195
197196"""
@@ -200,33 +199,41 @@ end
200199Add a direction as the cross product between two existing directions (i.e. `dir1` and `dir2`).
201200"""
202201function add_direction_orthogonal! (
203- frames:: FrameSystem{O, N} , name:: Symbol , dir1:: Symbol , dir2:: Symbol
202+ frames:: FrameSystem{O, N} , name:: Symbol , dir1:: Symbol , dir2:: Symbol , ax
204203) where {O, N}
205204
206205 for d in (dir1, dir2)
207206 if ! (d in directions (frames))
208207 throw (
209- ErrorException (
208+ ArgumentError (
210209 " no direction with name $d registered in the given frame system"
211210 )
212211 )
213212 end
214213 end
215214
215+ axid = axes_id (frames, ax)
216+
217+ ! has_axes (frames, axid) && throw (
218+ ArgumentError (
219+ " no axes with id $ax registered in the given frame system"
220+ )
221+ )
222+
216223 fun = t-> SVectorNT {3O, N} (
217- cross3 (direction3 (frames, dir1, t), direction3 (frames, dir2, t))
224+ cross3 (direction3 (frames, dir1, axid, t), direction3 (frames, dir2, axid , t))
218225 )
219226 dfun = t-> SVectorNT {3O, N} (
220- cross6 (direction6 (frames, dir1, t), direction6 (frames, dir2, t))
227+ cross6 (direction6 (frames, dir1, axid, t), direction6 (frames, dir2, axid , t))
221228 )
222229 ddfun = t-> SVectorNT {3O, N} (
223- cross9 (direction9 (frames, dir1, t), direction9 (frames, dir2, t))
230+ cross9 (direction9 (frames, dir1, axid, t), direction9 (frames, dir2, axid , t))
224231 )
225232 dddfun = t-> SVectorNT {3O, N} (
226- cross12 (direction12 (frames, dir1, t), direction12 (frames, dir2, t))
233+ cross12 (direction12 (frames, dir1, axid, t), direction12 (frames, dir2, axid , t))
227234 )
228235
229- return add_direction! (frames, name, fun, dfun, ddfun, dddfun)
236+ return add_direction! (frames, name, axid, fun, dfun, ddfun, dddfun)
230237end
231238
232239"""
@@ -244,27 +251,29 @@ function add_direction_normalize!(
244251 )
245252 )
246253 end
247- fun = t-> SVectorNT {3O, N} (unitvec (direction3 (frames, dir, t)))
248- dfun = t-> SVectorNT {3O, N} (_normalize6 (frames, dir, t))
249- ddfun = t-> SVectorNT {3O, N} (_normalize9 (frames, dir, t))
250- dddfun = t-> SVectorNT {3O, N} (_normalize12 (frames, dir, t))
254+ axid = directions_map (frames)[dir]. axesid
255+
256+ fun = t-> SVectorNT {3O, N} (unitvec (direction3 (frames, dir, axid, t)))
257+ dfun = t-> SVectorNT {3O, N} (_normalize6 (frames, dir, axid, t))
258+ ddfun = t-> SVectorNT {3O, N} (_normalize9 (frames, dir, axid, t))
259+ dddfun = t-> SVectorNT {3O, N} (_normalize12 (frames, dir, axid, t))
251260 return add_direction! (frames, name, fun, dfun, ddfun, dddfun)
252261end
253262
254- function _normalize6 (frames, dir, t)
255- d = direction6 (frames, dir, t)
263+ function _normalize6 (frames, dir, axid, t)
264+ d = direction6 (frames, dir, axid, t)
256265 @views nd = vcat (unitvec (d[1 : 3 ]), δunitvec (d[4 : 6 ]))
257266 return nd
258267end
259268
260- function _normalize9 (frames, dir, t)
261- d = direction9 (frames, dir, t)
269+ function _normalize9 (frames, dir, axid, t)
270+ d = direction9 (frames, dir, axid, t)
262271 @views nd = vcat (unitvec (d[1 : 3 ]), δunitvec (d[4 : 6 ]), δ²unitvec (d[7 : 9 ]))
263272 return nd
264273end
265274
266- function _normalize12 (frames, dir, t)
267- d = direction12 (frames, dir, t)
275+ function _normalize12 (frames, dir, axid, t)
276+ d = direction12 (frames, dir, axid, t)
268277 @views nd = vcat (unitvec (d[1 : 3 ]), δunitvec (d[4 : 6 ]), δ²unitvec (d[7 : 9 ]), δ³unitvec (d[10 : 12 ]))
269278 return nd
270279end
0 commit comments