Skip to content

Commit eda68c4

Browse files
Convex Hull: Clarified Readme, and small code clarity changes.
Began to clarify Convex Hull readme, and code. (Needs more work!!)
1 parent 81534d5 commit eda68c4

File tree

4 files changed

+27
-17
lines changed

4 files changed

+27
-17
lines changed

Convex Hull/Convex Hull.xcodeproj/project.pbxproj

+3-3
Original file line numberDiff line numberDiff line change
@@ -149,7 +149,7 @@
149149
};
150150
8E6D68B51E59989400161780 = {
151151
CreatedOnToolsVersion = 8.2.1;
152-
DevelopmentTeam = 7C4LVS3ZVC;
152+
DevelopmentTeam = 4SQG5NJNPF;
153153
ProvisioningStyle = Automatic;
154154
};
155155
};
@@ -384,7 +384,7 @@
384384
isa = XCBuildConfiguration;
385385
buildSettings = {
386386
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
387-
DEVELOPMENT_TEAM = 7C4LVS3ZVC;
387+
DEVELOPMENT_TEAM = 4SQG5NJNPF;
388388
INFOPLIST_FILE = "Convex Hull/Info.plist";
389389
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
390390
PRODUCT_BUNDLE_IDENTIFIER = "workmoose.Convex-Hull";
@@ -397,7 +397,7 @@
397397
isa = XCBuildConfiguration;
398398
buildSettings = {
399399
ASSETCATALOG_COMPILER_APPICON_NAME = AppIcon;
400-
DEVELOPMENT_TEAM = 7C4LVS3ZVC;
400+
DEVELOPMENT_TEAM = 4SQG5NJNPF;
401401
INFOPLIST_FILE = "Convex Hull/Info.plist";
402402
LD_RUNPATH_SEARCH_PATHS = "$(inherited) @executable_path/Frameworks";
403403
PRODUCT_BUNDLE_IDENTIFIER = "workmoose.Convex-Hull";
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,8 @@
1+
<?xml version="1.0" encoding="UTF-8"?>
2+
<!DOCTYPE plist PUBLIC "-//Apple//DTD PLIST 1.0//EN" "http://www.apple.com/DTDs/PropertyList-1.0.dtd">
3+
<plist version="1.0">
4+
<dict>
5+
<key>IDEDidComputeMac32BitWarning</key>
6+
<true/>
7+
</dict>
8+
</plist>

Convex Hull/Convex Hull/View.swift

+2-10
Original file line numberDiff line numberDiff line change
@@ -11,28 +11,20 @@ import UIKit
1111
class View: UIView {
1212

1313
let MAX_POINTS = 100
14-
1514
var points = [CGPoint]()
16-
1715
var convexHull = [CGPoint]()
1816

1917
override init(frame: CGRect) {
2018
super.init(frame: frame)
21-
22-
// last checked with Xcode 9.0b4
23-
#if swift(>=4.0)
24-
print("Hello, Swift 4!")
25-
#endif
26-
27-
generatePoints()
19+
generateRandomPoints()
2820
quickHull(points: points)
2921
}
3022

3123
required init?(coder aDecoder: NSCoder) {
3224
fatalError("init(coder:) has not been implemented")
3325
}
3426

35-
func generatePoints() {
27+
func generateRandomPoints() {
3628
for _ in 0..<MAX_POINTS {
3729
let offset: CGFloat = 50
3830
let xrand = CGFloat(arc4random()) / CGFloat(UINT32_MAX) * (self.frame.width - offset) + 0.5 * offset

Convex Hull/README.md

+14-4
Original file line numberDiff line numberDiff line change
@@ -1,14 +1,23 @@
11
# Convex Hull
22

3-
There are multiple Convex Hull algorithms. This particular implementation uses the Quickhull algorithm.
3+
Given a group of points on a plane. The Convex Hull algorithm calculates the shape (made up from the points itself) containing all these points. It can also be used on a collection of points of different dimensions. This implementation however covers points on a plane. It essentially calculates the lines between points which together contain all points. In comparing different solutions to this problem we can describe each algorithm in terms of it's big-O time complexity.
44

5-
Given a group of points on a plane. The Convex Hull algorithm calculates the shape (made up from the points itself) containing all these points. It can also be used on a collection of points of different dimensions. This implementation however covers points on a plane. It essentially calculates the lines between points which together contain all points.
5+
There are multiple Convex Hull algorithms but this solution is called Quickhull, is comes from the work of both W. Eddy in 1977 and also separately A. Bykat in 1978, this algorithm has an expected time complexity of O(n log n), but it's worst-case time-complexity can be O(n^2) . With average conditions the algorithm has ok efficiency, but it's time-complexity can start to head become more exponential in cases of high symmetry or where there are points lying on the circumference of a circle for example.
66

77
## Quickhull
88

99
The quickhull algorithm works as follows:
10-
The algorithm takes an input of a collection of points. These points should be ordered on their x-coordinate value. We pick the two points A and B with the smallest(A) and the largest(B) x-coordinate. These of course have to be part of the hull. Imagine a line from point A to point B. All points to the right of this line are grouped in an array S1. Imagine now a line from point B to point A. (this is of course the same line as before just with opposite direction) Again all points to the right of this line are grouped in an array, S2 this time.
11-
We now define the following recursive function:
10+
11+
- The algorithm takes an input of a collection of points. These points should be ordered on their x-coordinate value.
12+
- We first find the two points A and B with the minimum(A) and the maximum(B) x-coordinates (as these will obviously be part of the hull).
13+
- Use the line formed by the two points to divide the set in two subsets of points, which will be processed recursively.
14+
- Determine the point, on one side of the line, with the maximum distance from the line. The two points found before along with this one form a triangle.
15+
- The points lying inside of that triangle cannot be part of the convex hull and can therefore be ignored in the next steps.
16+
- Repeat the previous two steps on the two lines formed by the triangle (not the initial line).
17+
- Keep on doing so on until no more points are left, the recursion has come to an end and the points selected constitute the convex hull.
18+
19+
20+
Our functioni will have the following defininition:
1221

1322
`findHull(points: [CGPoint], p1: CGPoint, p2: CGPoint)`
1423

@@ -18,6 +27,7 @@ findHull(S2, B, A)
1827
```
1928

2029
What this function does is the following:
30+
2131
1. If `points` is empty we return as there are no points to the right of our line to add to our hull.
2232
2. Draw a line from `p1` to `p2`.
2333
3. Find the point in `points` that is furthest away from this line. (`maxPoint`)

0 commit comments

Comments
 (0)