# Mc2. WRITE PYTHON FUNCTION THAT: You need to write the function which takes the index of the last point in the path sent, current, as well as the path, as arguments and returns the index of the next point to send. To write this function, remember the equations for the slope (m) of a line given two points on the line, and the offset (c) of a line give one point and the slope: y = mx +c. If you know the slope and offset, then whenever you are given a point (x1,y1) you can determine whether it lies on the line or not by evaluating r = y1-m*x1-c. This (y=mx+c) will be zero for a point on the line, and non-zero otherwise! The easiest way to see if you are on a straight line is to use the first two points to calculate m and c, then sum the value of r for the third, fourth, etc. until you reach a point where the sum of r exceeds some threshold value. That is, when the points have accumulated too much error from a straight line. You can use 0.1 as your default value of the threshold. Generate output to the screen from your function so you can keep track of how many ‘lines’ your program thinks there were in the path

Mc2.

WRITE PYTHON FUNCTION THAT:

You need to write the function which takes the index of the last point in the path sent, current, as well as the path, as arguments and returns the index of the next point to send.

To write this function, remember the equations for the slope (m) of a line given two points on the line, and the offset (c) of a line give one point and the slope: y = mx +c. If you know the slope and offset, then whenever you are given a point (x1,y1) you can determine whether it lies on the line or not by evaluating r = y1-m*x1-c. This (y=mx+c) will be zero for a point on the line, and non-zero otherwise!

The easiest way to see if you are on a straight line is to use the first two points to calculate m and c, then sum the value of r for the third, fourth, etc. until you reach a point where the sum of r exceeds some threshold value. That is, when the points have accumulated too much error from a straight line. You can use 0.1 as your default value of the threshold. Generate output to the screen from your function so you can keep track of how many ‘lines’ your program thinks there were in the path

Step by step

Solved in 2 steps