-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathindexExtract.m
63 lines (51 loc) · 1.63 KB
/
indexExtract.m
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
function [] = indexExtract(stlfile)
% Get filename without extension
[pathstr, stlname, ext] = fileparts(stlfile);
% Read stl file
[Face,Vertex] = stlread(stlfile);
Vertex=10*[Vertex(:,1),Vertex(:,3)];
[row_face, ~]=size(Face);
% % Find the origin of the 2D shape
% Xc=(min(Vertex(:,1))+max(Vertex(:,1)))/2;
% Yc=(min(Vertex(:,2))+max(Vertex(:,2)))/2;
%
% % Move the center of the coordinate system to the origin
% Vertex(:,1)=Vertex(:,1)-Xc;
% Vertex(:,2)=Vertex(:,2)-Yc;
% Xc=(min(Vertex(:,1))+max(Vertex(:,1)))/2;
% Yc=(min(Vertex(:,2))+max(Vertex(:,2)))/2;
% Bounding box
X_max=20;
X_min=-20;
Y_max=20;
Y_min=-20;
% 2D grid
N=100; % grid dimension
X_step=(X_max-X_min)/(N-1);
Y_step=(Y_min-Y_max)/(N-1);
[X,Y]=meshgrid(X_min:X_step:X_max, Y_max:Y_step:Y_min);
% Check if grid points are inside
% grid_point=zeros(N,N);
% Name the text file of path
indexname = [stlname '_index_100.txt'];
pathname = fileparts('C:\Users\Jun\Dropbox\SLA_database\abaqus_INDEX\abaqus_INDEX7\');
txtfile = fullfile(pathname, indexname);
fileID = fopen(txtfile, 'w');
for i=1:N
for j=1:N
for k=1:row_face
b=isPointInTriangle([X(i,j),Y(i,j)],[Vertex(Face(k,1),:);Vertex(Face(k,2),:);Vertex(Face(k,3),:)]);
if b==1
% grid_point(i,j)=1;
% fprintf(['X(',num2str(i),',',num2str(j),')=',num2str(X(i,j)),'\n']);
% X(i,j)
% fprintf(['Y(',num2str(i),',',num2str(j),')=',num2str(Y(i,j)),'\n']);
% Y(i,j)
fprintf(fileID, [num2str(i),',',num2str(j),'\r\n']);
% fprintf([num2str(i),',',num2str(j),'\n']);
break;
end
end
end
end
fclose(fileID);