Replies: 1 comment 4 replies
-
|
If you store the two points as coordinates, calculating the Euclidean distance between them is very easy: const { subtract, norm, distance } = math;
let A = [1, 2];
let B = [-5, 8];
let d = norm(subtract(A, B)) // 8.485
// or equivalently
let d = distance(A, B) // 8.485The easiest way to calculate the distance to a polygon is to calculate the distance to each of its edges and take the smallest one. Calculating the distance to edges isn't implemented in mathjs (yet), but it sounds like a fun excersise to write such a function oneself. The important ideas are outlined in this wiki article. If you get around to implement it, be sure to share it here! 😁️ |
Beta Was this translation helpful? Give feedback.
4 replies
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment



Uh oh!
There was an error while loading. Please reload this page.
-
Hi,
first of all thanks a lot for all the work you do.
Now my questions: How can I calculate the distance between two points on a 2d plane? And how can I calculate the minimum distance between a point and a polygon, also on a 2d plane, the polygon can be convex and concave, and the point is somewhere outside the polygon?
Thanks!
Beta Was this translation helpful? Give feedback.
All reactions