I'm trying to calculate the euclidean distance between two points (x1,y1) and (x2,y2) which is

sqrt( (x2-x1)^2 + (y2-y1)^2 )

Is there a way to calculate this easily with Emacs calc?

(I looked in the Info pages, but was not able to tell if there a way to do this easily. I can use f h to compute the hypotenuse, but I can't figure out how to use that with points, or if Emacs has any first class notion of a point)

  • 1
    You can enter points as complex. abs((3,4))=>5 or abs(3+4i)=>5. For your example abs((x2,y2)-(x1,y1))=sqrt((x2-x1)^2+(y2-y1)^2) – gigiair Feb 6 at 22:08
  • you can also enter points as array. abs([x2, y2] - [x1, y1])=>hypot(x2 - x1, y2 - y1) – gigiair Feb 7 at 6:41

You can represent points with complex numbers or vectors. The calc-abs (A) function returns the absolute value of a complex number or the Euclidean norm of a vector. For instance this is the trail trace which results from the calculus of the distance from [7 -2] to [4 2]

Emacs Calculator Trail
alg' [7, -2]
alg' [4, 2]
   - [-3, 4]
 abs 5
  • You should expand your answer to include all of the details in your comments: that would make it much more useful. – NickD Feb 7 at 20:57
  • The main point is that you can use the abs function for complex numbers or for vectors. I can't imagine that calculate a difference could create any difficulties. Points can be represented either with complex numbers or vectors, depending on the context. – gigiair Feb 7 at 22:48
  • Thanks! You may be right, but IME, the more detailed the answer, the more helpful it is (not only for the OP, but also for future visitors). – NickD Feb 7 at 22:55

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.