Interfacing MATLAB With CAD - EMPossible

2y ago
25 Views
3 Downloads
3.45 MB
36 Pages
Last View : 1m ago
Last Download : 3m ago
Upload by : Madison Stoltz
Transcription

9/13/2018ECE 532221st Century r. Raymond C. RumpfA‐337(915) 747‐6958rcrumpf@utep.eduLecture #19Synthesizing Geometries for21st Century ElectromagneticsInterfacing MATLAB with CADLecture 191Lecture Outline STL Files– File format description– Problems and repairing MATLAB Topics––––Importing and exporting STL files in MATLABVisualizing surface meshes in MATLABGenerating faces and vertices using MATLABSurface mesh 3D grid CAD Topics–––––Lecture 19Converting flat images to STLPoint cloudsImporting custom polygons into SolidWorksSTL to CAD file conversionExporting STL from Blender with proper unitsSlide 21

9/13/2018STL File FormatDescriptionWhat is an STL File?STL – Standard Tessellation LanguageThis file format is widely used in rapidprototyping (i.e. 3D printing, additive manufacturing). Itcontains only a single triangular mesh of an objects surface.Color, texture, materials, and other attributes are notrepresented in the standard STL file format. Hackedformats exists to accommodate this type of additionalinformation.They can be text files or binary. Binary is more commonbecause they are more compact. We will look at text filesbecause that is more easily interfaced with MATLAB.Lecture 19Slide 42

9/13/2018Surface MeshDespite this sphere really being a solid object, it is represented in anSTL file by just its surface.Solid ObjectSTL RepresentationLecture 195STL File Formatsolid namefacet normal nx ny nzouter loopvertex vx,1 vy,1 vz,1vertex vx,2 vy,2 vz,2vertex vx,3 vy,3 vz,3endloopendfacetendsolid nameThis set of text is repeated for every triangle on thesurface of the object. v v v3 v1 nˆ 2 1 v2 v1 v3 v1 v2 v1 v3Bold face indicates a keyword; these must appear in lower case. Note that there is a space in “facet normal” and in“outer loop,” while there is no space in any of the keywords beginning with “end.” Indentation must be with spaces;tabs are not allowed. The notation, “{ } ,” means that the contents of the brace brackets can be repeated one ormore times. Symbols in italics are variables which are to be replaced with user-specified values. The numerical datain the facet normal and vertex lines are single precision floats, for example, 1.23456E 789. A facet normalcoordinate may have a leading minus sign; a vertex coordinate may not.Lecture 1963

9/13/2018Example STL Filesolid pyramidfacet normal -8.281842e-001 2.923717e-001 -4.781524e-001outer loopvertex 4.323172e-018 1.632799e-017 6.495190e-001vertex 3.750000e-001 7.081604e-001 4.330127e-001vertex 3.750000e-001 0.000000e 000 0.000000e 000endloopendfacetfacet normal 0.000000e 000 2.923717e-001 9.563048e-001outer loopvertex 7.500000e-001 0.000000e 000 6.495190e-001vertex 3.750000e-001 7.081604e-001 4.330127e-001vertex 0.000000e 000 0.000000e 000 6.495190e-001endloopendfacetfacet normal 8.281842e-001 2.923717e-001 -4.781524e-001outer loopvertex 3.750000e-001 -1.632799e-017 0.000000e 000vertex 3.750000e-001 7.081604e-001 4.330127e-001vertex 7.500000e-001 0.000000e 000 6.495190e-001endloopendfacetfacet normal 0.000000e 000 -1.000000e 000 0.000000e 000outer loopvertex 3.750000e-001 0.000000e 000 0.000000e 000vertex 7.500000e-001 0.000000e 000 6.495190e-001vertex 0.000000e 000 0.000000e 000 6.495190e-001endloopendfacetendsolid pyramidAn STL file is essentially just alist of all the triangles on thesurface of an object.Each triangle is defined with asurface normal and theposition of the three vertices.Lecture 19Slide 7A Single Trianglefacet normal -8.281842e-001 2.923717e-001 -4.781524e-001outer loopvertex 4.323172e-018 1.632799e-017 6.495190e-001vertex 3.750000e-001 7.081604e-001 4.330127e-001vertex 3.750000e-001 0.000000e 000 0.000000e 000endloopendfacet1. Facet normal must follow right‐handrule and point outward from object.a) Some programs set this to [0;0;0]or convey shading information.b) Don’t depend on it!2. Adjacent triangles must have twocommon vertices.3. STL files appear to be setup to handlearbitrary polygons. Don’t do this.Lecture 19Vertex 3Facet NormalVertex 1Vertex 2Slide 84

9/13/2018Warnings About Facet Normals Since the facet normal can be calculated from thevertices using the right-hand rule, sometimes thefacet normal in the STL file contains otherinformation like shading, color, etc. Don’t depend on the right-hand rule beingfollowed. Basically, don’t depend on anything!Lecture 199STL FileProblems andRepairing5

9/13/2018Inverted NormalsAll surface normals should point mlLecture 1911Intersecting TrianglesNo faces should cut through each other. Intersections should ure 19126

9/13/2018Noise ShellsA shell is a collection of triangles that form a single independentobject. Some STL files may contain small shells that are just noise.These should be eliminated.Main shellNoise ShellLecture 1913Nonmanifold MeshesA manifold (i.e. watertight) mesh has no holes and is described by asingle continuous surface.http://http://www.autodesk.com/Lecture 19147

9/13/2018Mesh Repair Software Commercial Software– Magics– NetFabb– SpaceClaim– Autodesk Open Source Alternatives– MeshLab– NetFabb Basic– Blender– Microsoft Model RepairLecture 19Slide 15Importing andExporting STLFiles in MATLAB8

9/13/2018MATLAB Functions for STL FilesThe Mathworks website has very good functions for reading andwriting STL files in both ASCII and binary formats.STL File xchange/29906‐binary‐stl‐file‐readerSTL File scii‐stl‐fileLecture 1917How to Store the DataWe have N facets and 3N vertices to store in arrays.F(N,3) Array of triangle facetsV(?,3) Array of triangle verticesMany times, the number of vertices is 3N. Observing that many ofthe triangle facets share vertices, there will be redundant vertices.STL files can be compressed to eliminate redundant vertices, butmany times they are not.Lecture 19189

9/13/2018Lazy Array of Vertices (1 of 2) vx ,1 vx ,2V vx , Mv y ,1v y ,2 vy ,Mvz ,1 vz ,2 vz , M V is an arraycontaining theposition of all thevertices in Cartesiancoordinates.582469M is the totalnumber of1vertices.71131210Lecture 1919Lazy Array of Vertices (2 of 2)There is redundancy here. Twelve vertices are stored, but the deviceis really only composed of four.While an inefficient representation,this is probably not worth your time fixing.2,5,8SolidWorks exports a lazy array of vertices. vx ,1 vx ,2V vx , MLecture 19v y ,1v y ,2 vy,Mvz ,1 vz ,2 vz , M 4,9,111,6,123,7,102010

9/13/2018Compact Array of Vertices vx ,1 vx ,2V vx ,3 vx ,4v y ,1v y ,2v y ,3v y ,4vz ,1 vz ,2 vz ,3 vz ,4 2222Array of Vertices, V414431134313Lecture 1921Array of Faces n1,1 n2,1F nN ,1n1,2n2,2 nN ,2F is an arrayindicating the arrayindices of thevertices definingthe facet.n1,3 n2,3 nN ,3 5all integers8224694N is the totalnumber offaces.Lecture 19711311312102211

9/13/2018Example of Lazy Arrays2,5,84,9,111,6,123,7,10Lecture 1923Example of Compact Arrays2413This can make a very large difference for large and complex objects.Lecture 192412

9/13/2018Eliminating Redundant VerticesRedundant vertices are easily eliminated using MATLAB’s built inunique() command.% ELIMINATE REDUNDENT VERTICES[V,indm,indn] unique(V,'rows');F indn(F);Identifies unique rows in Vand eliminates them from V.Corrects indices in F thatreferenced eliminated vertices.indm – indices of rows in V that correspond to unique vertices.indn – Map of row indices in original V to new row indices in the reduced V.Lecture 1925STL Files Generated bySolidWorksFor some reason, Solidworks does not use the z‐axis as the verticalaxis.For convenience, STL files can be easily reoriented.% REORIENT SOLIDWORKS AXES TO MATLAB AXESY V(:,2);V(:,2) V(:,3);V(:,3) Y;Orientation in SolidWorksLecture 19Imported OrientationAdjusted Orientation2613

9/13/2018VisualizingSurface Meshesin MATLABHow to Draw the ObjectGiven the faces and vertices, the object can be drawn in MATLABusing the patch() command.% DRAW STRUCTURE USING PATCHESP h',2);Lecture 192814

9/13/2018GeneratingFaces andVertices UsingMATLABMATLAB SurfacesSurfaces composed of square facets are stored in X, Y, and Z arrays.The surface shown is constructedof arrays that are all 5 5.Lecture 193015

9/13/2018Direct Construction of theSurface MeshMATLAB has a number of built‐in commands for generating surfaces.Some of these are cylinder(), sphere() and ellipsoid().% CREATE A UNIT SPHERE[X,Y,Z] sphere(41);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 VERTICESh .5 0.5 0.8],'EdgeColor','k');Lecture 1931Grid Surface Mesh3D objects on a grid can be converted to a surface mesh using thecommand isosurface().% CREATE ELLIPTICAL OBJECTOBJ (X/rx). 2 (Y/ry). 2 (Z/rz). 2;OBJ (OBJ 1);% CREATE SURFACE MESH[F,V] isosurface(X,Y,Z,OBJ,0.5);Object on 3D GridLecture 19Surface Mesh3216

9/13/2018May Need isocaps()When 3D objects extend to the edge of the grid, you may need touse isocaps() in addition to isosurface().isosurface()isocaps()isosurface() isocaps()% CREATE SURFACE MESH[F,V] isosurface(X,Y,Z,OBJ,0.5);[F2,V2] isocaps(X,Y,Z,OBJ,0.5);Lecture 1933Combining Faces and Verticesfrom Two ObjectsThere are no functions in MATLAB to perform Boolean operations on multiplemeshes. We can, however, combine the faces and vertices from two objects. Becareful this does not result in overlaps or gaps between objects.F1 and V1F2 and V2CorrectlyCombined% COMBINE FACES AND VERTICESF3 [ F1 ; F2 length(V1(:,1)) ]V3 [ V1 ; V2 ]Lecture 19IncorrectlyCombined% WRONG WAY TO% COMBINE FACES AND VERTICESF3 [ F1 ; F2 ]V3 [ V1 ; V2 ]3417

9/13/2018ConvertingSurface Meshesto Objects on a3D GridExample – PyramidER(nx,ny,nz)SolidWorks ModelLecture 19Import STL into MATLABConvert to Volume Object3618

9/13/2018Example – DinosaurER(nx,ny,nz)Import STL into MATLABConvert to Volume ObjectLecture 1937MATLAB Functions for“Voxelization” of STL FilesThe Mathworks website has excellent functions forconverting surface meshes to points on a 3D array.Function for /fileexchange/27390‐mesh‐voxelisationLecture 193819

9/13/2018ConvertingImages and 2DObjects to STLLoad and Resize the Image% LOAD IMAGEB imread(‘letter.jpg');% RESIZE IMAGEB imresize(B,0.2);[Nx,Ny,Nc] size(B);This will give us a coarser mesh in orderto be faster and more memory efficient.Lecture 194020

9/13/2018Flatten the ImageImages loaded from file usually contain RGBinformation making them 3D arrays. These arraysmust be converted to flat 2D arrays beforemeshing.%BBBFLATTEN COLOR IMAGE double(B); B(:,:,1) B(:,:,2) B(:,:,3); 1 - B/765;Lecture 1941Stack the ImageWe will mesh the image using isocaps(), butthat function requires a 3D array. So, we will stackthis image to be two layers thick.% STACK IMAGEB(:,:,2) B;Lecture 194221

9/13/2018Mesh the Image Usingisocaps()We only wish to mesh a single surface so we giveisocaps() the additional input argument‘zmin’ to do this.% CREATE 2D MESH[F,V] isocaps(ya,xa,[0 1],B,0.5,'zmin');Lecture 1943Save the Mesh as an STL FileWe can save this mesh as an STL file.Lecture 194422

9/13/2018Extrude Using Blender (1 of 2)1. Open Blender.exe.2. File Import Stl (.stl)3. Open the STL file you just created.Lecture 1945Extrude Using Blender (2 of 2)1. Select the object with rightmouse 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 objector export as a new 3D STL file.Lecture 194623

9/13/2018Point CloudsWhat is a Point Cloud?Klein Bottle (see MATLAB demos)Point Cloud Description of a Klein BottlePoint clouds represent the outside surface of object as a set of vertices defined by X, Y, and Zcoordinates. They are typically generated by 3D scanners, but can also be used to export 3Dobjects from MATLAB into SolidWorks or other CAD programs.Lecture 194824

9/13/2018Other Examples of Point CloudsLecture 1949Point Cloud DataThe position of all the points in the pointcloud can be stored in an array. x1 x 2PC x3 xNPC 0.12000.11590.03110.0000-0.0311-0.0600Lecture 19y1y2y3 yN0.0000-0.0311-0.1159-0.1200-0.1159-0.1039z1 z2 z3 z N 0.70710.70710.70710.70710.70710.70715025

9/13/2018Saving Point Cloud Data to File(1 of 2)Point cloud data files are comma separatedtext files with the extension “.xyz”These can be easily generated using thebuilt‐in MATLAB command csvwrite().% SAVE POINT CLOUD AS A COMMA SEPERATED FILEPC [ X Z Y wline','pc');PC [ X Y Z ];PC [ X Z Y ];Lecture 1951Saving Point Cloud Data to File(2 of 2)SolidWorks wants to see an X Y Z atthe start of the file.You can add this manually usingNotepad or write a more sophisticatedMATLAB text file creator.Lecture 195226

9/13/2018Activate ScanTo3D Add-In inSolidWorksFirst, you will need to activate theScanTo3D in SolidWorks.Click Tools Add‐Ins.Check the Scanto3D check box.Click OK.Lecture 1953Open the Point Cloud FileLecture 195427

9/13/2018Run the Mesh Prep WizardTools ScanTo3D Mesh Prep Wizard Lecture 191.2.3.4.Run the Mesh Prep Wizard.Select the point cloud.Click the right array button.Orientation method, select Nonebecause we did this in MATLAB.5. Noise removal, zero assuminggeometry came from MATLAB.6. Work through all options.7. Click the green check mark to finish.55Point Cloud DensityLecture 195628

9/13/2018Final Notes on Point Clouds Other CAD packages have better point cloudimport capabilities than SolidWorks. Rhino 3D issaid to be excellent. Generating a solid model from the data can bedone in SolidWorks. The meshed model isessentially used as a template for creating thesolid model. This procedure is beyond the scopeof this lecture.Lecture 1957ImportingCustomPolygons intoSolidWorks29

9/13/2018The ProblemSuppose we calculate the vertices of a polygon from an optimizationin MATLAB.How do we important thevertices so that the polygoncan be imported exactly intoSolidworks so that it can beextruded, cut, modified, etc.?There is no feature inSolidWorks to do this!!Lecture 1959Example ApplicationPlacing a GMR filter ontoa curved surface.Grating period is spatiallyvaried to compensate. sin x R x tan 1 R 1 d R cos x R K x K 0 k0 ninc sin inc x inc x x x K x dx 0 1 r x rcos x cos f cos x cos f R. C. Rumpf, M. Gates, C. L. Kozikowski, W. A. Davis,"Guided‐Mode Resonance Filter Compensated to Operateon a Curved Surface," PIER C, Vol. 40, pp. 93‐103, 2013.Lecture 196030

9/13/2018Be Careful About XYZ CurvesThere is a feature in SolidWorks “Curve Through XYZ Points” thatappears to import discrete points, but it fits the points to a spline.This effectively rounds any corners and may produce intersectionsthat cannot be rendered.This should be a square!The four points are fit to a spline!Lecture 1961Step 1 – Define the PolygonCreate an N 3 array in memory which contains all of the pointsaround the perimeter of the polygon. N is the number of points.P 0.38180.77950.82931.09720.6448Lecture 1

9/13/2018Step 2 – Save as an IGES fromMATLABThere is a function called igesout() available for free downloadfrom the Mathworks website. This will save your polygon to an IGESfile.% SAVE IGES FILEigesout(P,'poly');This creates a file called “poly.igs” in your working directory.Lecture 1963Step 3 – Open the IGES inSolidWorks (1 of 2)Select the IGES file type in the [Open] file dialog. Then click on the[Options ] button.Lecture 196432

9/13/2018Step 3 – Open the IGES inSolidWorks (2 of 2)1. Make sure that“Surface/solidentities” isunchecked2. Ensure that “Freepoint/curve entities”is checked.3. Click on the “Importas sketch(es) radiobutton.Open the file.Lecture 1965Step 4 – Convert to a Standard2D SketchThe polygon imports as a 3D sketch by default.Edit the 3D sketch and copy.Open a new 2D sketch and paste.Now you can do whatever you wish with the sketch! Extrude,revolve, cut extrude, etc.Lecture 196633

9/13/2018STL to CADConversionImport STL Into MeshLab1. Open meshlab.exe.2. File Import Mesh3. Open the 3D STL file you just created.Lecture 196834

9/13/2018Convert to SolidWorks Part1.2.3.4.5.6.7.8.Open meshlab.exe.File Export Mesh AsSelect DXF file type.Save mesh.Launch SolidWorks.File OpenSelect DXF file.Select ‘Import to a new part as:’then ‘3D curves or model’then ‘Next .’9. Select ‘All Layers’Lecture 1969Exporting STLfrom Blender withProper Units35

9/13/2018Properly Sizing STL Files inBlenderLecture 197136

21st Century Electromagnetics Interfacing MATLAB with CAD Lecture #19 Lecture 19 1 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 usi

Related Documents:

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for algebra, plotting, calculus, and solving differential .

19 MATLAB Excel Add-in Hadoop MATLAB Compiler Standalone Application MATLAB deployment targets MATLAB Compiler enables sharing MATLAB programs without integration programming MATLAB Compiler SDK provides implementation and platform flexibility for software developers MATLAB Production Server provides the most efficient development path for secure and scalable web and enterprise applications

MATLAB tutorial . School of Engineering . Brown University . To prepare for HW1, do sections 1-11.6 – you can do the rest later as needed . 1. What is MATLAB 2. Starting MATLAB 3. Basic MATLAB windows 4. Using the MATLAB command window 5. MATLAB help 6. MATLAB ‘Live Scripts’ (for

3. MATLAB script files 4. MATLAB arrays 5. MATLAB two‐dimensional and three‐dimensional plots 6. MATLAB used‐defined functions I 7. MATLAB relational operators, conditional statements, and selection structures I 8. MATLAB relational operators, conditional statements, and selection structures II 9. MATLAB loops 10. Summary

PART 1: Working With the CAD Standards Section 1. Purpose and scope of the CAD standards 1.1 Why WA DOC has data standards . 1.2 Scope of the CAD standards . 1. Who must use the standards? Section 2. CAD Environment 2. Basic CAD Software 1. CAD Application Software Section 3. Requesting CAD Data from WA DOC 2. How to request data Section 4.

foundation of basic MATLAB applications in engineering problem solving, the book provides opportunities to explore advanced topics in application of MATLAB as a tool. An introduction to MATLAB basics is presented in Chapter 1. Chapter 1 also presents MATLAB commands. MATLAB is considered as the software of choice. MATLAB can be used .

I. Introduction to Programming Using MATLAB Chapter 1: Introduction to MATLAB 1.1 Getting into MATLAB 1.2 The MATLAB Desktop Environment 1.3 Variables and Assignment Statements 1.4 Expressions 1.5 Characters and Encoding 1.6 Vectors and Matrices Chapter 2: Introduction to MATLAB Programming 2.1 Algorithms 2.2 MATLAB Scripts 2.3 Input and Output

accounting requirements for preparation of consolidated financial statements. IFRS 10 deals with the principles that should be applied to a business combination (including the elimination of intragroup transactions, consolidation procedures, etc.) from the date of acquisition until date of loss of control. OBJECTIVES/OUTCOMES After you have studied this learning unit, you should be able to .