WRL 和 VRML 到 Matplotlib/Numpy

计算科学 Python 可视化 麻木的 scipy 绘图
2021-12-26 21:59:28

我想在 python 中导入(或解析??)WRL/VRML文件格式,以便使用 Matplotlib 处理数据。有没有办法将此文件格式转换为可绘制的 numpy 数组?

我附上了一张使用FreeWRL查看器 可视化的 WRL 文件的照片在此处输入图像描述

1个回答

{假设您仍然需要代码} 让 A1.wrl 是您的 wrl 文件。

import matplotlib.pyplot as plt
from mpl_toolkits.mplot3d import Axes3D
import numpy as np
import re
holder = []
with open("A1.wrl", "rb") as vrml:
    for lines in vrml:
        a = re.findall("[-0-9]{1,3}.[0-9]{6}", lines)
        if len(a) == 3:
            holder.append(map(float, a))

holder_array = np.array(holder) #if you want numpy array

#3D Plotting
x,y,z = zip(*holder)
fig = plt.figure()
ax = Axes3D(fig)
ax.plot(x,y,z)
plt.show()

我的 A.wrl:http ://pastebin.com/PeVXbR5C

文件生成:

在此处输入图像描述