Model.hm_getmatrixdifference#

Model.hm_getmatrixdifference(matrix_1, matrix_2)#

Given 4x4 transformation matrices, representing the orientation and positions of two geometric shapes A and B, return the transformation matrix that brings the A to B. This can be used in conjunction with Model.hm_getorientation() that returns the transformation matrices for various entity types.

Parameters:
  • matrix_1 (hwDoubleList) – The first matrix, passed in as a list of 16 values.

  • matrix_2 (hwDoubleList) – The second matrix, passed in as a list of 16 values.

Returns:

  • hwReturnStatus - Status object

  • HmQueryResult - Result object containing the output values:

    • transformationMatrix (numpy.ndarray) - The list of 16 values representing the 4x4 matrix M1-1M2

Examples#

Find the difference between the orientation of two selections of surfaces#
import hm
import hm.entities as ent


def matToList(matrix: numpy.ndarray):
    """
    Simple function that converts a numpy array of numpy arrays to list
    """

    converted_list = list()
    for row in matrix:
        for col in row:
            converted_list.append(col)

    return converted_list


model = hm.Model()

# Orientation matrix for surfaces with IDs 22-44 on current model
surface_collection_1 = hm.Collection(model, ent.Surface, list(range(22, 45)))
_, resultlist = model.hm_getorientation(entityCollection=surface_collection_1)

result = resultlist[0]  # Length of resultlist = 1 in this case
m1 = matToList(result.orientation)  # Orintation matrix converted to list

# Orientation matrix for surfaces with IDs 56-61 on current model
surface_collection_2 = hm.Collection(model, ent.Surface, list(range(56, 61)))

_, resultlist = model.hm_getorientation(entityCollection=surface_collection_2)
result = resultlist[0]  # Length of resultlist = 1 in this case
m2 = matToList(result.orientation)  # Orintation matrix converted to list

_, result = model.hm_getmatrixdifference(matrix_1=m1, matrix_2=m2)

print("Transformation Matrix:", result.transformationMatrix.reshape(4, 4))
Find the difference between the orientation of two components#
import hm
import hm.entities as ent


def matToList(matrix: numpy.ndarray):
    """
    Simple function that converts a numpy array of numpy arrays to list
    """

    converted_list = list()
    for row in matrix:
        for col in row:
            converted_list.append(col)

    return converted_list


model = hm.Model()

# Orientation matrix for components with IDs 44, 45 on current model
comps_collection_1 = hm.Collection(model, ent.Component, [44, 45])
_, resultlist = model.hm_getorientation(
    entityCollection=comps_collection_1, comparetype=1
)

result = resultlist[0]  # Length of resultlist = 2 in this case
m1 = matToList(result.orientation)  # Orintation matrix converted to list

result = resultlist[1]
m2 = matToList(result.orientation)  # Orintation matrix converted to list

_, result = model.hm_getmatrixdifference(matrix_1=m1, matrix_2=m2)

print("Transformation Matrix:", result.transformationMatrix.reshape(4, 4))