[3D 再構成] Matlab が .wrl 3D 画像ファイルを読み取る

Matlab は .wrl 3D 画像ファイルを読み取ります

1.wrlファイル

  • wrl (仮想現実言語): wrl ファイルは、仮想現実テキスト形式のファイルです。VRML シーン モデル ファイルの拡張子でもあります。
  • wrl ファイルは純粋な ASCII ファイルであるため、テキスト エディタで開いて編集できます。それでも、大きな 3D ファイルの場合です。純粋に手動の方法を使用することはお勧めできません。シーンのモデリングと出力には 3D ソフトウェア (maya、max など) を使用することを選択する必要があります。
  • SolidWorks作成およびエクスポート可能
  • 視覚化はmatlabで開くことができます

たとえば、scene.wrlファイルの内容は次のとおりです。

#VRML V2.0 utf8
Transform {
	children [
		DEF model1 Transform {
			children [
				DEF body1 Transform {
					translation -1 0 0
					children [
						DEF shape1 Shape {
							appearance Appearance {
								material Material {
									diffuseColor 1.0 1.0 0.0
								}
							}
							geometry Box {
								size 1.5 1.5 1.5
							}
						}
					]
				}
			]
		}
		DEF model2 Transform {
			children [
				DEF body2 Transform {
					translation 1 0 0
					children [
						DEF shape2 Shape {
							appearance Appearance {
								material Material {
									diffuseColor 1.0 1.0 0.0
								}
							}
							geometry Box {
								size 1.5 1.5 1.5
							}
						}
					]
				}
			]
		}
	]
}

2. matlab で .wrl ファイルを開きます

%********************打开.wrl文件*************
vrsetpref('DefaultViewer', 'internalv5')
w = vrworld('scene.wrl');
open(w);
view(w);

ここに画像の説明を挿入

3. Matlab は wrl で 3 次元座標点を描画します

.wrl ファイルを txt 形式で開き、点セットの座標を matlab コードに直接コピーし、座標の各行の後に追加します。...

%绘制三维点
%%base_link
P=[ -0.075000 -0.100000 0.000000, -0.075000 -0.100000 0.570000, -0.075000 -0.075000 0.436008, -0.075000 -0.073559 0.421376, -0.075000 -0.073559 0.450639,...
 -0.075000 -0.069291 0.407306, -0.075000 -0.069291 0.464709, -0.075000 -0.062360 0.394340, -0.075000 -0.062360 0.477675, -0.075000 -0.053033 0.382975,...
 -0.075000 -0.053033 0.489041, -0.075000 -0.041668 0.373647, -0.075000 -0.041668 0.498368, -0.075000 -0.028701 0.366717, -0.075000 -0.028701 0.505299,...
 -0.075000 -0.014632 0.362449, -0.075000 -0.014632 0.509567, -0.075000 0.000000 0.361008, -0.075000 0.000000 0.511008, -0.075000 0.014632 0.362449,...
 -0.075000 0.014632 0.509567, -0.075000 0.028701 0.366717, -0.075000 0.028701 0.505299, -0.075000 0.041668 0.373647, -0.075000 0.041668 0.498368,...
 -0.075000 0.053033 0.382975, -0.075000 0.053033 0.489041, -0.075000 0.062360 0.394340, -0.075000 0.062360 0.477675, -0.075000 0.069291 0.407306,...
 -0.075000 0.069291 0.464709, -0.075000 0.073559 0.421376, -0.075000 0.073559 0.450639, -0.075000 0.075000 0.436008, -0.075000 0.100000 0.000000,...
 -0.075000 0.100000 0.570000, -0.025000 -0.075000 0.436008, -0.025000 -0.073559 0.421376, -0.025000 -0.073559 0.450639, -0.025000 -0.069291 0.407306,...
 -0.025000 -0.069291 0.464709, -0.025000 -0.062360 0.394340, -0.025000 -0.062360 0.477675, -0.025000 -0.053033 0.382975, -0.025000 -0.053033 0.489041,...
 -0.025000 -0.041668 0.373647, -0.025000 -0.041668 0.498368, -0.025000 -0.028701 0.366717, -0.025000 -0.028701 0.505299, -0.025000 -0.014632 0.362449,...
 -0.025000 -0.014632 0.509567, -0.025000 0.000000 0.361008, -0.025000 0.000000 0.436008, -0.025000 -0.000000 0.511008, -0.025000 0.014632 0.362449,...
 -0.025000 0.014632 0.509567, -0.025000 0.028701 0.366717, -0.025000 0.028701 0.505299, -0.025000 0.041668 0.373647, -0.025000 0.041668 0.498368,...
 -0.025000 0.053033 0.382975, -0.025000 0.053033 0.489041, -0.025000 0.062360 0.394340, -0.025000 0.062360 0.477675, -0.025000 0.069291 0.407306,...
 -0.025000 0.069291 0.464709, -0.025000 0.073559 0.421376, -0.025000 0.073559 0.450639, -0.025000 0.075000 0.436008, 0.075000 -0.100000 0.000000,...
 0.075000 -0.100000 0.570000, 0.075000 0.100000 0.000000, 0.075000 0.100000 0.570000 ]

i=1
while i<length(P)
    scatter3(P(i),P(i+1),P(i+2));
    hold on
    i=i+3;
end

ここに画像の説明を挿入

4. 3D 点の空間回転変換を実行します。

%旋转矩阵:
%绕x\y\z轴旋转,输入弧度
function [R]=getR(a,flg)
    R=[]
    if(flg==0)
        R=[ 1  0  0;
        0  cos(a) -sin(a);
        0  sin(a)  cos(a)];
    elseif(flg==1)
        R=[ cos(a)  0  sin(a);
        0  1  0 ;
        -sin(a)  0  cos(a)];
    elseif(flg==2)
        R=[ cos(a) -sin(a)  0;
        sin(a)  cos(a)  0  ;
        0  0  1];
    end
end

見出し 3 の点セット形式に従って、計算は次のようになります。

rx=getR(-pi/2,0);
points0=points*rx

ry=getR(-pi/2,1);
points1=points*ry

rz=getR(-pi/2,2)
points2=point*rz

おすすめ

転載: blog.csdn.net/yohnyang/article/details/126765446#comments_27620931