I’ve looked through the .geom package, and I can’t find anything that does this. Here’s my goal: I have two line segments that intersect, and I want to find the angle between them.
I’ve thought of one way to do it. It’s pretty convoluted. First, find the intersection of the two lines by choosing one line and using a PathIterator to count through the points on that line until we find the point with a distance of zero from the other line. There’s our intersection.
Next, create two lines of equal size, thus: find the shorter of the two lines; create a new line (if necessary) that is identical to the longer line, but whose P1 is at the intersection of the two lines; use a PathIterator again to count through the points on the longer line until we’ve defined a segment of the longer line that is the same length as the shorter line.
Now we should have two lines of equal length. This length is the radius of the circle we need to create to find the angle between the lines. But what we need to actually define is the rectangle that bounds the circle that encompasses the lines. We can do that by starting from the intersection point and subtracting the segment length from the x and y of that point. That should give us the location of the upper left corner of the rectangle we’re looking for.
Now, the last leg of this process: iterating through a bunch of different Arc2Ds. Using the endpoint of one of the lines as a startPoint for the arcs, we iterate to find an arc whose endPoint is 0 distance from the second line. Once we’ve found the startPoint and the endPoint of an arc that runs from one line to the other, the parameter that defines the degrees of that arc segment will also give us the angle between the two lines. Voila!
Whew.
That’s the simplest (hah!) method I can think of. I’d love to hear of another. Anyone?