python Ansys ACT中的局部坐标系定义

kxkpmulp  于 2023-06-20  发布在  Python
关注(0)|答案(1)|浏览(101)

我有坐标系的位置和基向量,我想使用这些数据在ANSYS Workbench(2023R1)中使用python ACT API创建坐标系。
我发现有各种方法可以提供与GUI相同的功能,但没有任何方法可以简单地使用原点和基来创建系统。
有人能给予我一个提示吗?

6ojccjat

6ojccjat1#

我假设你在Ansys Mechanical内部工作。我在文档中找到了这个片段,并添加了绕y轴逆时针旋转90 °的函数:

def rotate_vector_around_y_axis(vector):
    rotation_matrix = [[0, 0, 1],
                       [0, 1, 0],
                       [-1, 0, 0]]
    rotated_vector = [sum(rotation_matrix[i][j] * vector[j] for j in range(3)) for i in range(3)]
    return rotated_vector

def create_csys_by_origin_and_base(origin,base_vector):

    # Create a new coordinate system
    csys = Model.CoordinateSystems.AddCoordinateSystem()
    
    # place csys origin at arbitrary location
    csys.SetOriginLocation(Quantity(origin[0],"mm"), Quantity(origin[1],"mm"), Quantity(origin[2],"mm"))
    # set base to arbitrary direction

    # rotate base vector
    primary_axis_corresponding = rotate_vector_around_y_axis(base_vector)
    csys.PrimaryAxisDirection = Vector3D(primary_axis_corresponding[0],primary_axis_corresponding[1],primary_axis_corresponding[2])
    
    # force a graphics redraw to update coordinate system graphics annotations
    csys.Suppressed=True
    csys.Suppressed=False
    
origin = [0,25,50]
base_vector = [1,2,3]
create_csys_by_origin_and_base(origin,base_vector)

当我在2022R2上时,文档中的源代码看起来像这样:https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/act_script/act_script_examples_arbitrary_cs.html?q=coordinate%20system

    • 编辑:**

添加了旋转矩阵,因为我错过了关键字基向量。

相关问题