Synthesizing Geometries For 21st Century Electromagnetics: Lecture Outline
Synthesizing Geometries For 21st Century Electromagnetics: Lecture Outline
Synthesizing Geometries For 21st Century Electromagnetics: Lecture Outline
ECE 5322
21st Century Electromagnetics
Instructor: Dr. Raymond C. Rumpf
Office: A‐337
Phone: (915) 747‐6958
E‐Mail: rcrumpf@utep.edu
Lecture #19
Lecture Outline
• STL Files
– File format description
– Problems and repairing
• MATLAB Topics
– Importing and exporting STL files in MATLAB
– Visualizing surface meshes in MATLAB
– Generating faces and vertices using MATLAB
– Surface mesh 3D grid
• CAD Topics
– Converting flat images to STL
– Point clouds
– Importing custom polygons into SolidWorks
– STL to CAD file conversion
– Exporting STL from Blender with proper units
Lecture 19 Slide 2
1
9/13/2018
2
9/13/2018
Surface Mesh
Despite this sphere really being a solid object, it is represented in an
STL file by just its surface.
Solid Object
STL Representation
Lecture 19 5
Lecture 19 6
3
9/13/2018
A Single Triangle
facet normal -8.281842e-001 2.923717e-001 -4.781524e-001
outer loop
Vertex 3
vertex 4.323172e-018 1.632799e-017 6.495190e-001
vertex 3.750000e-001 7.081604e-001 4.330127e-001
vertex 3.750000e-001 0.000000e+000 0.000000e+000
endloop
endfacet
Facet Normal
1. Facet normal must follow right‐hand
rule and point outward from object.
a) Some programs set this to [0;0;0]
or convey shading information. Vertex 1
b) Don’t depend on it!
2. Adjacent triangles must have two
common vertices. Vertex 2
3. STL files appear to be setup to handle
arbitrary polygons. Don’t do this.
Lecture 19 Slide 8
4
9/13/2018
Lecture 19 9
STL File
Problems and
Repairing
5
9/13/2018
Inverted Normals
All surface normals should point outwards.
Good Bad
http://admproductdesign.com/workshop/3d‐printing/definition‐of‐stl‐errors.html
Lecture 19 11
Intersecting Triangles
No faces should cut through each other. Intersections should be
removed.
http://admproductdesign.com/workshop/3d‐printing/definition‐of‐stl‐errors.html
Lecture 19 12
6
9/13/2018
Noise Shells
A shell is a collection of triangles that form a single independent
object. Some STL files may contain small shells that are just noise.
These should be eliminated.
Main shell
Noise Shell
Lecture 19 13
Nonmanifold Meshes
A manifold (i.e. watertight) mesh has no holes and is described by a
single continuous surface.
http://http://www.autodesk.com/
Lecture 19 14
7
9/13/2018
Importing and
Exporting STL
Files in MATLAB
8
9/13/2018
STL File Reader
http://www.mathworks.com/matlabcentral/fileexchange/29906‐binary‐stl‐file‐reader
STL File Writer
http://www.mathworks.com/matlabcentral/fileexchange/36770‐stlwrite‐write‐binary‐or‐
ascii‐stl‐file
Lecture 19 17
Many times, the number of vertices is 3N. Observing that many of
the triangle facets share vertices, there will be redundant vertices.
STL files can be compressed to eliminate redundant vertices, but
many times they are not.
Lecture 19 18
9
9/13/2018
M is the total
number of 7
vertices. 1
3 11
12
10
Lecture 19 19
vx ,1 v y ,1 vz ,1
v v y ,2 vz ,2
V
x ,2 4,9,11
1,6,12
vx , M vy,M vz , M
3,7,10
Lecture 19 20
10
9/13/2018
1 3
1
3
3 4
1
Lecture 19 3 21
Array of Faces
5
n1,1 n1,2 n1,3
n n2,2 n2,3 all integers
F
2,1
8
2
nN ,1 nN ,2 nN ,3
2
4
F is an array 6
indicating the array
indices of the
vertices defining 9
the facet.
4
1 7
1
3
N is the total 11
3
number of
faces. 12
Lecture 19 10 22
11
9/13/2018
2,5,8
4,9,11
1,6,12
3,7,10
Lecture 19 23
3
This can make a very large difference for large and complex objects.
Lecture 19 24
12
9/13/2018
Lecture 19 25
Lecture 19 26
13
9/13/2018
Visualizing
Surface Meshes
in MATLAB
Lecture 19 28
14
9/13/2018
Generating
Faces and
Vertices Using
MATLAB
MATLAB Surfaces
Surfaces composed of square facets are stored in X, Y, and Z arrays.
The surface shown is constructed
of arrays that are all 5×5.
Lecture 19 30
15
9/13/2018
Surfaces can be converted to triangular patches (facets and vertices)
using the surf2patch() function.
% CONVERT TO PATCH
[F,V] = surf2patch(X,Y,Z,’triangles’);
The faces and vertices can be directly visualized using the patch()
function.
% VISUALIZE FACES AND VERTICES
h = patch('faces',F,'vertices',V);
set(h,'FaceColor',[0.5 0.5 0.8],'EdgeColor','k');
Lecture 19 31
Object on 3D Grid Surface Mesh
Lecture 19 32
16
9/13/2018
Lecture 19 33
Correctly Incorrectly
F1 and V1 F2 and V2 Combined Combined
17
9/13/2018
Converting
Surface Meshes
to Objects on a
3D Grid
Example – Pyramid
ER(nx,ny,nz)
SolidWorks Model
Import STL into MATLAB Convert to Volume Object
Lecture 19 36
18
9/13/2018
Example – Dinosaur
ER(nx,ny,nz)
Import STL into MATLAB Convert to Volume Object
Lecture 19 37
Function for Voxelization
http://www.mathworks.com/matlabcentral/fileexchange/27390‐
mesh‐voxelisation
Lecture 19 38
19
9/13/2018
Converting
Images and 2D
Objects to STL
% LOAD IMAGE
B = imread(‘letter.jpg');
% RESIZE IMAGE
B = imresize(B,0.2);
[Nx,Ny,Nc] = size(B);
This will give us a coarser mesh in order
to be faster and more memory efficient.
Lecture 19 40
20
9/13/2018
Images loaded from file usually contain RGB
information making them 3D arrays. These arrays
must be converted to flat 2D arrays before
meshing.
Lecture 19 41
We will mesh the image using isocaps(), but
that function requires a 3D array. So, we will stack
this image to be two layers thick.
% STACK IMAGE
B(:,:,2) = B;
Lecture 19 42
21
9/13/2018
We only wish to mesh a single surface so we give
isocaps() the additional input argument
‘zmin’ to do this.
% CREATE 2D MESH
[F,V] = isocaps(ya,xa,[0 1],B,0.5,'zmin');
Lecture 19 43
Lecture 19 44
22
9/13/2018
1. Open Blender.exe.
2. File Import Stl (.stl)
3. Open the STL file you just created.
Lecture 19 45
1. Select the object with right
mouse click.
2. Press TAB to enter Edit mode.
3. Press ‘e’ to extrude mesh.
4. Press TAB again to exit Edit mode.
5. You can now edit your object
or export as a new 3D STL file.
Lecture 19 46
23
9/13/2018
Point Clouds
Point clouds represent the outside surface of object as a set of vertices defined by X, Y, and Z
coordinates. They are typically generated by 3D scanners, but can also be used to export 3D
objects from MATLAB into SolidWorks or other CAD programs.
Lecture 19 48
24
9/13/2018
Lecture 19 49
PC =
0.1200 0.0000 0.7071
0.1159 -0.0311 0.7071
0.0311 -0.1159 0.7071
0.0000 -0.1200 0.7071
-0.0311 -0.1159 0.7071
-0.0600 -0.1039 0.7071
Lecture 19 50
25
9/13/2018
These can be easily generated using the
built‐in MATLAB command csvwrite().
PC = [ X Y Z ]; PC = [ X Z Y ];
Lecture 19 51
You can add this manually using
Notepad or write a more sophisticated
MATLAB text file creator.
Lecture 19 52
26
9/13/2018
Click ToolsAdd‐Ins.
Check the Scanto3D check box.
Click OK.
Lecture 19 53
Lecture 19 54
27
9/13/2018
ToolsScanTo3DMesh Prep Wizard…
1. Run the Mesh Prep Wizard.
2. Select the point cloud.
3. Click the right array button.
4. Orientation method, select None
because we did this in MATLAB.
5. Noise removal, zero assuming
geometry came from MATLAB.
6. Work through all options.
7. Click the green check mark to finish.
Lecture 19 55
Lecture 19 56
28
9/13/2018
Lecture 19 57
Importing
Custom
Polygons into
SolidWorks
29
9/13/2018
The Problem
Suppose we calculate the vertices of a polygon from an optimization
in MATLAB.
How do we important the
vertices so that the polygon
can be imported exactly into
Solidworks so that it can be
extruded, cut, modified, etc.?
There is no feature in
SolidWorks to do this!!
Lecture 19 59
Example Application
Placing a GMR filter onto Grating period is spatially
a curved surface. varied to compensate.
x sin x R
inc x tan 1
R 1 d R cos x R
K x K 0 k0 ninc sin inc x
x
x K x dx
0
R. C. Rumpf, M. Gates, C. L. Kozikowski, W. A. Davis,
"Guided‐Mode Resonance Filter Compensated to Operate
on a Curved Surface," PIER C, Vol. 40, pp. 93‐103, 2013.
Lecture 19 60
30
9/13/2018
This should be a square! The four points are fit to a spline!
Lecture 19 61
P =
0.6448 0 0
1.0941 0.3758 0
1.3427 1.0452 0
0.3642 0.5573 0
0.4753 1.8765 0
-0.0651 0.7853 0
-0.5258 1.1984 0
-0.4824 0.5240 0
-0.8912 0.4822 0
-0.9966 0.1664 0
-0.9087 -0.1517 0
-1.0666 -0.5774 0
-1.1762 -1.2777 0
-0.5403 -1.2314 0
-0.1403 -1.6931 0
0.3818 -1.5074 0
0.7795 -1.1927 0
0.8293 -0.6455 0
1.0972 -0.3766 0
0.6448 -0.0000 0
Lecture 19 62
31
9/13/2018
This creates a file called “poly.igs” in your working directory.
Lecture 19 63
Lecture 19 64
32
9/13/2018
Open the file.
Lecture 19 65
Lecture 19 66
33
9/13/2018
STL to CAD
Conversion
Lecture 19 68
34
9/13/2018
Lecture 19 69
Exporting STL
from Blender with
Proper Units
35
9/13/2018
Lecture 19 71
36