Page 169 - Learn To Program With Scratch
P. 169
Start from a point on
the line facing right.
The nose of the cat
is touching the line.
The left ear of the cat
is touching the line.
The right ear of the cat
is touching the line.
The cat is not touching
the line. Move slowly to
find a starting point.
Figure 6-25: Line-following algorithm
try it out 6-3
Open the application and run it to see how it works . Experiment with the given
values to make the sprite finish the track in the fastest possible time . One reviewer
completed the track in 11 seconds . Can you beat the record? Create other tracks
and see if this simple algorithm still works .
Equation of a Line
EquationOfALine The equation of a line joining two points P = (x , y ) and Q = (x , y ) is
2
1
1
2
.sb2 y = mx + b, where m = (y – y ) / (x – x ) is the slope of the line and b is the
1
2
1
2
y-intercept. A vertical line has an equation of the form x = k, and a hori-
zontal line has an equation of the form y = k, where k is a constant. In this
section, we’ll develop an application that finds the equation of the line that
joins two points in the Cartesian plane. The user interface for the applica-
tion is shown in Figure 6-26.
Making Decisions 147
www.it-ebooks.info

