Golden Thumb Parenting Tips [012]
Angle bisector in Xcode
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:
[001] Golden Thumb who?
[002] Play 24 Game if kids know + − × ÷
[003] Kids love challenges. Don’t ruin their day with quick answers.
[004] Finger gymnastics on keyboard
[005] Install Xcode on mac and create an empty runnable app
[006] Install Eclipse on Windows PC and create Hello World app
[007] Draw and fill shapes with Java in Eclipse
[008] Use straightedge and compass correctly
[009] Ongoing stories of An
[010] 让数学与编程伴随孩子成长
[011] Line segment bisector in Xcode
[012] Angle bisector in Xcode
[013] Draw perpendicular in Xcode
[019] Ongoing stories of Peter
[029] Ongoing stories of Nicole
[039] Ongoing stories of Willa
[059] Ongoing stories of Ethan
[049] Ongoing stories of Lucas
[069] Ongoing stories of Lambert
[079] Ongoing stories of Felix
[089] Ongoing stories of Hal
[099] Ongoing stories of Michael
[109] Ongoing stories of Marius
[119] Ongoing stories of Bowen
[129] Ongoing stories of Oliver
[139] Ongoing stories of Grace
[149] Ongoing stories of Ryan
[159] Ongoing stories of Angie
[169] Ongoing stories of Elaine
[179] Ongoing stories of Andy