Specifications
BASIC Stamp II
Page 238 • BASIC Stamp Programming Manual 1.8 • Parallax, Inc.
SIN
Returns the two’s complement, 8-bit sine of an angle specified as an 8-
bit (0 to 255) angle. To understand the BS2 SIN operator more com-
pletely, let’s look at a typical sine function. By definition: given a circle
with a radius of 1 unit (known as a unit circle), the sine is the y-coordi-
nate distance from the center of the circle to its edge at a given angle.
Angles are measured relative to the 3-o'clock position on the circle,
increasing as you go around the circle counterclockwise.
At the origin point (0 degrees) the sine is 0, because that point has the
same y (vertical) coordinate as the circle center; at 45 degrees, sine is
0.707; at 90 degrees, 1; 180 degrees, 0 again; 270 degrees, -1.
The BS2 SIN operator breaks the circle into 0 to 255 units instead of 0 to
359 degrees. Some textbooks call this unit a binary radian or brad. Each
brad is equivalent to 1.406 degrees. And instead of a unit circle, which
results in fractional sine values between 0 and 1, BS2 SIN is based on a
127-unit circle. Results are given in two’s complement in order to ac-
commodate negative values. So, at the origin, SIN is 0; at 45 degrees
(32 brads), 90; 90 degrees (64 brads), 127; 180 degrees (128 brads), 0;
270 degrees (192 brads), -127.
To convert brads to degrees, multiply by 180 then divide by 128; to
convert degrees to brads, multiply by 128, then divide by 180. Here’s a
small program that demonstrates the SIN operator:
degr var w1 ' Define variables.
sine var w2
for degr = 0 to 359 step 45 ' Use degrees.
sine = SIN (degr * 128 / 180) ' Convert to brads, do SIN.
debug "Angle: ",DEC degr,tab,"Sine: ",SDEC sine,cr ' Display.
next
COS
Returns the two’s complement, 8-bit cosine of an angle specified as an
8-bit (0 to 255) angle. See the explanation of the SIN operator above.
COS is the same in all respects, except that the cosine function returns
the x distance instead of the y distance. To demonstrate the COS op-
erator, use the example program from SIN above, but substitute COS
for SIN.










