import java.awt.Graphics; public class HalfSpace { public double a; public double b; public double c; public Segment s; public HalfSpace(Segment s) { // here i compute the coefficients of line a*x + b*y + c = 0 // the line contains segment this.s = s; this.a = s.q.y - s.p.y; this.b = s.p.x - s.q.x; // average c so there is no bias towards any of the vertices this.c = -0.5*(a*(s.p.x + s.q.x) + b*(s.p.y + s.q.y)); } public void draw(Graphics g) { g.drawLine((int)s.p.x, (int)s.p.y, (int)s.q.x, (int)s.q.y); } public int eval(Vertex v) { // classify the vertex wrt taking in account EPSILON double d = a*v.x + b*v.y + c; if (d > Parameters.EPSILON) return Parameters.IN_FRONT; else if (d < -Parameters.EPSILON) return Parameters.IN_BACK; else return Parameters.COINCIDENT; } public int eval(Segment s) { // this is a hack that does the classification of // by combining the classifications of 's endpoints int e1 = eval(s.p); int e2 = eval(s.q); return (e1 == e2) ? e1 : e1 + e2; } }