91av视频/亚洲h视频/操亚洲美女/外国一级黄色毛片 - 国产三级三级三级三级

  • 大小: 3KB
    文件類型: .m
    金幣: 1
    下載: 0 次
    發布日期: 2021-05-13
  • 語言: Matlab
  • 標簽: MATLAB??STL文件??

資源簡介

此程序可以焊好的讀取STL文件,可以輸出F(面數),V(頂點),N(三角面片的法向量)等,可以穩定輸出

資源截圖

代碼片段和文件信息

function?varargout?=?stlread(file)

%?讀取STL模型
????if?~exist(file‘file‘)%判斷文件是否存在
????????error([‘File?‘‘%s‘‘?not?found.?If?the?file?is?not?on?MATLAB‘‘s?path‘?...
???????????????‘?be?sure?to?specify?the?full?path?to?the?file.‘]?file);
????end
????
????fid?=?fopen(file‘r‘);????
????if?~isempty(ferror(fid))
????????error(lasterror);?%#ok
????end??
????M?=?fread(fidinf‘uint8=>uint8‘);%進行讀取
????fclose(fid);
????[fvn]?=?stlbinary(M);
????%if(?isbinary(M)?)
????%????[fvn]?=?stlbinary(M);
????%else
????%????[fvn]?=?stlascii(M);
????%end
????
????varargout?=?cell(1nargout);%函數輸出
????switch?nargout????????
????????case?2
????????????varargout{1}?=?f;%f為面(face)
????????????varargout{2}?=?v;%v為頂點坐標(vertices)
????????case?3
????????????varargout{1}?=?f;
????????????varargout{2}?=?v;
????????????varargout{3}?=?n;%為面的法向量
????????otherwise
????????????varargout{1}?=?struct(‘faces‘f‘vertices‘v);
????end

end

function?[FVN]?=?stlbinary(M)

????F?=?[];
????V?=?[];
????N?=?[];
????
????if?length(M)?????????error(‘MATLAB:stlread:incorrectFormat‘?...
??????????????‘Incomplete?header?information?in?binary?STL?file.‘);
????end
????
????%?字節81-84為一個無符號的32位整數,用于指定后面的面數。
????numFaces?=?typecast(M(81:84)‘uint32‘);
????%numFaces?=?double(numFaces);
????if?numFaces?==?0?%判斷STL模型中的面熟
????????warning(‘MATLAB:stlread:nodata‘‘No?data?in?STL?file.‘);
????????return
????end
????
????T?=?M(85:end);
????F?=?NaN(numFaces3);
????V?=?NaN(3*numFaces3);%一個三角面片三個頂點,頂點數為面數的

評論

共有 條評論