Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Problem 1a collinear.py: Collinearity of three points [5 points] Write a function collinear3() that takes three arguments p1, p2, p3 which are pairs of doubles

Problem 1a collinear.py: Collinearity of three points [5 points] Write a function collinear3() that takes three arguments p1, p2, p3 which are pairs of doubles (i.e., you can assume that p1 is a tuple of the form (x1,y2), and similarly for p2 and p3). The function should return True if the points p1 ? (x1, y1), p2 ? (x2, y2), and p3 ? (x3, y3) are all collinear, and False otherwise.

Hint: The slope of any two segments, say P1P2 and P1P3, must be equal. Write the formula for this condition in such a way that it can also handle axis-parallel segments.

Problem 1b collinear.py: Collinearity of many points [5 points] Write a function collinear() that takes a list of pairs (tuples) as an argument, where each pair again represents a point on a plane. Your function should return True only if all points in the list are collinear, and False otherwise. If the list has less than three points (including none), you should trivially return True1 .

For credit, your answer in Problem 1b must reuse your function from Problem 1a.

Hint: If there are n points in the input list, it is sufficient that you check n ? 2 appropriately chosen triples of points (there are several ways to choose which triples).

Practice goal: An accumulation pattern with boolean and to evaluate a for all expression; you have to figure out what the range of that for all is (i.e., which triples of points to consider). Also, further practice in code reuse and modular programming.

Step by Step Solution

There are 3 Steps involved in it

Step: 1

blur-text-image

Get Instant Access to Expert-Tailored Solutions

See step-by-step solutions with expert insights and AI powered tools for academic success

Step: 2

blur-text-image_2

Step: 3

blur-text-image_3

Ace Your Homework with AI

Get the answers you need in no time with our AI-driven, step-by-step assistance

Get Started

Recommended Textbook for

More Books

Students also viewed these Databases questions

Question

computer application

Answered: 1 week ago

Question

5. Discuss the key components of behavior modeling training.

Answered: 1 week ago