@@ -370,15 +370,18 @@ function misalignent (elm, m, lw) --
370
370
371
371
-- translation
372
372
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
374
377
-- rotate
375
378
if algn.rot and sdir > 0 then
376
379
yrotation(elm, m, edir, algn.dthe)
377
380
xrotation(elm, m, edir, -algn.dphi)
378
381
srotation(elm, m, edir, algn.dpsi)
379
382
end
380
383
381
- -- translate
384
+ -- translate (Weighting by edir is done above and in translate so needs to be unweighted here)
382
385
if algn.trn then
383
386
translate(elm, m, 1, edir*_T[1], edir*_T[2], _T[3])
384
387
end
@@ -399,37 +402,32 @@ function misalignexi (elm, m, lw) --
399
402
local el, eld, ang, tlt, sdir, edir, tdir, algn in m
400
403
local mang = m.mang or ang
401
404
402
- -- translation
405
+ -- translation (Needs to be weighted by edir before rtbar is computed)
403
406
if algn.trn then _T:fill{edir*algn.dx, edir*algn.dy, algn.ds} else _T:zeros() end
404
407
405
- -- rotation
408
+ -- rotation (Needs to be weighted by edir before rtbar is computed)
406
409
if algn.rot then _R:rotzxy(-edir*algn.dphi, edir*algn.dthe, edir*algn.dpsi) end
407
410
408
- -- compute Rbar, Tbar
411
+ -- compute Rbar, Tbar (PTC uses path length for misalignment)
409
412
_C.mad_mat_rtbar(_Rb._dat, _Tb._dat, abs(eld or el), mang, tlt, algn.rot and _R._dat or nil, _T._dat)
410
413
411
414
-- misalignment at exit and local/global frames
412
415
-- forward : x2 = Rb^-1*(x2'-Tb)
413
416
-- backward: x2' = Rb*x2+Tb
414
417
415
- -- _T:print("T")
416
- -- _R:print("R")
417
- -- _Tb:print("Tb")
418
- -- _Rb:print("Rb")
419
-
420
418
-- rotate
421
- if algn.rot and sdir > 0 then
419
+ if algn.rot and sdir > 0 then -- Weighting by edir is done above
422
420
local ax, ay, az = _Rb:torotzxy()
423
421
srotation(elm, m, -1, az)
424
422
xrotation(elm, m, -1, ax)
425
423
yrotation(elm, m, -1, ay)
426
424
end
427
425
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])
430
428
431
429
-- rotate
432
- if algn.rot and sdir < 0 then
430
+ if algn.rot and sdir < 0 then -- Weighting by edir is done above
433
431
local ax, ay, az = _Rb:torotzxy()
434
432
yrotation(elm, m, 1, ay)
435
433
xrotation(elm, m, 1, ax)
0 commit comments