Yea yea, I know Battlestar Galactica is over, but today I thought of the "Daybreak part 1" episode of BSG.
Hera, a little girl has been kidnapped by the Cylons. As part of a desperate plan to save Hera, Admiral Adama draws a red line on the deck, and asks for those willing to risk their lives to save her, do so by crossing the line.

I had a similar problem also with my scripts. I wanted to simply know if a Point was behind a Line or not... :)

 
/*-----------------------------------------------------------------
Returns true if Point P is behind line defined by Points C and D.
 ----------------------------------------------------------------*/
function isBehindLine(P:Point,C:Point,D:Point):Boolean
{
	var a:Number=Point.distance(P,C.add(Point.polar(1,Math.atan2(C.y - D.y,C.x - D.x) + Math.PI / 2)));
	var b:Number=Point.distance(P,C.add(Point.polar(-1,Math.atan2(C.y - D.y,C.x - D.x) + Math.PI / 2)));
	return a < b;
}
 
One Response to “Knowing if a Point is behind a Line”
  1. [...] « Knowing if a Point is behind a Line May 28 2009 [...]

Leave a Comment

Thanks for visiting www.keith-hair.net