Download presentation
Presentation is loading. Please wait.
1
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
2
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
3
Example Data format: –Polygonal parts –List of vertices –(0,0) as the separator Data file: 1.00 1.00 3.00 1.00 3.50 2.75 1.50 2.75 0 0 1.50 3.25 2.00 3.25 1.75 5.00 0 0 4.00 3.25 5.50 3.25 3.50 5.00 5.75 5.00 x Desired cut pattern y
4
Structured Programming Divide and subdivide the project. Write functions for the parts. Manage complexity Debugable Readable Testable Reusable functions Maintainable
5
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
6
Example 1 – clipping a time plot to [-1,1]: Time (sec.)
7
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
8
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
9
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
10
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
11
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
Similar presentations
© 2025 SlidePlayer.com. Inc.
All rights reserved.