Golden Thumb Parenting Tips [012]

Angle bisector in Xcode

拇指 muzhi.com
4 min readApr 3, 2020

--

The mathematician’s patterns, like the painter’s or the poet’s, must be beautiful; the ideas, like the colours or the words, must fit together in a harmonious way. Beauty is the first test: there is no permanent place in the world for ugly mathematics.

G.H. Hardy

School Geometry with Ruler, Compass and Coding (03) Perpendiculars
School Geometry with Ruler, Compass and Coding (04) Parallel
School Geometry with Ruler, Compass and Coding (05) Triangle
School Geometry with Ruler, Compass and Coding (06) Circle through three points
School Geometry with Ruler, Compass and Coding (07) Pythagorean theorem
School Geometry with Ruler, Compass and Coding (08) Irrational numbers √2
School Geometry with Ruler, Compass and Coding (09) Right triangle from given hypotenuse and one side
School Geometry with Ruler, Compass and Coding (10) Circle tangent to circle

We created the Xcode project RulerCompass in Ruler and Compass (01). Let’s continue with angle bisector.

First we move the code into a new function lineSegmentBisector():

import UIKitclass EuclideanView: UIView {    override func draw(_ rect: CGRect) {
lineSegmentBisector()
}

func lineSegmentBisector() {
let rulerPath1 = UIBezierPath()
rulerPath1.move(to: CGPoint(x: 200, y: 350))
rulerPath1.addLine(to: CGPoint(x: 500, y: 350))
rulerPath1.lineWidth = 3
rulerPath1.stroke()

let compassPath1 = UIBezierPath()
compassPath1.addArc(withCenter: CGPoint(x: 200, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: true)
UIColor.green.setStroke()
compassPath1.stroke()

let compassPath2 = UIBezierPath()
compassPath2.addArc(withCenter: CGPoint(x: 500, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: false)
UIColor.brown.setStroke()
compassPath2.stroke()

let rulerPath2 = UIBezierPath()
rulerPath2.move(to: CGPoint(x: 350, y: 10))
rulerPath2.addLine(to: CGPoint(x: 350, y: 700))
rulerPath2.lineWidth = 2
UIColor.red.setStroke()
rulerPath2.stroke()
}
}

Run and see the same result:

Similarly we create another function angleBisector() to start drawing angle and its bisector:

override func draw(_ rect: CGRect) {
// lineSegmentBisector()
angleBisector()
}

func angleBisector() {
let anglePath = UIBezierPath()
anglePath.move(to: CGPoint(x: 400, y: 50))
anglePath.addLine(to: CGPoint(x: 100, y: 350))
anglePath.addLine(to: CGPoint(x: 400, y: 650))
anglePath.lineWidth = 3
anglePath.stroke()
}

Draw an arc to cut the two legs of the angle:

func angleBisector() {
let anglePath = UIBezierPath()
anglePath.move(to: CGPoint(x: 400, y: 50))
anglePath.addLine(to: CGPoint(x: 100, y: 350))
anglePath.addLine(to: CGPoint(x: 400, y: 650))
anglePath.lineWidth = 3
anglePath.stroke()

let compassPath1 = UIBezierPath()
compassPath1.addArc(withCenter: CGPoint(x: 100, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: true)
UIColor.brown.setStroke()
compassPath1.stroke()

}

Keep going and draw two green arcs and then the angle bisector. Here is the complete code:

import UIKitclass EuclideanView: UIView {    override func draw(_ rect: CGRect) {
// lineSegmentBisector()
angleBisector()
}

func angleBisector() {
let anglePath = UIBezierPath()
anglePath.move(to: CGPoint(x: 400, y: 50))
anglePath.addLine(to: CGPoint(x: 100, y: 350))
anglePath.addLine(to: CGPoint(x: 400, y: 650))
anglePath.lineWidth = 3
anglePath.stroke()

let compassPath1 = UIBezierPath()
compassPath1.addArc(withCenter: CGPoint(x: 100, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: true)
UIColor.brown.setStroke()
compassPath1.stroke()

let compassPath2 = UIBezierPath()
compassPath2.addArc(withCenter: CGPoint(x: 100 + 300/sqrt(2), y: 350 - 300/sqrt(2)), radius: 300, startAngle: 0, endAngle: 0.5 * CGFloat.pi, clockwise: true)
UIColor.green.setStroke()
compassPath2.stroke()

let compassPath3 = UIBezierPath()
compassPath3.addArc(withCenter: CGPoint(x: 100 + 300/sqrt(2), y: 350 + 300/sqrt(2)), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0, clockwise: true)
UIColor.green.setStroke()
compassPath3.stroke()

let bisectorPath = UIBezierPath()
bisectorPath.move(to: CGPoint(x: 100, y: 350))
bisectorPath.addLine(to: CGPoint(x: 600, y: 350))
bisectorPath.lineWidth = 2
UIColor.red.setStroke()
bisectorPath.stroke()
}

func lineSegmentBisector() {
let rulerPath1 = UIBezierPath()
rulerPath1.move(to: CGPoint(x: 200, y: 350))
rulerPath1.addLine(to: CGPoint(x: 500, y: 350))
rulerPath1.lineWidth = 3
rulerPath1.stroke()

let compassPath1 = UIBezierPath()
compassPath1.addArc(withCenter: CGPoint(x: 200, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: true)
UIColor.green.setStroke()
compassPath1.stroke()

let compassPath2 = UIBezierPath()
compassPath2.addArc(withCenter: CGPoint(x: 500, y: 350), radius: 300, startAngle: -0.5 * CGFloat.pi, endAngle: 0.5 * CGFloat.pi, clockwise: false)
UIColor.brown.setStroke()
compassPath2.stroke()

let rulerPath2 = UIBezierPath()
rulerPath2.move(to: CGPoint(x: 350, y: 10))
rulerPath2.addLine(to: CGPoint(x: 350, y: 700))
rulerPath2.lineWidth = 2
UIColor.red.setStroke()
rulerPath2.stroke()
}
}

And we are done:

--

--