Created
December 30, 2014 15:53
-
-
Save hernanBeiza/1069c1e5bc4f3a22608b to your computer and use it in GitHub Desktop.
AS3 - Punto random en un triángulo
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
//Créditos | |
//http://labs.grupow.com/index.php/2009/05/random-points-inside-a-triangle/ | |
function getRandomPointInTriangle (A:Point,B:Point,C:Point):Point { | |
//P = aA + bB + cC | |
//@see http://www.cgafaq.info/wiki/Random_Point_In_Triangle | |
var a:Number = Math.random(); | |
var b:Number = Math.random(); | |
if (a + b > 1) { | |
a = 1-a; | |
b = 1-b; | |
} | |
var c:Number = 1-a-b; | |
var rndX:Number = (a*A.x)+(b*B.x)+(c*C.x); | |
var rndY:Number = (a*A.y)+(b*B.y)+(c*C.y); | |
return new Point(rndX,rndY); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment