1
$\begingroup$

I have a computer graphics program that prints out affine matrices like

Transform Basis: V3 (V3 0.99060506 (-1.4430956e-2) 0.1359906) (V3 1.381684e-2 0.9998897 5.458703e-3) (V3 (-0.13605437) (-3.5284583e-3) 0.9906951) 
Transform Position: V3 0.4690141 0.6664715 0.16474605

Is there a way to visualize this matrix in Mathematica (in some sort of 3D plot)? Say of where it sends the origin looking forward?

$\endgroup$

1 Answer 1

6
$\begingroup$
inputstring = 
  "Transform Basis: V3 (V3 0.99060506 (-1.4430956e-2) 0.1359906) (V3 1.381684e-2 0.9998897 5.458703e-3) (V3 (-0.13605437) (-3.5284583e-3) 0.9906951) 
  Transform Position: V3 0.4690141 0.6664715 0.16474605";

lines = StringSplit[
  StringDelete[inputstring, {
    "(", ")",
    RegularExpression["V\\d+"],
    RegularExpression["Transform.*?:"]}], "\n"];

getnumbers[line_] := Module[{parts},
  parts = Flatten[StringCases[StringSplit[line], RegularExpression["-?[\\d.e]+-?\\d+"]]];
  ToExpression[StringReplace[#, "e" -> "*^"]] & /@ Flatten[parts]
]

m = ArrayReshape[getnumbers[lines[[1]]], {3, 3}];
v = getnumbers[lines[[2]]];
Graphics3D[{
  Opacity[.25],
  Blue, Cuboid[],
  Red, GeometricTransformation[Cuboid[], {m, v}]
}]

affine transform vis

Since it's an affine transform m.p + v, the origin is displaced from {0,0,0} to v.

$\endgroup$
2
  • $\begingroup$ Nifty! ${}{}{}{}{}{}{}{}{}$ $\endgroup$
    – mjw
    Aug 7, 2020 at 2:47
  • 1
    $\begingroup$ It should be noted that the transformation function itself can be obtained as AffineTransform[{m, v}]. $\endgroup$ Aug 7, 2020 at 9:02

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Not the answer you're looking for? Browse other questions tagged or ask your own question.