Calculates the distance between two points in a 3D space

Source: Internet
Author: User

Oneself in the game to forget the unity to help us to provide a calculation of the distance between two points, Baidu search under.

Originally there was a formula to write a method O (∩_∩) o~, to the zombie to reach a point after the run to the other past

/// <summary>    ///how to calculate the distance between two points in 3 dimensions/// </summary>    /// <param name= "P1" ></param>    /// <param name= "P2" ></param>    /// <returns></returns>    Private floatTwopointdistance3d (Vector3 p1, Vector3 p2) {floati = mathf.sqrt ((p1.x-p2.x) * (p1.x-p2.x)+ (P1.Y-P2.Y) * (P1.Y-p2.y)+ (P1.Z-P2.Z) * (P1.z-p2.z)); returni; }    /// <summary>    ///how to calculate the distance between two points in 2 dimensions/// </summary>    /// <param name= "P1" ></param>    /// <param name= "P2" ></param>    /// <returns></returns>    Private floattwopointdistance2d (Vector2 p1, Vector2 p2) {floati = mathf.sqrt ((p1.x-p2.x) * (p1.x-p2.x)+ (P1.Y-P2.Y) * (P1.Y-p2.y)); returni; }

Mathematical formula:

Euclidean distance definition: Euclidean distance (Euclidean distance) is a commonly used distance definition, which is the true distance between two points in m-dimensional space.
The Euclidean distance in two and three-dimensional space is the distance between two points, and the two-dimensional formula is
D = sqrt ((x1-x2) ^+ (y1-y2) ^)
The three-dimensional formula is
D=sqrt (x1-x2) ^+ (y1-y2) ^+ (z1-z2) ^)
Extended to n-dimensional space, the formula for Euclidean distance is
D=sqrt (∑ (xi1-xi2) ^) Here I=1,2..N
XI1 represents the i-dimensional coordinates of the first point, and Xi2 represents the i-dimensional coordinates of the second point
n dimensional Euclidean space is a point set, each of its points can be expressed as (X (1), X (2),... x (n)), where x (i) (I=1,2...N) is a real number, called the X-I coordinate, the distance between two points x and y= (Y (1), Y (2) ... y (n)), and D (x, y) Defined as the formula above.
Euclidean distance is regarded as the similarity of signal. The closer you are, the more likely you are to interfere with each other and the higher the BER

Calculates the distance between two points in a 3D space

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.