Difference between revisions of "Aiming"
From CodeStuff
| Line 3: | Line 3: | ||
<edcode> | <edcode> | ||
| + | |||
var t=0.0; | var t=0.0; | ||
var speed=0.02; | var speed=0.02; | ||
| Line 104: | Line 105: | ||
drawLine(ax,ay,bx,by); | drawLine(ax,ay,bx,by); | ||
| − | annotation=" | + | annotation="The straight line to the target makes a right angled triangle"; |
triangleNote(); | triangleNote(); | ||
| Line 128: | Line 129: | ||
vector(transition(0,30)); | vector(transition(0,30)); | ||
annotation="We want to move a fixed distance along this line"; | annotation="We want to move a fixed distance along this line"; | ||
| − | dataNote+=" | + | dataNote+=". We want to move 30"; |
} | } | ||
| Line 140: | Line 141: | ||
speed=0.003; | speed=0.003; | ||
loop(); | loop(); | ||
| − | annotation=" | + | annotation="The movement distance should always be the same "; |
| − | dataNote+=" | + | dataNote+=". We want to move 30 "; |
} | } | ||
| Line 147: | Line 148: | ||
triangle(); | triangle(); | ||
vector(30); | vector(30); | ||
| − | annotation="To find | + | annotation="To find our movement we scale all values by the same amount"; |
| − | dataNote+=" | + | dataNote+=". We want to move 30"; |
} | } | ||
| Line 171: | Line 172: | ||
speed=0.001; | speed=0.001; | ||
| − | annotation="The angles stay the same | + | annotation="The angles stay the same when all sides are scaled evenly"; |
triangleNote(); | triangleNote(); | ||
| − | dataNote+=" | + | dataNote+=". We want to move 30"; |
var newdx=dx*scale; | var newdx=dx*scale; | ||
| Line 230: | Line 231: | ||
run(update); | run(update); | ||
| + | |||
| + | |||
</edcode> | </edcode> | ||
Revision as of 20:33, 27 June 2017
Run this program to see an animated diagram shoing how to find a direction towards another point.