Combine two transforms. Parameters ---------- t_first : dict First transform. t_second : dict Second transform. fro : int From coordinate frame. to : int To coordinate frame. Returns ------- trans : dict Combined transform
(t_first, t_second, fro, to)
| 517 | |
| 518 | |
| 519 | def combine_transforms(t_first, t_second, fro, to): |
| 520 | """Combine two transforms. |
| 521 | |
| 522 | Parameters |
| 523 | ---------- |
| 524 | t_first : dict |
| 525 | First transform. |
| 526 | t_second : dict |
| 527 | Second transform. |
| 528 | fro : int |
| 529 | From coordinate frame. |
| 530 | to : int |
| 531 | To coordinate frame. |
| 532 | |
| 533 | Returns |
| 534 | ------- |
| 535 | trans : dict |
| 536 | Combined transformation. |
| 537 | """ |
| 538 | fro = _to_const(fro) |
| 539 | to = _to_const(to) |
| 540 | if t_first["from"] != fro: |
| 541 | raise RuntimeError( |
| 542 | 'From mismatch: {fro1} ("{cf1}") != {fro2} ("{cf2}")'.format( |
| 543 | fro1=t_first["from"], |
| 544 | cf1=_coord_frame_name(t_first["from"]), |
| 545 | fro2=fro, |
| 546 | cf2=_coord_frame_name(fro), |
| 547 | ) |
| 548 | ) |
| 549 | if t_first["to"] != t_second["from"]: |
| 550 | raise RuntimeError( |
| 551 | 'Transform mismatch: t1["to"] = {to1} ("{cf1}"), ' |
| 552 | 't2["from"] = {fro2} ("{cf2}")'.format( |
| 553 | to1=t_first["to"], |
| 554 | cf1=_coord_frame_name(t_first["to"]), |
| 555 | fro2=t_second["from"], |
| 556 | cf2=_coord_frame_name(t_second["from"]), |
| 557 | ) |
| 558 | ) |
| 559 | if t_second["to"] != to: |
| 560 | raise RuntimeError( |
| 561 | 'To mismatch: {to1} ("{cf1}") != {to2} ("{cf2}")'.format( |
| 562 | to1=t_second["to"], |
| 563 | cf1=_coord_frame_name(t_second["to"]), |
| 564 | to2=to, |
| 565 | cf2=_coord_frame_name(to), |
| 566 | ) |
| 567 | ) |
| 568 | return Transform(fro, to, np.dot(t_second["trans"], t_first["trans"])) |
| 569 | |
| 570 | |
| 571 | @verbose |