[CoordinateTransformations.jl + Meshes.jl + Rotations.jl] Design for mixed 3d homogeneous and cartesian meshes

The problem is with the way you’ve constructed your cartesian_translation — it’s not a LinearMap at all, it’s a Translation. Both linear maps and translations are types of affine maps, so you can use the AffineMap type to combine them, or you can combine them with composition.

Here’s an example of how to deconstruct your 4x4 matrix into the necessary parts:

julia> m44 = [3 2 1 4;
              1 3 1 2;
              1 2 3 1;
              0 0 0 1]
4×4 Matrix{Int64}:
 3  2  1  4
 1  3  1  2
 1  2  3  1
 0  0  0  1

The 3x3 linear map and translation vector:

julia> m33 = m44[1:3,1:3]
3×3 Matrix{Int64}:
 3  2  1
 1  3  1
 1  2  3

julia> t = m44[1:3,4]
3-element Vector{Int64}:
 4
 2
 1

Putting these together, you can see you get the same result using AffineMap or 4x4 matrix multiplication:

julia> AffineMap(m33, t)([1,2,3])
3-element Vector{Int64}:
 14
 12
 15

julia> m44 * [1,2,3,1]
4-element Vector{Int64}:
 14
 12
 15
  1

Alternatively, you can construct the AffineMap from the translation and linear map parts. The library will eagerly compose these together into a single AffineMap data structure (the same one we manually constructed above):

julia> Translation(t) ∘ LinearMap(m33)
AffineMap([3 2 1; 1 3 1; 1 2 3], [4, 2, 1])
2 Likes