main/src/georegression/geometry/algs/AreaIntersectionPolygon2D_F64.java
private double inter(Polygon2D_F64 a, Polygon2D_F64 b)
	{
		if (a.size() < 3 || b.size() < 3)
			return 0;

		//		int na = a.size();
//		int nb = b.size();
		Vertex[] ipa = new Vertex[a.size() + 1];
		Vertex[] ipb = new Vertex[b.size()+ 1];
		Rectangle2D_F64 bbox = new Rectangle2D_F64(
				Double.MAX_VALUE, Double.MAX_VALUE,
				-Double.MAX_VALUE, -Double.MAX_VALUE);


		range(a, bbox);
		range(b, bbox);

		double rngx = bbox.p1.x - bbox.p0.x;
		sclx = gamut / rngx;
		double rngy = bbox.p1.y - bbox.p0.y;
		scly = gamut / rngy;
		double ascale = sclx * scly;

		fit(a, ipa, 0, bbox);
		fit(b, ipb, 2, bbox);

		for (int j = 0; j < a.size(); ++j) {
			for (int k = 0; k < b.size(); ++k) {
				if (ovl(ipa[j].rx, ipb[k].rx) && ovl(ipa[j].ry, ipb[k].ry)) {
					long a1 = -area(ipa[j].ip, ipb[k].ip, ipb[k + 1].ip);
					long a2 = area(ipa[j + 1].ip, ipb[k].ip, ipb[k + 1].ip);
					boolean o = a1 < 0;
					if (o == a2 < 0) {
						long a3 = area(ipb[k].ip, ipa[j].ip, ipa[j + 1].ip);
						long a4 = -area(ipb[k + 1].ip, ipa[j].ip,
								ipa[j + 1].ip);
						if (a3 < 0 == a4 < 0) {
							if (o)
								cross(ipa[j], ipa[j + 1], ipb[k], ipb[k + 1],
										a1, a2, a3, a4);
							else
								cross(ipb[k], ipb[k + 1], ipa[j], ipa[j + 1],
										a3, a4, a1, a2);
						}
					}
				}
			}
		}

		inness(ipa, a.size(), ipb, b.size());
		inness(ipb, b.size(), ipa, a.size());

		return ssss / ascale;
	}
private double inter(Polygon2D_F64 a, Polygon2D_F64 b)
	{
		if (a.size() < 3 || b.size() < 3)
			return 0;

		//		int na = a.size();
//		int nb = b.size();
		Vertex[] ipa = new Vertex[a.size() + 1];
		Vertex[] ipb = new Vertex[b.size()+ 1];
		Rectangle2D_F64 bbox = new Rectangle2D_F64(
				Double.MAX_VALUE, Double.MAX_VALUE,
				-Double.MAX_VALUE, -Double.MAX_VALUE);


		range(a, bbox);
		range(b, bbox);

		double rngx = bbox.p1.x - bbox.p0.x;
		sclx = gamut / rngx;
		double rngy = bbox.p1.y - bbox.p0.y;
		scly = gamut / rngy;
		double ascale = sclx * scly;

		fit(a, ipa, 0, bbox);
		fit(b, ipb, 2, bbox);

		for (int j = 0; j < a.size(); ++j) {
			for (int k = 0; k < b.size(); ++k) {
				if (ovl(ipa[j].rx, ipb[k].rx) && ovl(ipa[j].ry, ipb[k].ry)) {
					long a1 = -area(ipa[j].ip, ipb[k].ip, ipb[k + 1].ip);
					long a2 = area(ipa[j + 1].ip, ipb[k].ip, ipb[k + 1].ip);
					boolean o = a1 < 0;
					if (o == a2 < 0) {
						long a3 = area(ipb[k].ip, ipa[j].ip, ipa[j + 1].ip);
						long a4 = -area(ipb[k + 1].ip, ipa[j].ip,
								ipa[j + 1].ip);
						if (a3 < 0 == a4 < 0) {
							if (o)
								cross(ipa[j], ipa[j + 1], ipb[k], ipb[k + 1],
										a1, a2, a3, a4);
							else
								cross(ipb[k], ipb[k + 1], ipa[j], ipa[j + 1],
										a3, a4, a1, a2);
						}
					}
				}
			}
		}

		inness(ipa, a.size(), ipb, b.size());
		inness(ipb, b.size(), ipa, a.size());

		return ssss / ascale;
	}
private double inter ( Polygon2D_F64 a , Polygon2D_F64 b ) { if ( a . size ( ) < 3 || b . size ( ) < 3 ) return 0 ; //		int na = a.size(); //		int nb = b.size(); Vertex [ ] ipa = new Vertex [ a . size ( ) + 1 ] ; Vertex [ ] ipb = new Vertex [ b . size ( ) + 1 ] ; Rectangle2D_F64 bbox = new Rectangle2D_F64 ( Double . MAX_VALUE , Double . MAX_VALUE , - Double . MAX_VALUE , - Double . MAX_VALUE ) ; range ( a , bbox ) ; range ( b , bbox ) ; double rngx = bbox . p1 . x - bbox . p0 . x ; sclx = gamut / rngx ; double rngy = bbox . p1 . y - bbox . p0 . y ; scly = gamut / rngy ; double ascale = sclx * scly ; fit ( a , ipa , 0 , bbox ) ; fit ( b , ipb , 2 , bbox ) ; for ( int j = 0 ; j < a . size ( ) ; ++ j ) { for ( int k = 0 ; k < b . size ( ) ; ++ k ) { if ( ovl ( ipa [ j ] . rx , ipb [ k ] . rx ) && ovl ( ipa [ j ] . ry , ipb [ k ] . ry ) ) { long a1 = - area ( ipa [ j ] . ip , ipb [ k ] . ip , ipb [ k + 1 ] . ip ) ; long a2 = area ( ipa [ j + 1 ] . ip , ipb [ k ] . ip , ipb [ k + 1 ] . ip ) ; boolean o = a1 < 0 ; if ( o == a2 < 0 ) { long a3 = area ( ipb [ k ] . ip , ipa [ j ] . ip , ipa [ j + 1 ] . ip ) ; long a4 = - area ( ipb [ k + 1 ] . ip , ipa [ j ] . ip , ipa [ j + 1 ] . ip ) ; if ( a3 < 0 == a4 < 0 ) { if ( o ) cross ( ipa [ j ] , ipa [ j + 1 ] , ipb [ k ] , ipb [ k + 1 ] , a1 , a2 , a3 , a4 ) ; else cross ( ipb [ k ] , ipb [ k + 1 ] , ipa [ j ] , ipa [ j + 1 ] , a3 , a4 , a1 , a2 ) ; } } } } } inness ( ipa , a . size ( ) , ipb , b . size ( ) ) ; inness ( ipb , b . size ( ) , ipa , a . size ( ) ) ; return ssss / ascale ; }
-------------------------------------------------------------------------
-------------------------------------------------------------------------