Languages
[Edit]
EN

TypeScript - calculate distance between two points in 3D space

0 points
Created by:
evangeline
420

In this article, we would like to show you how to calculate the distance between two points in 3D space using a modified Pythagorean equation in TypeScript.

Quick solution:

 

1. Mathematical theorem for the coordinate system

Edit

Distance calculation for points requires starting with the transformation of the Pythagorean equation to the point version.

what can be transformed to:

Note: absolute values can be avoided because of squares inside Pythagorean equation - squares remove minuses.

Example calculations:

2. TypeScript custom distance function example

Edit

Output:

3. Math.hypot method example

Edit

Note: Math.hypot has been introduced in ECMAScript 2015.

Output:

1
Donate to Dirask
Our content is created by volunteers - like Wikipedia. If you think, the things we do are good, donate us. Thanks!
Join to our subscribers to be up to date with content, news and offers.
Native Advertising
🚀
Get your tech brand or product in front of software developers.
For more information Contact us
Dirask - we help you to
solve coding problems.
Ask question.

❤️💻 🙂

Join