Apply homogeneous transformation matrix to meshes

14 views
Skip to first unread message

Maia R.

unread,
Jul 16, 2021, 3:22:26 PM7/16/21
to scalismo
Dear community,
I need help to apply an homogeneous transformation matrix to meshes. 
I tried to get the rotation (Euler angles) and the translation matrices and apply a composed transformation to the mesh but I failed to obtain a good result as with CloudCompare for example.
Does someone already work with the same problem ?
Thank you,
Best regards
Maia

Marcel Luethi

unread,
Jul 16, 2021, 10:52:48 PM7/16/21
to Maia R., scalismo
Hi Maia

You cannot directly use a matrix to transform a mesh, as Scalismo works on a higher level of abstraction. But you can easily construct a transformation from a matrix like this::
def homogeneousTransform(matrix4x4 : DenseMatrix[Double]) : Transformation[_3D] = {
Transformation{
(point : Point[_3D]) => {
val pointInHomogeneousCoords = DenseVector(point.x, point.y, point.z, 1.0)
val transformedPointHomogeneousCoords = matrix4x4 * pointInHomogeneousCoords
Point3D(transformedPointHomogeneousCoords(0), transformedPointHomogeneousCoords(1), transformedPointHomogeneousCoords(2))
}
}
}

val mat : DenseMatrix[Double] = ??? // 4x4 matrix with transformation
val transformation = homogeneousTransform(mat)
val mesh : TriangleMesh[_3D] = ???
val transformedMesh = mesh.transform(transformation)

The more direct would be to specify a transformation directly, using the known rotation (Euler angles) and translation parameters:
val t = RotationAfterTranslation3D(translation = Translation(EuclideanVector3D(1, 1, 1)),
rotation = Rotation(0, 0, 0, center = Point3D(0, 0, 0)))

Best regards,

Marcel


--
You received this message because you are subscribed to the Google Groups "scalismo" group.
To unsubscribe from this group and stop receiving emails from it, send an email to scalismo+u...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/scalismo/b5198808-306f-4560-bbca-26124cf32793n%40googlegroups.com.

V R

unread,
Jul 17, 2021, 8:13:08 AM7/17/21
to Marcel Luethi, scalismo
Thank you very much. 
Reply all
Reply to author
Forward
0 new messages