COS (x)


'TRIG lesson one.bas  SmallBASIC 0.12.2 [B+=MGA] 2016-03-12
'note: the lines in the diagram have been thickened to help see and identify the color
const green=rgb(0,128,0) 'never liked QB color for green
sub drawTRIGtri
'3 points make a triangle, one point requires an x,y coordinate
xp1=xmax-100-.25*ymax : yp1=ymax-100 'bottom left angle of triangle
xp2=xmax-100 : yp2=ymax-100 'bottom right corner with right angle
xp3=xmax-100 : yp3=ymax-100-.433*ymax 'upper corner
'green botton line is called side adjacent the yellow angle at the base of this triangle (not the 90 degree right angle)
line xp1,yp1,xp2,yp2,green
line xp1-1,yp1+1,xp2+1,yp2+1,green
line xp1-2,yp1+2,xp2+2,yp2+2,green

'blue vertical line is call side opposite the yellow angle at the base of this triangle (not the 90 degree right angle)
line xp2,yp2,xp3,yp3,9
line xp2+1,yp2+1,xp3+1,yp3-1,9
line xp2+2,yp2+2,xp3+2,yp3-2,9   
'red diagonal line always the longest of a right triangle is called the hypotenuse
for i=0 to 6
  line xp1,yp1+.5*i,xp3,yp3+i,12
'mark the 90 degree angel
rect xp2-50,yp2-50 step 48,48,15 
at xp2-50+10,yp2-50+15:?"90"
'the yellow angle: ARC x,y,r, start radians, stop radians[, aspect [, color]] note: start clockwise to stop radians
arc xp1,yp1,.2*ymax/2,2*pi-pi/3,0,1,14
arc xp1,yp1,.18*ymax/2,2*pi-pi/3,0,1,14
'note: here 0 degrees is due east and the angle advances clockwise
while 1
at 0,0
?"A man put up a pole (blue) and attached a 100 foot wire (red)"
?"from top to ground. Now he needs to know the height of the"
?"pole. He doesn't have a ladder nearly that high but he"
?"can use a first lesson in trignometry to get the height of"
?"the pole."
?"Trignometry means right triangles. A right triangle is one
?"that contains a 90 degree angle, the same angle a proper 
?"pole makes with the ground."
?"Trig has made a study of right triangles and made one big
?"discovery: The RATIO of the sides of a right triangle are 
?"always the same if the ANGLES of the sides (AKA legs and 
?"hypotenuse) are the same." 
?"That is trig in a nutshell. Notice I said RATIO of lengths."
?"press any when ready...
at 0,0
?"The two main RATIOs of Trig are SIN and COS."
?"COS (AKA COSINE) is the RATIO of the green side (next to"
?"the yellow ANGLE) to the hypotenuse (red diagonal) AKA"  
?"(adjacent leg) / (hypotenuse)  shortened to (adj/hyp)"
?"or here (green line length) / (red line length)."
?"That's it!  COS is the leg length next to the angle in"
?"question divided by the diagonal length."
?"So the man measures the distance from the pole to where"
?"the wire meets the gound and gets 50 feet. This is the"
?"green leg next to the angle we want to figure out for the"
?"COS RATIO (adj/hyp). In this case it is 50 ft along the" 
?"ground divided by 100 ft the diagonal red wire, 50/100=.5" 
?"So that means COS of the angle is .5 the man says."
?"So the man goes to some trig tables and finds what angle"
?"makes a COS ratio of .5, he is looking up the Arc COS of"
?"the ratio(.5) = the angle whose adj-leg/hypotenuse is .5" 
?"Oh! he says that is a 60 degree angle the wire is making"
?"with the ground, the yellow angle is 60 degrees."
?"Press any key when ready..."
at 0,0
?"Now that he knows the angle is 60 degrees he can use the"
?"SIN ratio to calculate the height of the pole. The SIN"
?"RATIO is opp/hyp, the (opposite leg length)/(hypotenuse)"
?"The pole/wire = SIN of 60 degrees = .8660"
?"or pole/wire=.866."
?"Multiply both sides of this equation by wire length and" 
?"get pole=.866*wire."
?"Since the wire is 100, pole = .866*100 = 86.6 feet."
?"press any for first screen again..."

At an angle around a given point, SIN and COS and radius (or distance) can locate the absolute screen x,y coordinate:

''' Diagrammed SIN and COS.bas  SmallBASIC 0.12.2 [B+=MGA] 2016-03-16
''' ah finally got diagramed analysis built into single quote commented code!!!
''' the color codes match original Trig lesson one
'''reminder XMAX, YMAX and PI are built in constants
CONST green =RGB(0,128,0)
''' a central point cx,cy around which to draw 
cx=XMAX/2:cy=YMAX/2 'again cx,cy can be anywhere on screen so dont make them constant
'''highlight center
CIRCLE cx,cy,2,1,15
r=200 'the radius or distance in pixels from cx,cy desired
CIRCLE cx,cy,r,1,8  'we want a point somewhere on this circle, radius = constant distance away from point
'''      locate point 30 degrees and r distance from cx,cy       30 degrees = PI/6 radians
''' here is 30 degrees in tiny purple circle around x=r*cos(rad(30),y=r*sin(rad(30)
CIRCLE cx + r*COS(RAD(30)), cy + r*SIN(RAD(30)), 3, 1, 13   'x,y,r=3,aspect=1,color 13
''' uncomment single comment lines for analysis
'LINE cx,cy,cx+r*COS(RAD(30)),cy,green 'adjacent leg in red
'LINE cx+r*COS(RAD(30)),cy,cx+r*COS(RAD(30)),cy + r*SIN(RAD(30)),9 'leg opposite in blue
'LINE cx,cy,cx+r*COS(RAD(30)),cy + r*SIN(RAD(30)),12
'RECT cx+r*COS(RAD(30))-11,cy+2 step 9,9,15
''''             V there are 12, 30 degree angles in circle (2*PI) so 2*PI/12 or PI/6
'ARC cx,cy,30,0,PI/6,1,14
'ARC cx,cy,35,0,RAD(30),1,14

'''                Another example at 240 degrees = 4*PI/3 radians
''' here is 60+180=240 degrees in yellow both x and y are neg in relation to cx,cy
'CIRCLE cx + r*COS(RAD(240)), cy + r*SIN(RAD(240)), 3, 1, 14  'yellow
'''uncomment single comment lines for analysis
'LINE cx,cy,cx+r*COS(RAD(240)),cy,green 'adjacent leg in red
'LINE cx+r*COS(RAD(240)),cy,cx+r*COS(RAD(240)),cy + r*SIN(RAD(240)),9 'leg opposite in blue
'LINE cx,cy,cx+r*COS(RAD(240)),cy + r*SIN(RAD(240)),12
'RECT cx+r*COS(RAD(240))+2,cy-11 step 9,9,15
'''240 degrees =180 + 60 = PI + 2*PI/6 = PI+PI/3 = 4*PI/3 radians
'''               V end angle for arc in radians = RAD(240) or 4*PI/3 radians
'ARC cx,cy,15,0,4*PI/3,1,14
'ARC cx,cy,10,0,RAD(240),1,14
sub legend
  at 0,0
  ?"green = leg adj, blue =leg opp, red = hypotenuse = radius"
  ?"white square is where the right angle is, yellow arcs mark angle in question
  ?"COS(yellow) = adj/hyp = green/red, red is radius of circle
  ?"SIN(yellow) = opp/hyp =  blue/red, red is radius of circle