Tony Cook > Imager-Graph-0.10 > Imager::Graph::Util

Imager-Graph-0.10.tar.gz

Dependencies

Annotate this POD

Website

# CPAN RT

 New 14 Open 4
View/Report Bugs
Source   Latest Release: Imager-Graph-0.12

# NAME

`  Imager::Graph::Util - simple geometric functions`

# SYNOPSIS

```  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);```

# DESCRIPTION

Provides some simple geometric functions intended for use in drawing graphs.

line_from_points(\$x1, \$y1, \$x2, \$y2)

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.

intersect_lines(@abc1, @abc2)

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.

# INTERNALS

intersect_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 :)

# AUTHOR

Tony Cook <tony@develop-help.com>

`  Imager::Graph(3), http://www.develop-help.com/imager/`