static double fractionCauchyToGN ( double lengthCauchy , double lengthGN , double lengthPtoGN , double region ) { // First triangle has 3 known sides double a = lengthGN , b = lengthCauchy , c = lengthPtoGN ; // Law of cosine to find angle for side GN (a.k.a 'a') double cosineA = ( a * a - b * b - c * c ) / ( - 2.0 * b * c ) ; double angleA = Math . acos ( cosineA ) ; // In the second triangle, that is now being considered, lengthP is known and the side which intersects // the region boundary is known, but we need to solve for the length from P to the intersection // with the boundary a = region ; double angleB = Math . asin ( ( b / a ) * Math . sin ( angleA ) ) ; double angleC = Math . PI - angleA - angleB ; c = Math . sqrt ( a * a + b * b - 2.0 * a * b * Math . cos ( angleC ) ) ; return c / lengthPtoGN ; }
Compute the fractional distance from P to GN where the point intersects the region s boundary