draw a cup in matlab

Here is a possible way to draw a cup in Matlab using the plot() and fill() functions:

main.m
% Cup coordinates
r = 0.5;         % radius
h = 1;           % height
t = 0.1;         % thickness
x = [0 r r r-t r-t r+t r+t r];
y = [0 0 h-2*r h-2*r h-t h-t h-2*r h-2*r];

% Plot cup
figure
hold on
plot(x, y, 'k', 'LineWidth', 2)         % outline
fill(x(2:7), y(2:7), 'w', 'EdgeColor', 'k')   % inside
fill([0 r/2 r], [h-2*r h-2*r-t h-t], 'w', 'EdgeColor', 'none')   % handle
axis equal
box on
397 chars
16 lines

This code creates a cup with a given radius (r), height (h), and thickness (t). It then defines the x and y coordinates of the cup shape, and plots it using plot(). The inside of the cup is filled using fill(), and a handle is added as another fill shape. The result is shown below:

Cup plot in Matlab

gistlibby LogSnag