TASK: Write a function that shrinks a triangle.
COMMENT: Your function should have the form
function [ x2, y2 ] = triangle_shrink ( x1, y1, s )
where
To shrink a triangle involves two steps:
x2(i) = xc + s * ( x1(i) - xc )
y2(i) = yc + s * ( y1(i) - yc )
The easiest way to verify your calculation is to use the fill() command to plot your original and shrunken triangles.
INSTRUCTIONS:
Begin with the function header
Compute the triangle centroid.
Create the values of x2 and y2.
return
end
CHECK: The commands:
x1 = [ 0, 7, 9 ];
y1 = [ 6, 1, 3 ];
[ x2, y2 ] = triangle_shrink ( x1, y1, 0.33 );
fill ( x1, y1, 'b' )
hold on
fill ( x2, y2, 'r' )
should produce a picture of the big (blue) and shrunken (red)
triangles like this:
SUBMIT: Because it's a function, your file should be named "triangle_shrink.m". (I don't need a picture of your shrunken triangle.) Your file should begin with:
% triangle_shrink.m
% YOUR NAME
% This script (describe what it does)