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)
1条答案
按热度按时间6ojccjat1#
我假设你在Ansys Mechanical内部工作。我在文档中找到了这个片段,并添加了绕y轴逆时针旋转90 °的函数:
当我在2022R2上时,文档中的源代码看起来像这样:https://ansyshelp.ansys.com/account/secured?returnurl=/Views/Secured/corp/v222/en/act_script/act_script_examples_arbitrary_cs.html?q=coordinate%20system
添加了旋转矩阵,因为我错过了关键字基向量。