dpoint centre(Point p1, Point p2, Point p3) { Point n1,n2; double c1,c2; n1=vector(p1,p2); n2=vector(p2,p3); c1=calculate_c(n1,midpoint(p1,p2)); c2=calculate_c(n2,midpoint(p2,p3)); return intersect(n1,n2,c1,c2); }
Point compute_v(CHpoints *P) { /* B ------------- | | ^ ^ A | SCREEN | C | | -> -> | | Bn Dn An Cn ------------- D */ Point An,Bn,Cn,Dn; /* Normalvectors to the Screen borders A,B,C,D */ Point n; /* Normalvector to the bisector between P and Next(p) */ double c; /* the constant in the equation ax+by=c, where (a,b) is normalvector to the bisetor */ Point i; dpoint di; /* Point where bisector of P and next(P) intersects with border */ Point p,np; double minX, minY, maxX, maxY; /* Max, min X and Y coordinate */ minX=-10000.0; minY=-10000.0; maxX=10000.0; maxY=10000.0; An.x=1; An.y=0; /* Setup normalvectores for the border lines */ Bn.x=0; Bn.y=1; Cn.x=1; Cn.y=0; Dn.x=0; Dn.y=1; p=P->node; /* p=P and np=next(P) */ np=next(P)->node; n=vector(p,np); c=calculate_c(n,midpoint(p,np)); if ((p.x < np.x) && (p.y < np.y)) { /* intersects either D or A */ di=intersect(n,Dn,c,maxY); if ((minX>di.x) || (di.x>maxX)) di=intersect(n,An,c,minX); } else if ((p.x < np.x) && (p.y == np.y)) { /* intersects D */ di=intersect(n,Dn,c,maxY); } else if ((p.x < np.x) && (p.y > np.y)) { /* intersects either D or C */ di=intersect(n,Dn,c,maxY); if ((minX>di.x) || (di.x>maxX)) di=intersect(n,Cn,c,maxX); } else if ((p.x == np.x) && (p.y < np.y)) { /* intersects A */ di=intersect(n,An,c,minX); } else if ((p.x == np.x) && (p.y > np.y)) { /* intersects C */ di=intersect(n,Cn,c,maxX); } else if ((p.x > np.x) && (p.y < np.y)) { /* intersects either A or B */ di=intersect(n,Bn,c,minY); if ((minX>di.x) || (di.x>maxX)) di=intersect(n,An,c,minX); } else if ((p.x > np.x) && (p.y == np.y)) /* intersects B */ di=intersect(n,Bn,c,minY); else if ((p.x > np.x) && (p.y > np.y)) { /* intersects either C or B */ di=intersect(n,Bn,c,minY); if ((minX>di.x) || (di.x>maxX)) di=intersect(n,Cn,c,maxX); } else { printf("Error: Can't intersect\n"); exit(1); } i.x= (int)di.x; i.y= (int)di.y; return i; }