// Finds the intersection[s] between a line and a circle given two points on// the line [x1, y1], [x2, y2], the center of the circle [cx, cy],// and the radius of the circle.//// Returns:// an array, each element containing an array with [x,y] coordinates for// each intersection point. There can // be 0, 1, or 2 points of intersection. For example, this may return// something like [[1,1], [2,1]]//// See:// http://mathworld.wolfram.com/Circle-LineIntersection.html
circleLineIntersections[x1, y1, x2, y2, cx, cy, r] :=
{// First shift coordinates so the center of the circle is at 0,0
x1a = x1 - cx
y1a = y1 - cy
x2a = x2 - cx
y2a = y2 - cy

/** This performs the inverse of the arbitrary affine transformation above,
converting the point [x',y'] back into the original coordinates [x,y]
using the same affine transform coefficients a,b,c,d,e,f as passed to
the affineTransform function above.

/* This performs the inverse of the arbitrary affine transformation above,
converting the point [x',y'] back into the original coordinates [x,y]
using the same affine transform coefficients coeffs=[a,b,c,d,e,f] as
passed to the affineTransform function above.

/** This composes a set of transformation coefficients with another set of
transformation coefficients. The inputs should be an array of 6 elements
containing the coefficients [a,b,c,d,e,f] as described in the documentation
for the affineTransformation function above.