2. Angle bisection
VC2M9SP03: level 9: Design, test and refine algorithms involving a sequence of steps and decisions based on geometric constructions and theorems; discuss and evaluate refinements
creating and testing algorithms designed to construct or bisect angles, using pseudocode or flow charts
2.1. Angle bisector
Here is simple directions for an algorithm to construct an angle bisector:
Input: An angle with vertex O and rays OA and OB
Step 1: Set the compass width to any convenient length and place the compass point at O
Step 2: Draw an arc that intersects both rays OA and OB and label the intersection points as P and Q
Step 3: Without changing the compass width, place the compass point at P
Step 4: Draw an arc above the Angle
Step 5: Without changing the compass width, place the compass point at Q
Step 6: Draw an arc above the angle that intersects the arc drawn from P at R
Step 7: Use the straightedge to draw a line segment from O through R
Step 8: OR is the angle bisector
Here is a diagram which illustrates the angle bisection.
Here is the python to draw the angle bisection.
1import turtle
2import math
3import random
4
5def label_point(t, label, penc="black"):
6 """Write a label next to a turtle's position.
7
8 Args:
9 t (turtle.Turtle): The turtle object.
10 label (str): The text to write.
11 penc (str): The color of the text. Defaults to "black".
12 """
13 t.penup()
14 t.setx(t.xcor() - 12)
15 t.sety(t.ycor() + 2)
16 t.pendown()
17 t.pencolor(penc)
18 t.write(label, font=("Arial", 12, "normal"))
19
20# Define a function to move the turtle to a point (x, y) with the penup
21def move_to(t, point):
22 """Move the turtle to a given point without drawing.
23
24 Args:
25 t (turtle.Turtle): The turtle object.
26 point (tuple): The coordinates of the point as (x, y).
27 """
28 t.penup()
29 t.goto(point)
30
31def move_arc(t, centre=(0, 0), angle=0, radius=10, extent=360):
32 """Move the turtle along an arc with a given centre, angle and radius.
33
34 Args:
35 t (turtle.Turtle): The turtle object.
36 centre (tuple): The coordinates of the centre of the arc as (x, y). Defaults to (0, 0).
37 angle (int): The angle of the initial position of the turtle relative to the centre. Defaults to 0.
38 radius (int): The radius of the arc. Defaults to 10.
39 extent (int): The angle of the arc that the turtle moves along. Defaults to 360.
40 """
41 move_to(t, centre)
42 t.seth(angle)
43 t.fd(radius)
44 t.seth(angle + 90)
45 t.circle(radius, extent=extent)
46
47
48def draw_line(t, point, length, direction, penc="black"):
49 """Draw a straight line from a given point with a given length, direction and colour.
50
51 Args:
52 t (turtle.Turtle): The turtle object.
53 point (tuple): The coordinates of the starting point as (x, y).
54 length (int): The length of the line.
55 direction (int): The direction of the line in degrees.
56 penc (str): The color of the line. Defaults to "black".
57 """
58 move_to(t, point)
59 t.setheading(direction)
60 t.pendown()
61 t.pencolor(penc)
62 t.forward(length)
63
64
65def draw_centered_arc(t, centre=(0, 0), angle=0, radius=10, extent=360, penw=1, penc="black"):
66 """Draw an arc with a given centre, angle, radius, extent, pen width and color.
67
68 Args:
69 t (turtle.Turtle): The turtle object.
70 centre (tuple): The coordinates of the centre of the arc as (x, y). Defaults to (0, 0).
71 angle (int): The angle of the initial position of the turtle relative to the centre. Defaults to 0.
72 radius (int): The radius of the arc. Defaults to 10.
73 extent (int): The angle of the arc that the turtle draws. Defaults to 360.
74 penw (int): The width of the pen. Defaults to 1.
75 penc (str): The color of the pen. Defaults to "black".
76 """
77 move_to(t, centre)
78 t.seth(angle)
79 t.pensize(penw)
80 t.pencolor(penc)
81 t.fd(radius)
82 t.pd()
83 t.seth(angle + 90)
84 t.circle(radius, extent=extent)
85 for i in range(int((360-extent)/4)): # Draw a dot at each point on the circle
86 t.pd()
87 t.circle(radius, extent=1)
88 t.pu()
89 t.circle(radius, extent=3)
90
91
92def angle_bisector(t, size, angle):
93 # Input: An angle with vertex O and rays OA and OB
94 # Draw the rays OA and OB first
95 ray_length = 1.1*size # This is the dsdie lengths
96 angle_AOB = angle # This is the angle between OA and OB=
97 O = (0, 0)
98 label_point(t, "O", "red")
99 draw_line(t, O, ray_length, 0, penc="black") # Draw the ray OA
100 label_point(t, "A", "black")
101 draw_line(t, O, ray_length, angle_AOB, penc="black") # Draw the ray OB
102 label_point(t, "B", "black")
103
104 # Step 1: Set the compass width to any convenient length and place the compass point at O
105 compass_width = int(size/2)
106
107 # Step 2: Draw an arc that intersects both rays OA and OB and label the intersection points as P and Q
108 move_to(t, (compass_width, 0))
109 P = t.pos()
110 t.dot(5, "blue")
111 label_point(t, "P", "blue")
112
113 draw_centered_arc(
114 t,
115 centre=O,
116 angle=0,
117 radius=compass_width,
118 extent=angle_AOB,
119 penw=1,
120 penc="red",
121 )
122
123 move_to(t, P)
124 move_arc(t, centre=(0, 0), angle=0, radius=compass_width, extent=angle_AOB)
125 Q = t.pos()
126 t.dot(5, "blue")
127 label_point(t, "Q", "blue")
128
129 # Step 3: Without changing the compass width, place the compass point at P
130 move_to(t, P)
131
132 # Step 4: Draw an arc above the angle
133 draw_centered_arc(
134 t,
135 centre=P,
136 angle=0,
137 radius=compass_width,
138 extent=(1.2*angle_AOB),
139 penw=1,
140 penc="blue",
141 )
142
143 # Step 5: Without changing the compass width, place the compass point at Q
144 move_to(t, Q)
145
146 # Step 6: Draw an arc above the angle that intersects the arc drawn from P at R
147 draw_centered_arc(
148 t,
149 centre=Q,
150 angle=angle_AOB,
151 radius=compass_width,
152 extent=-(1.2*angle_AOB),
153 penw=1,
154 penc="blue",
155 )
156
157 move_to(t, P)
158 move_arc(t, centre=P, angle=0, radius=compass_width, extent=angle_AOB)
159 R = t.pos()
160 t.dot(5, "green")
161 label_point(t, "R", "green")
162
163 # Step 7: Use the straightedge to draw a line segment from O through R
164 move_to(t, O)
165 draw_line(t, O, 1.5*t.distance(R[0], R[1]), t.towards(R), penc="green")
166 # Step 8: OR is the angle bisector
167
168
169
170def main():
171 SCREEN_WIDTH = 800
172 SCREEN_HEIGHT = 600
173 SIZE = 220
174 ANGLE = random.randint(40, 90)
175
176 # Set up the turtle screen
177 s = turtle.Screen()
178 s.bgcolor("white")
179 s.title("angle bisector")
180 s.setup(width=SCREEN_WIDTH, height=SCREEN_HEIGHT, startx=0, starty=0)
181 s.tracer(0, 0)
182
183 # Create a turtle object
184 t = turtle.Turtle()
185 t.speed(0) # Set the turtle's speed to the fastest
186 t.ht()
187
188 angle_bisector(t, size=SIZE, angle=ANGLE)
189
190 s.update()
191 s.exitonclick()
192
193
194if __name__ == "__main__":
195 main()