Difference between revisions of "TI-BASIC:SK:Trigonometry"

From Learn @ Cemetech
Jump to navigationJump to search
(Initial automated import)
 
(Automated internal link correction)
 
Line 67: Line 67:
  
 
{{Template:TI-BASIC:Next-prev
 
{{Template:TI-BASIC:Next-prev
|prevpage = sk:probability
+
|prevpage = TI-BASIC:SK:Probability
 
|prevtitle = Probability
 
|prevtitle = Probability
|tocpage = starter-kit
+
|tocpage = TI-BASIC:Starter_Kit
 
|toctitle = Table of Contents
 
|toctitle = Table of Contents
|nextpage = sk:complex
+
|nextpage = TI-BASIC:SK:Complex
 
|nexttitle = Complex Numbers}}[[Category:TI-BASIC]]
 
|nexttitle = Complex Numbers}}[[Category:TI-BASIC]]
 
[[Category:TIBD]]
 
[[Category:TIBD]]

Latest revision as of 00:53, 25 February 2016

Template:TI-BASIC:Cid

Besides standard math, trigonometry functions are helpful for simulating rotation and making games like Asteroids.

Key Commands

The trigonometric commands are Sin, Cos and Tan. sin(θ) returns the sine of θ, which is defined as the y-value of the point of intersection of the unit circle and a line containing the origin that makes an angle θ with the positive x-axis. cos(θ) returns the cosine of θ, which is defined as the x-value of the point of intersection of the unit circle and a line containing the origin that makes an angle θ with the positive x-axis. tan(θ) returns the tangent of angle θ, which is defined as <math>\frac{\sin \theta}{\cos \theta}</math> It is slightly unnecessary, as most games that use trigonometry only require sin and cos.

Let's say you are making an object firing simulation and you are keeping track of the angle θ. When you fire, you can increment the location variables X and Y with speed a and angle θ using these formulas:

X+Acos(θ→X
Y+Asin(θ→Y

Examples

The following code awaits the user to input an angle to fire at, using a Line to guide, and fires a projectile at that angle until the user pressed [Clear]

:AxesOff
:DelVarXDelVarθDegree
:ClrDraw
:94→Xmax
:62→Ymax
:0→Ymin
:Ans→Xmin
:Repeat K=21
:Line(0,0,2cos(θ),2sin(θ
:Repeat Ans
:getKey→K
:End
:Line(0,0,2cos(θ),2sin(θ),0
:max(0,min(90,θ+(Ans=25)-(Ans=34→θ
:End
:Repeat K=45
:X+2cos(θ→X
:Y+2sin(θ→Y
:Pt-On(X,Y
:getKey→K
:End

Of course, Earth has gravity, doesn't it? We can account for that pretty easily. To simplify the problem, we'll just assume that Earth is flat and that the projectile follows a parabolic path:

:AxesOff
:DelVarXDelVarθDegree
:ClrDraw
:94→Xmax
:62→Ymax
:0→Ymin
:Ans→Xmin
:Repeat K=21
:Line(0,0,2cos(θ),2sin(θ
:Repeat Ans
:getKey→K
:End
:Line(0,0,2cos(θ),2sin(θ),0
:max(0,min(90,θ+(Ans=25)-(Ans=34→θ
:End
:2sin(θ→G
:Repeat K=45
:X+2cos(θ→X
:Y+G→Y
:G-.05→G    // :D Now it follows a parabolic path! You can change gravity by changing this number.
:Pt-On(X,Y
:getKey→K
:End
<< Probability Table of Contents Complex Numbers >>