CurveLinearizer { Point calcCircleCenter( Point p0, Point p1, Point p2 ) throws IllegalArgumentException { double minOrd0 = CurveLinearizer.findShiftOrd0( p0, p1, p2 ); double minOrd1 = CurveLinearizer.findShiftOrd1( p0, p1, p2 ); Point p0Shifted = new DefaultPoint( null, p0.getCoordinateSystem(), p0.getPrecision(), new double[] { p0.get0() - minOrd0, p0.get1() - minOrd1 } ); Point p1Shifted = new DefaultPoint( null, p1.getCoordinateSystem(), p1.getPrecision(), new double[] { p1.get0() - minOrd0, p1.get1() - minOrd1 } ); Point p2Shifted = new DefaultPoint( null, p2.getCoordinateSystem(), p2.getPrecision(), new double[] { p2.get0() - minOrd0, p2.get1() - minOrd1 } ); if ( areCollinear( p0Shifted, p1Shifted, p2Shifted ) ) { throw new IllegalArgumentException( "The given points are collinear, no circum center can be calculated." ); } Vector3d a = new Vector3d( p0Shifted.get0(), p0Shifted.get1(), p0Shifted.get2() ); Vector3d b = new Vector3d( p1Shifted.get0(), p1Shifted.get1(), p1Shifted.get2() ); Vector3d c = new Vector3d( p2Shifted.get0(), p2Shifted.get1(), p2Shifted.get2() ); if ( Double.isNaN( a.z ) ) { a.z = 0.0; } if ( Double.isNaN( b.z ) ) { b.z = 0.0; } if ( Double.isNaN( c.z ) ) { c.z = 0.0; } Vector3d ab = new Vector3d( a ); Vector3d ac = new Vector3d( a ); Vector3d bc = new Vector3d( b ); Vector3d ba = new Vector3d( b ); Vector3d ca = new Vector3d( c ); Vector3d cb = new Vector3d( c ); ab.sub( b ); ac.sub( c ); bc.sub( c ); ba.sub( a ); ca.sub( a ); cb.sub( b ); Vector3d cros = new Vector3d(); cros.cross( ab, bc ); double crosSquare = 2 * cros.length() * cros.length(); a.scale( ( ( bc.length() * bc.length() ) * ab.dot( ac ) ) / crosSquare ); b.scale( ( ( ac.length() * ac.length() ) * ba.dot( bc ) ) / crosSquare ); c.scale( ( ( ab.length() * ab.length() ) * ca.dot( cb ) ) / crosSquare ); Point3d circle = new Point3d( a ); circle.add( b ); circle.add( c ); circle.x += minOrd0; circle.y += minOrd1; return geomFac.createPoint( null, new double[] { circle.x, circle.y }, p0Shifted.getCoordinateSystem() ); } CurveLinearizer( GeometryFactory geomFac ); Curve linearize( Curve curve, LinearizationCriterion crit ); LineStringSegment linearize( CurveSegment segment, LinearizationCriterion crit ); LineStringSegment linearizeArc( Arc arc, LinearizationCriterion crit ); LineStringSegment linearizeArcString( ArcString arcString, LinearizationCriterion crit ); LineStringSegment linearizeCubicSpline( CubicSpline spline, LinearizationCriterion crit ); static boolean areCollinear( Point p0, Point p1, Point p2 );  }
@Test public void testFindCircleCenter() { Point p0 = geomFac.createPoint( null, new double[] { 8, -1 }, null ); Point p1 = geomFac.createPoint( null, new double[] { 3, 1.6 }, null ); Point p2 = geomFac.createPoint( null, new double[] { -110, 16.77777 }, null ); Point center = linearizer.calcCircleCenter( p0, p1, p2 ); arePointsOnCircle( center, p0, p1, p2 ); }