CS 1112 Project 2, part A due Mon, Mar. 8, 11pm EST

(Part B will appear in a separate document. Both parts have the same submission deadline.)

You must work either on your own or with one partner. If you work with a partner you must first register as a group in CMS and then submit your work as a group. Adhere to the Code of Academic Integrity. For a group, “you” below refers to “your group.” You may discuss background issues and general strategies with others and seek help from the course staff, but the work that you submit must be your own. In particular, you may discuss general ideas with others but you may not work out the detailed solutions with others. It is not OK for you to see or hear another student’s code and it is certainly not OK to copy code from another person or from published/Internet sources. If you feel that you cannot complete the assignment on you own, seek help from the course staff.

Objectives

Completing this project will solidify your understanding of for-loops, while-loops, and nested loops (Chapters 2 and 3 in Insight) and give you practice with the accumulation pattern. You will also continue to explore Matlab graphics.

Ground rule

Since this is an introductory computing course, and in order to give you practice on specific programming constructs, some Matlab functions/features are forbidden in assignments. Specifically, the use of arrays and the break and continue commands is not allowed in this project. Only the built-in functions that have been discussed in class and in the assigned reading may be used. For this project, do not write user-defined functions; we will do that later in Project 3.

Rocket fuel gauge

Diagram of cylindrical tank

A rocket’s liquid oxygen tank is formed as a cylinder of radius r with hemispherical end caps (also of radius r), as shown in the figure to the right. The tank has a height h, where h ≥ 2r (which would be the height of the caps alone). By measuring the difference in pressure between the top and bottom of the tank, engineers can infer the depth d of propellant in the tank. But in order to know how much longer they can fire the engines, they must determine the volume of propellant remaining.

Write a script to compute the volume of liquid in the tank at n different “fill depths” d and make a plot of volume versus depth. The n values of d should be equally spaced from 0 to h, inclusive; your script should prompt the user to input a value for n, which you may assume will be an integer greater than 2. Solicit user input for r and h in meters as well. If the user-provided value of h is less than or equal to 2r, set h to 2r and print a message to the Command Window showing the new value of h.

Your script tank should have the following “outline”:

% Solicit input for r, h, and n. Change h if necessary.

close all    % Close all figure windows
figure       % Start a figure window
hold on      % Keep all subsequent plot commands on same axes

% Your code to calculate the volume and plot volume versus depth

hold off     % Subsequent plot command is shown on fresh axes

Note these hints and additional specifications:

Polar 3D printer

Diagram of polar 3D printer

In a 3D printer, plastic is extruded through a nozzle over a build surface. By moving the nozzle relative to the surface, material can deposited in an arbitrary pattern within a horizontal layer, and by stacking many such layers, a three-dimensional object is formed. In many 3D printers, the nozzle is able to move left and right along the x-axis (from a top-down view) while the build surface slides along the y-axis (with layers stacking up the z-axis).

However, in a polar 3D printer, the build surface is a circular turntable that spins about its center, while the nozzle is attached to an arm that pivots about a point just off the edge of the turntable (see figure). By making the length of the pivot arm equal to the radius of the turntable, the nozzle can be positioned over any point on the turntable by controlling a combination of spin angle φ (“phi”) and pivot angle θ (“theta”). Printing circular shapes is easy with such a setup (the turntable just spins under a fixed nozzle), but printing straight lines evenly is more difficult.

Our goal is to print a straight line from the center of the build surface to its edge, represented by the dotted line in the figure. Initially, both φ and θ are 0°; then, as the turntable spins (increasing φ), we must pivot the arm (increasing θ) at a different rate so that the nozzle (denoted by P) stays on the line. While the required pivot can be computed analytically, we will instead take an iterative approach inspired by feedback control: starting with the nozzle over the center (θ = 0°), increase θ by a fixed amount until the angle that the nozzle makes with respect to the horizontal line in the figure is equal to the turntable angle φ. More specifically, we want to increase θ until the difference between φ and the angle to P changes sign; that final value of θ is our solution. Along the way, we should plot this difference vs. θ to visualize our approach.

Download the file polarPrinter.m from the Projects page. Read and run it. Since the program is incomplete, the output includes only a figure window with axis labels and the given values of r and φ printed to the Command Window. You will complete the program to determine and print to the Command Window the value of θ that would place the nozzle on the target line, as well as its distance s along that line (you will use this to evaluate the evenness of the line in Project 3). You must use the approach described above (though if you can work out the analytical solution, you may use it to check your work).

Additional specifications, considerations, and hints

Submission

Submit your files on CMS (after registering your group). They should include tank.m, polarPrinter.m, and the files from part B. Don’t accidentally upload the original version of polarPrinter.m that you downloaded from the course website!