In: Computer Science
Using Python Suppose a robot starts at the origin and must reach a target point P in the first quadrant of the Cartesian plane. The robot initially moves in a straight line to an intermediate point (x, y) and then turns and travels along a straight line towards the target P. The robot can move anywhere in the first quadrant and along the horizontal and vertical axes except for a circle centered at the point C with radius r.
(a) Determine an objective whose minimum would describe an optimal route from the origin to the target.
(b) Using your code from the first two problems or by implementing an alternative method, write a function that minimizes the objective function. This function should input a target point, P, and the center and radius of the excluded circle and return the optimal intermediate point. Additionally, your code should plot the objective function over a meaningful range of x and y values as well as a plot of the optimal path from the origin to the target point and the excluded circle.
(c) Solve the minimization problem for the following parameters: 1. P = (5, 3), C = (2, 2), r = 1. 2. P = (2, 4), C = (2, 2), r = 1. 3. P = (3, 3), C = (2, 2), r = 1.
1.
def min_path(p1, p2):
# dx is total horizontal
# distance to be covered
dx = abs(p1[0] - p2[0])
# dy is total vertical
# distance to be covered
dy = abs(p1[1] - p2[1])
# required answer is
# maximum of these two
return max(dx, dy)
# Function to return the minimum steps
def coverPoints(sequence, size):
stepCount = 0
# finding steps for each
# consecutive poin the sequence
for i in range(size-1):
stepCount += min_path(sequence[i],sequence[i + 1])
return stepCount
# Driver code
# arr stores sequence of points
# that are to be visited
arr = [[4, 6] ,[ 1, 2 ], [ 4, 5] , [ 10, 12]] //here take your inputs as suggested in program
n = len(arr)
print(coverPoints(arr, n))
2.
def circle_equation(x1, y1, r):
a = -2 * x1;
b = -2 * y1;
c = (r * r) - (x1 * x1) - (y1 * y1);
# Printing result
print("x^2 + (", a, "x) + ", end = "");
print("y^2 + (", b, "y) = ", end = "");
print(c, ".");
# Driver code
x1 = 2;
y1 = -3;
r = 8;
circle_equation(x1, y1, r);