Translate the origin of a STL file

46 ビュー (過去 30 日間)
Pierrick Bersier
Pierrick Bersier 2014 年 9 月 5 日
コメント済み: Irene Yang 2019 年 10 月 6 日
I need to translate the origine of an STL. What I tried to do is to open the stl with the readstl script I found on the file exange. then I used reshape to do a 3 by n matrix with the cordinate:
X=reshape(coordinates, 3, [])';
Then I tooke of the offset I want to each point:
Y(i,:)=X(i,:)-Offset;
And generate a new STL from it with the stlwrite script also from the file exange.
stlwrite(strcat(input('Nom du fichier :','s'),'.stl'), Y(:, 1)', Y(:, 2)', Y(:, 3)', 'mode', 'ascii');
The problem I get is that when it build up the new stl is that the vertexes are in the good position according to the new origin but the facet are build "randomly" between any vertexes. (not randomly because it seems to build each time the same facet but not generate the same surface than the original file.)
I would really appreciate any help or advice about improving the my code or an other soft where it it is easier to translate the origin.
Thanks you all in advance.
  2 件のコメント
Sean de Wolski
Sean de Wolski 2014 年 9 月 5 日
Can you post the code you're using to do the offset start to finish?
Pierrick Bersier
Pierrick Bersier 2014 年 9 月 5 日
Here is the script with the two STL I used. The aim was to place the origin at the center off the femoral head. I tooke the coordinated of it using a stl fil that I cut off and let only the join head on it and then with the spherefit.
spherefit:

サインインしてコメントする。

採用された回答

Sean de Wolski
Sean de Wolski 2014 年 9 月 5 日
編集済み: Sean de Wolski 2014 年 9 月 5 日
Your logic and algorithm implementation look correct to me. I believe the problem is coming from the way you import the STL file. Instead of using that function, use one of the ones from the FEX that gives you an option to read it in as faces and vertices. E.g.
From here, repeat your centroid calculation and subtraction on the vertices component and then write it back out using the same faces and the modified vertices. The reason for the behavior you are seeing is because stlwrite is trying to connect the x/y/z data because it does not know the faces. A reader that gives you faces allows you it to skip this step.
  4 件のコメント
Pierrick Bersier
Pierrick Bersier 2014 年 9 月 8 日
編集済み: Pierrick Bersier 2014 年 9 月 8 日
Thanks you a lot one more time ! I finally get it to work ! You are awesome, I never expected such a fast answer !
Irene Yang
Irene Yang 2019 年 10 月 6 日
Sorry to bring this up again since it has been many years - but may I please ask what you did to solve this problem exactly? I have the same issue and when I tried the code, it didn't work.

サインインしてコメントする。

その他の回答 (0 件)

カテゴリ

Help Center および File ExchangeSTL (STereoLithography) についてさらに検索

製品

Community Treasure Hunt

Find the treasures in MATLAB Central and discover how the community can help you!

Start Hunting!

Translated by