Answered step by step
Verified Expert Solution
Link Copied!

Question

1 Approved Answer

Python Expert, I need your help. I need a program to find a distance between two points: The main method is used to request input

Python Expert, I need your help. I need a program to find a distance between two points:

The main method is used to request input and to call the appropriate methods described below in order to report the distance and direction.

Code main using the following algorithm.Prompt the user to enter two points

Transform the points P1 and P2, placing P1 at (0, 0) by calling the function transform_points.

Find the quadrant by calling the find_quadrant method, passing in the x1, y1, x2 and y2 values entered by user.

Use the found quadrant to find pt 3: (x3,y3):

For Quad I and Quad III:x3 = x2 and y3 = y1

For Quad II and Quad IV: x3 = x1 and y3 = y2

Compute length of three sides, by calling the distance method for each side with the appropriate parameteres.

Compute the angle A at point 1, by calling the comp_angle method, which uses the Law of Cosines. See ComputeAngles.java code.

Compute the direction by calling the comp_direction method

Display the distance and direction. Round the distance to two decimal places before displaying it. The ComputeAngles.java code shows you how to do this rounding.

1-transform_points()

return floats

x1,y1,x2,y2 parameteres(x1,y1,x2,y2) -----

Return the transformed points for P! and P2, where P1 is at the

origin (0, 0)

2-distance()

return float /parameters(x1',y1',x2',y2') ----- Return the distance from P1: (0, 0) to P2: (x2, y2)

3- compute_angle()

return float /parameters(sideA_len, sideB_len, sideC_len) ------ Return the angle at P1: (0, 0) in degrees, where

sideA is across from P1: (0, 0),

sideB is across from P2: (x2, y2),

sideC is across from P3: (x3, y3)

4- compute_direction()

return str /parameters(angle, quadrant) -------- Return the direction of travel using the angle and quadrant. Code this using a dictionary, where the keys are tuples holding the angle slices (low, high) and the value is the direction.

5- find_quadrant()

return int /parameters(x1',y1',x2',y2') ------ Return the quadrant in which the direction of travel takes you from P1: (0, 0) to P2: (x2,y2).

Quadrants:

Q1: when x2 > 0 and y2 >= 0

Q2: when x2 <= 0 and y2 > 0

Q3: when x2 < 0 and y2 <= 0

Q4: when x2 >= 0 and y2 < 0

return 1, 2, 3, or 4

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

Step: 3

blur-text-image

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

Inference Control In Statistical Databases From Theory To Practice Lncs 2316

Authors: Josep Domingo-Ferrer

2002nd Edition

3540436146, 978-3540436140

More Books

Students also viewed these Databases questions

Question

1. What might have led to the misinformation?

Answered: 1 week ago

Question

2. How will you handle the situation?

Answered: 1 week ago