/* * cvhhwdiff.c Jim Piper 22-09-86 * * Compute difference in area between a profile and its convex hull, * weighted by the cosine of the angle which the convex hull arc * makes to the horizontal (notionally; computation differs in detail * due to scaling problems between horizontal and value axes). */ #include #include cvhhwdiff (cvhh,cprof) struct object *cvhh, *cprof; { register int i,j,cdiff,xdiff,ydiff,*hv; int xrange,yrange,wdiff; struct polygondomain *cvhpdom; struct histogramdomain *cprofhdom; register struct ivertex *vtx, *wtx; cvhpdom = (struct polygondomain *) cvhh->idom; vtx = cvhpdom->vtx; cprofhdom = (struct histogramdomain *) cprof->idom; hv = cprofhdom->hv; /* * compute x and y ranges of convex hull */ xrange = vtx[cvhpdom->nvertices - 1].vtX - vtx->vtX; yrange = 0; for (i=0; invertices; i++,vtx++) if (vtx->vtY > yrange) yrange = vtx->vtY; /* * advance hv to first non-zero point */ while (*hv == 0) hv++; wdiff = 0; vtx = cvhpdom->vtx; wtx = vtx+1; for (i=1; invertices; i++,vtx++,wtx++) { /* compute (twice) area under chord */ xdiff = wtx->vtX - vtx->vtX; cdiff = xdiff * (wtx->vtY+vtx->vtY); /* subtract (twice) area of profile segment under this chord */ cdiff -= *hv++; /* half-weight from first point */ /* full weight from non-end points */ for (j=vtx->vtX+1; jvtX; j++) cdiff -= 2 * *hv++; cdiff -= *hv; /* half-weight from last point */ /* * scale xdiff, ydiff. */ xdiff *= yrange; ydiff = wtx->vtY - vtx->vtY; if (ydiff < 0) ydiff = - ydiff; ydiff *= xrange; /* * weight by |xdiff/(xdiff + ydiff)| */ cdiff = cdiff * xdiff / (xdiff + ydiff); wdiff += cdiff; } return(wdiff); }