Imager::Graph::Util - simple geometric functions
my @abc = line_from_points($x1, $y1, $x2, $y2); my @p = intersect_lines(@abc1, @abc2); my @points = intersect_line_and_circle(@abc1, $cx, $cy, $radius);
Provides some simple geometric functions intended for use in drawing graphs.
Returns the coefficients of a line in the Ax + By + C = 0 form.
Returns the list (A, B, C), or an empty list if they are the same point.
Returns the point of intersection of the 2 lines, each given in Ax+By+C=0 form. Returns either the point (x, y) or an empty list.
Returns the points or point of intersection of the given line and circle.
The implementation is a little heavy on math. Perhaps there was a better way to implement it.
Starting with the equations of a line and that of a circle:
(1) Ax + By + C = 0 (2) (x - x1)**2 + (y - y1)**2 = R ** 2 (3) Ax = -By - C # re-arrange (1) (4) A**2 (x - x1)**2 + A**2 (y - y1)**2 = R**2 A**2 # (2) * A**2 (5) (Ax - Ax1)**2 + (Ay - Ay1)**2 = R**2 A**2 # move it inside (6) (-By - C - Ax1)**2 + (Ay - Ay1)**2 = R**2 A**2 # sub (3) into (5)
Expand and convert to standard quadratic form, and similary for x.
Be careful :)
Tony Cook <firstname.lastname@example.org>