Semester Project Introduction Computer control of a cutting machine 1. Given a data file description of desired 2-D parts 2. Create software tools to: a. Compute the characteristics of the parts (area, perimeter, centroid locations) b. Solve for the cutter route (simplest to most efficient) c. Graphically display results
fscanf Create a link to a file fid = fopen(‘filename’) Read a line of data x = fscanf(fid, %f, 2) Close the link close(fid) Number of values read
Example Data format: –Polygonal parts –List of vertices –(0,0) as the separator Data file: x Desired cut pattern y
Structured Programming Divide and subdivide the project. Write functions for the parts. Manage complexity Debugable Readable Testable Reusable functions Maintainable
Structured Programming Hierarchical Modules are divided into smaller and smaller submodules (functions work well as modules) functions contain functions Modular Simple independent modules with well defined inputs and outputs Locality Minimize inputs and outputs Generate values inside the module where possible
Example 1 – clipping a time plot to [-1,1]: Time (sec.)
Method 1 – using a loop and branch: for k = 1:length(y) if y(k) > 1 y(k) = 1; elseif y(k) < -1 y(k) = -1; end
Method 2 – using mask math: p = y>1; n = y<-1; y = (1-p).*(1-n).*y + p - n; or p = y>1; n = y<-1; y = ~p.*~n.*y + p - n; “mask” arrays to indicate locations with relevant characteristics use masks either mathematically or logically
Method 3 – using mask addressing: p = y>1; or n = y<-1; y(p) = 1;y(y>1) = 1; y(n) = -1;y(y<-1) = -1; mask determines which elements to change
Method 1 – loop and branch: for k = 1:size(score,1) if score(k,1) < score(k,2) score(k,:) = score(k,[2 1]); end size with second argument 1 returns the number of rows
Method 2 – using mask addressing: flip = score(:,1)<score(:,2); score(flip,[1 2]) = score(flip,[2 1]) identify which rows to swap and reverse them