How do I calculate the length of an x/y coordinate in Python?
I'm constructing a program where the user clicks two points in the graphics window and the length of x and y must be shown. I've creating a clone and multiplying it by itself, but no luck. Any ideas? Thanks!
Edit: My program is supposed to create a 'money bin' based off the users data and 2 point clicks in the graphics window. I need help figuring out how to get the 'length in x direction' after the user clicks 2 points on the graphics window.
-Here's the example inputs- Enter shape of money bin:
1 cube/prism
2 cylinder
3 cone
4 pyramid
Shape: 4
Enter height of money bin: 96.5
Enter cost per cubic foot to build: 2.75
After clicking on the window, click the mouse at two points in the window to determine the money bin base
point 1 coordinates: 16.5258215962 45.7202505219
point 2 coordinates: 60.2190923318 13.40292275开发者_运维技巧57
Length in x direction: 43.6932707355 feet
Length in y direction: 32.3173277662 feet
Volume: 45420.9336744 cubic feet
Cost to build money bin rounded to nearest dollar: 124908
Press to quit
To get the absolute difference in the x coordinates use this formula:
dx = math.abs(x2 - x1)
Similarly for the y-coordinates:
dy = math.abs(y2 - y1)
On a related note, the formula for the distance between two points in two dimensions is:
dist = math.sqrt((x2 - x1)**2 + (y2 - y1)**2)
Do you mean you want to calculate the distance between the two points? If so, you just use the Pythagorean theorem: √((y1-y2)2+(x1-x2)2).
精彩评论