I need to offset one point on line by pixels.
public static function interpolate(pt1:Point, pt2:Point, f:Number):Point
{
var x:Number = f * pt1.x + (1 - f) * pt2.x;
var y:Number = f * pt1.y + (1 - f) * pt2.y;
return new Point(x, y);
}
This function can interpolate point by percent if “f” is 0.5 the point will be in the center of line pt1 pt2. Is there a way to make this with pixels?
it sounds like you want to write a method
interpolate(pt1, pt2, distanceFromPt1). Your existinginterpolatemethod does something similar, so you can use the latter to implement the former.Right now, if you call
interpolate(A,B,f), you get a point D where(distanceBetween(A,D) / distanceBetween(A,B)) == 1-f. In the version of interpolate you want to write, you don’t know whatfshould be, but you can solve for it, because you knowdistanceBetween(A,D).