← 返回题库
初级

用矩阵平移恐龙图像

未完成
初级参考 完整示例代码供参考,建议自己理解后重新输入
# Same code as above, except we define a new matrix
translation_matrix = ((1,0,-2),(0,1,-2),(0,0,1))
######################

dino_3d = [(x,y,1) for x,y in dino_vectors]

draw3d(
    Points3D(*dino_3d, color='C0'),
    *polygon_segments_3d(dino_3d, color='C0')
)

translated = [multiply_matrix_vector(translation_matrix, v) for v in dino_3d]

draw3d(
    Points3D(*dino_3d, color='C0'),
    *polygon_segments_3d(dino_3d,color='C0'),
    Points3D(*translated,color='C3'),
    *polygon_segments_3d(translated,color='C3')
)

translated_2d = [(x,y) for (x,y,z) in translated]

draw(
    Points(*dino_vectors, color='C0'),
    Polygon(*dino_vectors, color='C0'),
    Points(*translated_2d, color='C3'),
    Polygon(*translated_2d, color='C3'),
    save_as='figures/ex_5.27_second_dino.svg'
)
    plt.show()
Python 代码 🔒 登录后使用
🔒

登录后即可练习

注册免费账号,在浏览器中直接运行 Python 代码