Hahahaha, rockstar = me.
Okay, here's the latest fully operational version of the circleline program:
http://www.triple-bypass.net/download/circleline3.txtIt has been cleaned up a bit - at first it made sense to document every step of the messy quadratic equation. Now, extraneous assignments and variables have been removed. The calculation of circle arcs and the calculation of distances are both functions, and instead of returning a variable, they return an expression - again, removing unnecessary steps that were once invaluable.
The decimal point error has been corrected, and I am now getting nice accurate values with doubles. Here's the method:
double theta;
double rsquare;
double arc;
float stepone;
rsquare = pow(rad, 2);
stepone = (2 * rsquare - pow(chord, 2)) / (2 * rsquare);
theta = acos(stepone);
By declaring stepone, the argument passed to acos, as a float, I forced the Cosine Law calculation to return a float. Since all the variables in the equation are doubles, the result is automatically a double. Because of the declaration, however, the result is converted into a float. The result is that the double value is truncated to float precision. Even if you viewed the value of stepone (in the testfile) to 25 places, it is still just -1. stepone then gets converted back to a double when it is passed to acos. As you will see below, the results are great.
Also, since the results of acos are precise enough to pass the "== 0" test, my tangent-catcher works. And vertical lines are handled appropriately, using the calcarc and distancer function just as well as the normal lines. Horizontal lines are also dealt with appropriately.
Results:
1. normal test case
file1.dat:
0
0
10
10
1
5 5 1
powbook:~ lholcombe$ ./a.out
Enter a filename for input:
file1.dat
circle # 1 intersects the line, calculating arc distance
Enter a filename for output:
file1.out
file1.out:
15.2837
2. horizontal line with tangent circle
file2.dat:
0
5
10
5
1
5 6 1
powbook:~ lholcombe$ ./a.out
Enter a filename for input:
file2.dat
circle # 1 does not intersect the line (tangent)
Enter a filename for output:
file2.out
file2.out:
10
3. vertical line with intersecting circle
file3.dat:
0
0
0
10
1
0 5 1
powbook:~ lholcombe$ ./a.out
Enter a filename for input:
file3.dat
circle # 1 intersects the line, calculating arc distance
Enter a filename for output:
file3.out
file3.out:
11.1416
If anyone has any sensible suggestions for improving this program, please offer them.