Created
March 7, 2011 21:12
-
-
Save rafalrusin/859239 to your computer and use it in GitHub Desktop.
bisect.fx
This file contains 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
var u:Point2D = a.findBoundaryPoint(b.position, a.position); | |
var v:Point2D = b.findBoundaryPoint(a.position, b.position); | |
var l:Float = Math.sqrt(pointsLenSqr(u, v)); | |
content = [ | |
Path { | |
transforms: [ | |
Affine { | |
mxx: (v.x-u.x)/l | |
mxy: (v.y-u.y)/l | |
myx: (v.y-u.y)/l | |
myy: -(v.x-u.x)/l | |
tx: u.x | |
ty: u.y | |
} | |
] | |
elements: [ | |
MoveTo { | |
x: 0 | |
y: 0 | |
} | |
LineTo { | |
x: l | |
y: 0 | |
} | |
LineTo { | |
x: l-10 | |
y: 5 | |
} | |
MoveTo { | |
x: l | |
y: 0 | |
} | |
LineTo { | |
x: l-10 | |
y: -5 | |
} | |
... |
This file contains 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
public function findBoundaryPoint(a:Point2D,b:Point2D):Point2D { | |
// a is outside, b is inside | |
var m:Point2D = middle(a,b); | |
if (pointsLenSqr(a, b) < 1.) { | |
return m; | |
} else { | |
var n:Point2D = Point2D { | |
x: m.x - position.x | |
y: m.y - position.y | |
} | |
if (contains(n)) { | |
return findBoundaryPoint(a,m); | |
} else { | |
return findBoundaryPoint(m,b); | |
} | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment