19.16. ExercisesΒΆ
-
Add a
distanceFromPoint
method that works similar todistanceFromOrigin
except that it takes aPoint
as a parameter and computes the distance between that point and self.
-
Add a method
reflect_x
to Point which returns a new Point, one which is the reflection of the point about the x-axis. For example,Point(3, 5).reflect_x()
is (3, -5)
-
Add a method
slope_from_origin
which returns the slope of the line joining the origin to the point. For example,>>> Point(4, 10).slope_from_origin() 2.5
What cases will cause your method to fail? Return None when it happens.
Before you keep reading...
Making great stuff takes time and $$. If you appreciate the book you are reading now and want to keep quality materials free for other students please consider a donation to Runestone Academy. We ask that you consider a $10 donation, but if you can give more thats great, if $10 is too much for your budget we would be happy with whatever you can afford as a show of support.
-
The equation of a straight line is βy = ax + bβ, (or perhaps βy = mx + cβ). The coefficients a and b completely describe the line. Write a method in the Point class so that if a point instance is given another point, it will compute the equation of the straight line joining the two points. It must return the two coefficients as a tuple of two values. For example,
>>> print(Point(4, 11).get_line_to(Point(6, 15))) >>> (2, 3)
This tells us that the equation of the line joining the two points is βy = 2x + 3β. When will your method fail?
-
Add a method called
move
that will take two parameters, call themdx
anddy
. The method will cause the point to move in the x and y direction the number of units given. (Hint: you will change the values of the state of the point)
-
Given three points that fall on the circumference of a circle, find the center and radius of the circle.