Skip to content

Commit acf6faa

Browse files
jgray-19jgray-19
authored andcommitted
Add comments and reasoning for changes
1 parent 81c15cb commit acf6faa

File tree

1 file changed

+12
-14
lines changed

1 file changed

+12
-14
lines changed

src/madl_dynmap.mad

Lines changed: 12 additions & 14 deletions
Original file line numberDiff line numberDiff line change
@@ -370,15 +370,18 @@ function misalignent (elm, m, lw) --
370370

371371
-- translation
372372
if algn.trn then _T:fill{edir*algn.dx, edir*algn.dy, algn.ds} else _T:zeros() end
373-
if algn.trn and algn.rot then _T = _R:rotzxy(-edir*algn.dphi, edir*algn.dthe, edir*algn.dpsi, true)*_T end
373+
-- PTC applies the rotation to the translation before doing the translation
374+
if algn.trn and algn.rot then
375+
_R:rotzxy(-edir*algn.dphi, edir*algn.dthe, edir*algn.dpsi, true):mul(_T, _T)
376+
end
374377
-- rotate
375378
if algn.rot and sdir > 0 then
376379
yrotation(elm, m, edir, algn.dthe)
377380
xrotation(elm, m, edir, -algn.dphi)
378381
srotation(elm, m, edir, algn.dpsi)
379382
end
380383

381-
-- translate
384+
-- translate (Weighting by edir is done above and in translate so needs to be unweighted here)
382385
if algn.trn then
383386
translate(elm, m, 1, edir*_T[1], edir*_T[2], _T[3])
384387
end
@@ -399,37 +402,32 @@ function misalignexi (elm, m, lw) --
399402
local el, eld, ang, tlt, sdir, edir, tdir, algn in m
400403
local mang = m.mang or ang
401404

402-
-- translation
405+
-- translation (Needs to be weighted by edir before rtbar is computed)
403406
if algn.trn then _T:fill{edir*algn.dx, edir*algn.dy, algn.ds} else _T:zeros() end
404407

405-
-- rotation
408+
-- rotation (Needs to be weighted by edir before rtbar is computed)
406409
if algn.rot then _R:rotzxy(-edir*algn.dphi, edir*algn.dthe, edir*algn.dpsi) end
407410

408-
-- compute Rbar, Tbar
411+
-- compute Rbar, Tbar (PTC uses path length for misalignment)
409412
_C.mad_mat_rtbar(_Rb._dat, _Tb._dat, abs(eld or el), mang, tlt, algn.rot and _R._dat or nil, _T._dat)
410413

411414
-- misalignment at exit and local/global frames
412415
-- forward : x2 = Rb^-1*(x2'-Tb)
413416
-- backward: x2' = Rb*x2+Tb
414417

415-
-- _T:print("T")
416-
-- _R:print("R")
417-
-- _Tb:print("Tb")
418-
-- _Rb:print("Rb")
419-
420418
-- rotate
421-
if algn.rot and sdir > 0 then
419+
if algn.rot and sdir > 0 then -- Weighting by edir is done above
422420
local ax, ay, az = _Rb:torotzxy()
423421
srotation(elm, m, -1, az)
424422
xrotation(elm, m, -1, ax)
425423
yrotation(elm, m, -1, ay)
426424
end
427425

428-
-- translate
429-
translate(elm, m, -1, edir*_Tb[1], edir*_Tb[2], _Tb[3])
426+
-- translate (Weighting by edir is done above and in translate so needs to be unweighted here)
427+
translate(elm, m, -1, edir*_Tb[1], edir*_Tb[2], _Tb[3])
430428

431429
-- rotate
432-
if algn.rot and sdir < 0 then
430+
if algn.rot and sdir < 0 then -- Weighting by edir is done above
433431
local ax, ay, az = _Rb:torotzxy()
434432
yrotation(elm, m, 1, ay)
435433
xrotation(elm, m, 1, ax)

0 commit comments

Comments
 (0)