(使用八进制)我有一个文本文件,其中以这种方式定义了三角形顶点:
((x11, y11, z11), (x12, y12, z12), (x13, y13, z13))((x21, y21, z21), (x22, y22, z22), (x23, y23, z23))...((xn1, yn1, zn1), (xn2, yn2, zn2), (xn3, yn3, zn3))
这是3D空间中的三角形列表,每个三角形定义为((xn1, yn1, zn1)(xn2, yn2, zn2)(xn3, yn3, zn3))
。
如何在Octave中导入此文件以查看生成的网格?我知道我可以使用trimesh
,但我无法解析此文件以检索点坐标。
编辑:这是一个带有三角形的真实文件:
((-0.780869, -1.56174, 4.68521), (-0.776988, -1.08169, 4.81936), (-0.776988, -2.02627, 4.5045))((-0.776988, -1.08169, 4.81936), (-0.765386, -0.590883, 4.90561), (-0.776988, -2.02627, 4.5045))((-0.776988, -2.02627, 4.5045), (-0.765386, -0.590883, 4.90561), (-0.765386, -2.47066, 4.27902))((-0.765386, -0.590883, 4.90561), (-0.746177, -0.0942074, 4.94311), (-0.765386, -2.47066, 4.27902))((-0.765386, -2.47066, 4.27902), (-0.746177, -0.0942074, 4.94311), (-0.746177, -2.8905, 4.01101))((-0.746177, -0.0942074, 4.94311), (-0.719552, 0.403404, 4.93148), (-0.746177, -2.8905, 4.01101))((-0.746177, -2.8905, 4.01101), (-0.719552, 0.403404, 4.93148), (-0.719552, -3.28161, 3.70314))((-0.719552, 0.403404, 4.93148), (-0.685776, 0.897006, 4.87084), (-0.719552, -3.28161, 3.70314))((-0.719552, -3.28161, 3.70314), (-0.685776, 0.897006, 4.87084), (-0.685776, -3.64011, 3.35847))((-0.685776, 0.897006, 4.87084), (-0.645184, 1.38169, 4.76179), (-0.685776, -3.64011, 3.35847))((-0.685776, -3.64011, 3.35847), (-0.645184, 1.38169, 4.76179), (-0.645184, -3.96243, 2.98042))((-0.645184, 1.38169, 4.76179), (-0.59818, 1.85265, 4.60542), (-0.645184, -3.96243, 2.98042))((-0.645184, -3.96243, 2.98042), (-0.59818, 1.85265, 4.60542), (-0.59818, -4.24537, 2.57274))((-0.59818, 1.85265, 4.60542), (-0.545231, 2.30519, 4.40327), (-0.59818, -4.24537, 2.57274))((-0.59818, -4.24537, 2.57274), (-0.545231, 2.30519, 4.40327), (-0.545231, -4.48612, 2.1395))((-0.545231, 2.30519, 4.40327), (-0.486864, 2.73482, 4.15737), (-0.545231, -4.48612, 2.1395))((-0.545231, -4.48612, 2.1395), (-0.486864, 2.73482, 4.15737), (-0.486864, -4.68228, 1.685))((-0.486864, 2.73482, 4.15737), (-0.423657, 3.13728, 3.87014), (-0.486864, -4.68228, 1.685))((-0.486864, -4.68228, 1.685), (-0.423657, 3.13728, 3.87014), (-0.423657, -4.83191, 1.21375))((-0.423657, 3.13728, 3.87014), (-0.356241, 3.50855, 3.54445), (-0.423657, -4.83191, 1.21375))((-0.423657, -4.83191, 1.21375), (-0.356241, 3.50855, 3.54445), (-0.356241, -4.93351, 0.730433))((-0.356241, 3.50855, 3.54445), (-0.285283, 3.84496, 3.18354), (-0.356241, -4.93351, 0.730433))((-0.356241, -4.93351, 0.730433), (-0.285283, 3.84496, 3.18354), (-0.285283, -4.98609, 0.23986))((-0.285283, 3.84496, 3.18354), (-0.211491, 4.14315, 2.79099), (-0.285283, -4.98609, 0.23986))((-0.285283, -4.98609, 0.23986), (-0.211491, 4.14315, 2.79099), (-0.211491, -4.98911, -0.253097))((-0.211491, 4.14315, 2.79099), (-0.135596, 4.40016, 2.3707), (-0.211491, -4.98911, -0.253097))((-0.211491, -4.98911, -0.253097), (-0.135596, 4.40016, 2.3707), (-0.135596, -4.94255, -0.743539))((-0.135596, 4.40016, 2.3707), (-0.0583544, 4.61344, 1.92684), (-0.135596, -4.94255, -0.743539))((-0.135596, -4.94255, -0.743539), (-0.0583544, 4.61344, 1.92684), (-0.0583544, -4.84686, -1.22659))
答案 0 :(得分:1)
(这是用MATLAB测试的,但也应该在Octave中正常工作)
要解析文件,您可以使用以下函数:
function A = fparse_triangle(fname)
f = fopen(fname, 'r');
A = reshape(fscanf(f, '((%f, %f, %f)(%f, %f, %f)(%f, %f, %f))'),3,3,[]);
fclose(f);
end
结果将是一个3×3×n 矩阵,在第一个索引上具有顶点坐标( X , Y , Z ),在具有三角形(第1,第2,第3)的顶点的第二索引上,以及在具有三角形的第三索引上。
稍后修改
此备选方案将考虑以逗号分隔的顶点,如最近添加的示例中所示:
function A = fparse_triangle_alt(fname)
f = fopen(fname, 'r');
A = reshape(fscanf(f, '((%f, %f, %f), (%f, %f, %f), (%f, %f, %f))'),3,3,[]);
fclose(f);
end
<强> NB 强>
请注意,从此到trimesh
调用会涉及更多处理。如果您需要帮助,请告诉我。