Question: Add the following accessor method to the Point class: public boolean isCollinear(Point p1, Point p2) Returns whether this Point is collinear with the given two

Add the following accessor method to the Point class:

public boolean isCollinear(Point p1, Point p2)

Returns whether this Point is collinear with the given two other Points. Points are collinear if a straight line can be drawn that connects them. Two basic examples are three points that have the same - or -coordinate. The more general case can be determined by calculating the slope of the line between each pair of points and checking whether this slope is the same for all pairs of points. Use the formula (y2 − y1) / (x2 − x1) to determine the slope between two points (x1, y1) and (x2, y2).Since Java’s double type is imprecise, round all slope values to a reasonable accuracy such as four digits past the decimal point before you compare them.

Step by Step Solution

3.50 Rating (157 Votes )

There are 3 Steps involved in it

1 Expert Approved Answer
Step: 1 Unlock

public boolean isCollinear Point pl Point p2 basic case all points have same x or y v... View full answer

blur-text-image
Question Has Been Solved by an Expert!

Get step-by-step solutions from verified subject matter experts

Step: 2 Unlock
Step: 3 Unlock

Students Have Also Explored These Related Building Java Programs A Back to Basics Approach Questions!