How to 3d patch between 2 3d shapes (stl attached)
Show older comments
Hello, I'm trying to fill in or create 2 lids on top and bottom sides for this 3d shape and then extract it as stl, but I'm not sure how.
close all
clc
clear all
TR = stlread ('.stl');
x = TR.Points(:,1); % inner surface
y = TR.Points(:,2); % inner surface
z = TR.Points(:,3); % inner surface
xyz = [(mean (x)) ; (mean (y)); (mean(z))]; %centroid
n=size(x);
scatter3(mean(x),mean(y),mean(z));
hold on
% x(1:n)=x(1:n)+1;
% y(1:n)=y(1:n)+1;
% z(1:n)=z(1:n)+1;
scatter3(x,y,z);
% vector definitions
x1 = x(:,1) -xyz(1);
y1 = y(:,1) - xyz(2);
z1 = z(:,1) - xyz(3);
%length of the vector
x2 = sqrt ((x1(:,1).^2) + (y1(:,1).^2) + (z1(:,1).^2));
thickness = 2; % desired thickness
x2mod = x2(:,1) + thickness; %%length + demanded thickness
SF = x2mod(:,1)./x2(:,1); % scaling factor
% accounting for different references
X =x(:,1).*(SF(:,1));
X = X + xyz(1).*(1- SF); %% final X coordinates of the outer surface
Y =y(:,1).*(SF(:,1));
Y = Y + xyz(2).*(1- SF); %% final Y coordinates of the outer surface
Z =z(:,1).*(SF(:,1));
Z = Z + xyz(3).*(1- SF); %% final Z coordinates of the outer surface
hold on
scatter3(X,Y,Z); % final plot
i = TR.ConnectivityList % connectivity list
k= [ X(:,1) , Y(:,1), Z(:,1) ];
TR1 = triangulation(k,X,Y,Z); %%isn't working and showing this error (The input triangulation must contain index values. Entries with fractional parts are invalid.)
the outer surface is the yellow one and the inner surface is the red one. Accepted Answer
More Answers (1)
Shaik
on 12 May 2023
0 votes
The error "unable to open file .stl" suggests that MATLAB is unable to find the STL file you are trying to import.
In the first line of your code, you should replace '.stl' with the actual name of the STL file you want to import, including the file extension.
So, for example, if your STL file is named my_stl_file.stl and is located in the same directory as your MATLAB script, you would modify the first line of your code to:
TR = stlread ('my_stl_file.stl');
Make sure to replace my_stl_file.stl with the actual name of your STL file. If the file is located in a different directory, you will need to specify the full file path in single quotes.
If the file still cannot be found, make sure to check that the name and location of the STL file are correct, and that you have read permissions for the file and directory.
Categories
Find more on Data Type Identification in Help Center and File Exchange
Community Treasure Hunt
Find the treasures in MATLAB Central and discover how the community can help you!
Start Hunting!






