Difference between revisions of "Aiming"

From CodeStuff
Jump to: navigation, search
(Created page with "<edcode> var t=0.0; var speed=0.02; var ax=100; var ay=320; var bx=400; var by=200; var annotation = ""; var dataNote = ""; var dataNote2 = ""; function loop() { if (t>=...")
 
Line 1: Line 1:
<edcode>
+
Run this program to see an animated diagram shoing how to find a direction towards another point.
  
 +
 +
<edcode>
 
var t=0.0;
 
var t=0.0;
 
var speed=0.02;
 
var speed=0.02;
Line 138: Line 140:
 
   speed=0.003;
 
   speed=0.003;
 
   loop();
 
   loop();
   annotation="When the points are different the distance should stay the same";
+
   annotation="When the points are different the move distance should stay the same";
   dataNote+=", we want to move a distance of 30";
+
   dataNote+=", the move distance we want is 30";
 
}
 
}
  
Line 146: Line 148:
 
   vector(30);
 
   vector(30);
 
   annotation="To find x and y movement we reduce both values by the same amount";
 
   annotation="To find x and y movement we reduce both values by the same amount";
   dataNote+=", we want to move a distance of 30";
+
   dataNote+=", the move distance we want is 30";
 
}
 
}
  
Line 171: Line 173:
 
   annotation="The angles stay the same if the sides are divided by the same amount";
 
   annotation="The angles stay the same if the sides are divided by the same amount";
 
   triangleNote();   
 
   triangleNote();   
   dataNote+=", we want to move a distance of 30";
+
   dataNote+=", the move distance we want is 30";
  
 
   var newdx=dx*scale;
 
   var newdx=dx*scale;
Line 177: Line 179:
 
   var newd = Math.sqrt(newdx*newdx+newdy*newdy);
 
   var newd = Math.sqrt(newdx*newdx+newdy*newdy);
 
   var div = d/newd*30;  
 
   var div = d/newd*30;  
   dataNote2=" "+d.toFixed(1)+ " / " +div.toFixed(1) +" * 30 = "  +(newd).toFixed(1);
+
    
 +
  setColour("magenta");
 +
  print("Distance to Move  = "+d.toFixed(1)+ " / " +div.toFixed(1) +" * 30 = "  +(newd).toFixed(1), 100,50);
 +
  setColour("blue");
 +
  print("X Movement value = "+(bx-ax).toFixed(1)+ " / " +div.toFixed(1) +" * 30 = "  +(newdx).toFixed(1),100,80);
 +
  setColour("green");
 +
  print("Y Movement value = "+(by-ay).toFixed(1)+ " / " +div.toFixed(1) +" * 30 = "  +(newdy).toFixed(1),100,110);
 +
 
 
}
 
}
  
Line 190: Line 199:
  
 
   setColour("black");
 
   setColour("black");
   print(annotation);
+
   print(annotation,4,22);
  
 
   setColour("grey");
 
   setColour("grey");
 
   print("ax = "+ax.toFixed(0)+"    bx = "+bx.toFixed(0)+"            dx = bx-ax = " + (bx-ax).toFixed(0) ,100,370);
 
   print("ax = "+ax.toFixed(0)+"    bx = "+bx.toFixed(0)+"            dx = bx-ax = " + (bx-ax).toFixed(0) ,100,370);
   print("ay = "+ay.toFixed(0)+"    by = "+by.toFixed(0)+"            dy = by-ay = " + (bx-ax).toFixed(0) ,100,400);
+
   print("ay = "+ay.toFixed(0)+"    by = "+by.toFixed(0)+"            dy = by-ay = " + (by-ay).toFixed(0) ,100,400);
 
   print(dataNote,4,430);
 
   print(dataNote,4,430);
 
   print(dataNote2,4,460);
 
   print(dataNote2,4,460);
    
+
 
 +
   if (part+1<parts.length ) {
 +
    setColour("black");
 +
    print("Pres Space to continue.",220,470);
 +
 
 +
  }
 
   t+=speed;
 
   t+=speed;
 
   if (t>1) {
 
   if (t>1) {
Line 216: Line 230:
  
 
run(update);
 
run(update);
 +
 
</edcode>
 
</edcode>

Revision as of 20:12, 27 June 2017

Run this program to see an animated diagram shoing how to find a direction towards another point.