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