Tag Archives: distance

(Objective C) How to find the distance between two CG points

Distance between p1 and p2: CGFloat xDist = (p2.x – p1.x); CGFloat yDist = (p2.y – p1.y); CGFloat distance = sqrt((xDist * xDist) + (yDist * yDist)); Background: Pythagorean theorem Edit: if you only need to calculate if the distance between the points increases or decreases, you can omit the sqrt() which will make it [...]

Posted in Objective-C | Also tagged , , , , | Leave a comment

Closest pair of points problem in C++

Given n points, find two points with the smallest distance to each other. The examples listed below demonstrate two algorithms in C++ to tackle this problem. One algorithm simply checks every combination of points, also known as a brute force approach. The other one is an efficient algorithm which uses a divide and conquer approach.  The [...]

Posted in C++ | Also tagged , , , , , , , , , | 2 Comments

Distance between 2D and 3D vectors in C++

This example extends the Vector2 and Vector3 classes from the 2D and 3D vector normalization and angle calculation in C++ example. The formulas for distance calculation in 2D and 3D are listed below.

Posted in C++ | Also tagged , , , , , , , | Leave a comment

Distance between two latitude longitude points

Calculating the distance in meters between two points defined with latitude and longitude. Point one: Latitude:  52.9925463480 Longitude: 6.5634555238 Point two: Latitude: 51.9406140497 Longitude: 4.8140287399

Posted in PHP | Also tagged , , , , | Leave a comment