CLICK HERE TO COPY
Actionscript:
/**
Original function by Pieter Iserbyt:
http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/DistancePoint.java
from Paul Bourke's website:
http://local.wasp.uwa.edu.au/~pbourke/geometry/pointline/
*/
function pointToLineDistance(p1:Sprite, p2:Sprite, p3:Sprite):Number {
var xDelta:Number = p2.x - p1.x;
var yDelta:Number = p2.y - p1.y;
if ((xDelta == 0) && (yDelta == 0)) {
// p1 and p2 cannot be the same point
p2.x [...]
CLICK HERE TO COPY
Actionscript:
// calculate the slope of a line
function calculateSlope(x1:Number, y1:Number, x2:Number, y2:Number):Number {
// rise over run
var s:Number = (y1 - y2) / (x1 - x2);
/*if (x1==x2) {
// slope is Infinity or -Infinity
}*/
return s;
}
/**
Test it out
*/
function draw(x1:Number, y1:Number, [...]
Posted in Math, misc | Tagged actionscript, as3, flash |
CLICK HERE TO COPY
Actionscript:
var leng:int = 10;
for (var i:int = 0, j:int = leng; i <leng; i++, j = leng - i){
trace(i, j);
}
/*outputs
0 10
1 9
2 8
3 7
4 6
5 5
6 4
7 3
8 2
9 1
*/
Looping backwards and forwards.
CLICK HERE TO COPY
Actionscript:
import com.actionsnippet.qbox.*;
[SWF (backgroundColor=0xAA0000, width=700, height=600, frameRate=60)]
var sim:QuickBox2D = new QuickBox2D(this);
sim.createStageWalls();
/**
create a dancing pill
*/
// all x and y coords are relative to the center of the group
var partA:QuickObject = sim.addCircle({x:-1, y:0, radius:0.5, restitution:.9});
var partB:QuickObject = sim.addCircle({x:1, y:0, radius:0.5, restitution:.9});
var partC:QuickObject = sim.addBox({x:0, y:0, width:2, height:1});
// all the parts are passed into the objects [...]