# CompHmwk1WriteUp ```https://py3.codeskulptor.org/#user307_D7ZTXqNge8eatTR.py
Answers to the make_circle pre-write questions (Section 4.F).
1.
Question 4.F.i: How will the midpoint, slope, and perp functions help to nd the
center and/or radius of the circle?
The midpoint function will nd the midpoint (midpoint_x, midpoint_y) between the rst
and second points inputted ((point0x, point0y) and (point1x, point1y)), and the midpoint
between the second and third points ((point1x, point1y) and (point2x, point2y)). From
there, the slope function calculates the slope (slope_num) of the lines between
(point0x, point0y) and (point1x, point1y) and between (point1x, point1y) and (point2x,
point2y). The perp function calculates the slope perpendicular to each above slope
(perp_slope). In combination with the point (point0x, point0y), the perpendicular slope
to the line between (point0x, point0y) and (point1x, point0y) gives the equation for a
line perpendicular to the line between (point0x, point0y) and (point1x, point0y). In
combination with the point (point2x, point2y), the perpendicular slope to the line
between (point1x, point1y) and (point2x, point2y) gives the equation for a line
perpendicular to the line between (point1x, point1y) and (point2x, point2y). The
intersection of these lines found by the midpoint, slope, and perp functions will yield
the center of the circle.
2.
Question 4.F.ii: How will the intersect function help to nd the center and/or
The intersect function will intake the equation for each perpendicular line given by the
base point (point0x, point0y) and corresponding perpendicular slope from above
(assigned to perp1 in make_circle), and the base point (point2x, point2y) and its
corresponding perpendicular slope (assigned to perp2 in make_circle). The intersect
function will then compute the intersection of these two lines which is the center of the
circle, (x_intersect, y_intersect), assigned to x_center and y_center respectively in
make_circle.
3.
Question 4.F.iii: How will the distance function help to nd the center and/or
The distance function will compute the distance (dist_total) between the center point
(x_center, y_center) found from the intersect function, and a point (point0x, point0y),
which is the radius of the circle and is assigned to variable name radius within
make_circle.
fi
fi
fi
fi
ffi
fi
Discussion Question:The strategy we followed to calculate the center and
radius of the circle is not the most e cient. We used a geometric strategy
that you would use on paper in order to introduce you to Python and
1.
An algebraic method for calculating the center and radius of a circle is
through completing squares. Given an input of an equation containing the
sum of x^2, y^2, x, y, and non-variable terms, the variables are separated
into categories based on if it is an x or x^2-term, a y or y^2-term or an
unassociated term. Then, if the value before x^2 term is greater than 1,
the equation is divided by that value. Then, the value before the x-term is
divided by 2 and multiplied by negative 1 to get h in the equation (x - h)^2
+ (y-k)^2 = r^2, then this value of h is saved as the x-value of the center.
The same value of h is then squared and is subtracted from the constant
term on the right side of the equation. Then, the value before the y-term is
divided by 2 and multiplied by negative 1 to get k in the equation (x - h)^2
+ (y-k)^2 = r^2, then this value of k is saved as the y-value of the center.
The same value of k is then squared and is subtracted from the constant
term on the right side of the equation. The square root of the resultant
value on the right side of the equation is saved as the value of the radius.
1.
The concept of functions and variables were the most important concepts
reinforced by this assignment. I think that functions are incredibly important
because they allow the user to break down a large problem into smaller
components, reuse a chunk of code when a method or mathematical
manipulation needs to be applied more than once, and lastly they also make the
body of code much more comprehensible to any reader. I think variables are
very important because they allow a user to use a value returned by a function in
another calculation or method, they make the purpose of the particular section
of code more obvious, and they allow a value to be used multiple times. Thus, I
nd these concepts integral to coding and very helpful.
2.
These concepts transcend the calculation of a circle because functions and
variables can be used for any number of methods, calculations, or storage of
values for reuse. I envision applying these concepts in the future, in likely every
Comp 140 assignment moving forward, because they are necessary to make
code more concise and comprehensible. I would likely use them to perform a
mathematical manipulation multiple times, to perform checks on certain data, to
reuse values from earlier in a program or use values returned by functions.
3.
I think I applied the concepts of functions and variable naming conventions well.
I don’t believe I would do anything di erent if I did this assignment over because
I started it early without procrastination and accomplished the purpose of the
program and assignment.
ff
fi
Re ection:
fl
fi
computational problem solving. However, there are better non-geometric
ways for a computer to solve this problem. Describe an algebraic method
for nding the center of the circle. Your answer should be in clear, precise
English; no need to write any Python code!
4.
Yes I believe I would be able to teach the concepts applied in this assignment to
a peer. In particular, I believe I could teach these concepts because I have
taught these concepts to peers in the past while taking high school coding
classes and when friends have been curious about the basics of coding.
```