0

Calculating 2points and then an unknown point euclidean distance

I want the user to input two point (a, b) and (c, d) get the distance and then enter a 3rd unknown point(e, f) and get the distance from all three e.g ab to cd and ab to ef and cd to ef. the three distances must be printed in the console! please help really trying to understand this

19th May 2019, 2:20 AM
Marpari
11 Respuestas
+ 5
In addition to the correct answer posted by Jay Matthews, you can also use the builtin sqrt function... distance = sqrt( (d-b)**2 + (c-a)**2) ) You can also use the builtin math.hypot function... distance = math.hypot( c-a, d-b )
19th May 2019, 3:35 AM
David Carroll
David Carroll - avatar
+ 5
Marpari Since you shared your effort, I've written a version that should get you close to what you are looking for. https://code.sololearn.com/c4NW43mBwY85/?ref=app NOTE: Read the code comments at the beginning to understand the options I added to run with hard-coded points or to run with user inputs. These apply to running in Code Playground. You can modify anyway you need when running locally. I hope the code helps and makes sense.
19th May 2019, 5:38 AM
David Carroll
David Carroll - avatar
+ 1
Marpari I just saw your replies... which posted after I originally loaded your question. I'll have a closer look shortly.
19th May 2019, 3:38 AM
David Carroll
David Carroll - avatar
+ 1
Great thanx buds really appreciate this
19th May 2019, 4:10 AM
Marpari
+ 1
yes thanx buds really appreciate it
19th May 2019, 4:11 AM
Marpari
+ 1
Hi David thanx will head on over to it now
19th May 2019, 5:55 AM
Marpari
+ 1
it worked budz thanx a mill
19th May 2019, 5:56 AM
Marpari
+ 1
Marpari I'm glad to hear that. Does the approach I took with the code make sense?
19th May 2019, 6:28 AM
David Carroll
David Carroll - avatar
0
Yes that correct got it but the I am trying to get the user to input a third coordinate on the x y plane using a while statement and I'm not sure how to go about it! can you help me pretty please?
19th May 2019, 3:29 AM
Marpari
0
#Distance of two points and one unknown on xy plane = sqrt((x1-x2)2 + (Y1-Y2)2 +(z1-z2)2) condition = a, b = int(input("Enter two x Cordinates")), int(input()) c, d = int(input("Enter Two Y Cordinates")), int(input()) e, f = int(input("Enter Two Y Cordinates")), int(input()) while condition += dis = (((a - b) 2) + ((c - d) 2)) 0.5: print("Distance is", dis) else calculate += dis2 = (((c - d)2 + ((e - f)2)) 0.5: and dis3 = (((a - b)2 + (e -f)2)) 0.5: print("Distance is", dis) print("Distance is", dis2) print("Distance is", dis3)
19th May 2019, 3:31 AM
Marpari
0
this is what it looks like we'll actually what u think it to be
19th May 2019, 3:31 AM
Marpari